| [ Index ] |
PHP Cross Reference of Limb3 |
[Summary view] [Print] [Text view]
1 <?php 2 /* 3 * Limb PHP Framework 4 * 5 * @link http://limb-project.com 6 * @copyright Copyright © 2004-2007 BIT(http://bit-creative.com) 7 * @license LGPL http://www.gnu.org/copyleft/lesser.html 8 */ 9 10 /** 11 * Translates between form name attributes and tag displayname 12 * attributes (human reabable). 13 * @package wact 14 * @version $Id: error.inc.php 5945 2007-06-06 08:31:43Z pachanga $ 15 */ 16 class WactFormFieldNameDictionary 17 { 18 19 /** 20 * @var WactFormComponent 21 */ 22 protected $form; 23 24 function __construct($form) 25 { 26 $this->form = $form; 27 } 28 29 /** 30 * @param string name attribute of the field 31 * @return string displayname attribute of the field 32 * @access protected 33 * @package wact 34 * @version $Id: error.inc.php 5945 2007-06-06 08:31:43Z pachanga $ 35 */ 36 37 function getFieldName($field_name) 38 { 39 $field = $this->form->findChild($field_name); 40 if (is_object($field)) 41 return $field->getDisplayName(); 42 else 43 return $field_name; 44 } 45 }class WactFormErrorList extends ArrayIterator 46 { 47 protected $field_name_dictionary; 48 49 function addError($message, $fields = array(), $values = array()) 50 { 51 $this->append(new WactFormError($message, $fields, $values)); 52 } 53 54 function setFieldNameDictionary($dict) 55 { 56 $this->field_name_dictionary = $dict; 57 } 58 59 function getFieldName($field) 60 { 61 if(is_object($this->field_name_dictionary)) 62 return $this->field_name_dictionary->getFieldName($field); 63 else 64 return $field; 65 } 66 67 function bindToForm($form) 68 { 69 $this->setFieldNameDictionary(new WactFormFieldNameDictionary($form)); 70 $form->setErrors($this); 71 } 72 73 function current() 74 { 75 $error = parent :: current(); 76 77 $text = $error['message']; 78 foreach($error->getFields() as $key => $fieldName) 79 { 80 $replacement = $this->getFieldName($fieldName); 81 $text = str_replace('{' . $key . '}', $replacement, $text); 82 } 83 84 foreach($error->getValues() as $key => $replacement) 85 $text = str_replace('{' . $key . '}', $replacement, $text); 86 87 $error['message'] = $text; 88 return $error; 89 } 90 } 91 92 /** 93 * class WactFormError. 94 * 95 * @package wact 96 * @version $Id: error.inc.php 5945 2007-06-06 08:31:43Z pachanga $ 97 */ 98 class WactFormError extends ArrayObject 99 { 100 protected $fields_list = array(); 101 protected $values = array(); 102 103 function __construct($message, $fields_list = array(), $values = array()) 104 { 105 parent :: __construct(array('message' => $message)); 106 107 $this->fields_list = $fields_list; 108 $this->values = $values; 109 } 110 111 function getFields() 112 { 113 return $this->fields_list; 114 } 115 116 function getValues() 117 { 118 return $this->values; 119 } 120 } 121 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Mon Dec 1 03:56:46 2008 | Cross-referenced by PHPXref 0.7 |