[ Index ] |
|
Code source de PRADO 3.0.6 |
1 <?php 2 /** 3 * TAttributeCollection classes 4 * 5 * @author Qiang Xue <qiang.xue@gmail.com> 6 * @link http://www.pradosoft.com/ 7 * @copyright Copyright © 2005 PradoSoft 8 * @license http://www.pradosoft.com/license/ 9 * @version $Id: TAttributeCollection.php 1397 2006-09-07 07:55:53Z wei $ 10 * @package System.Collections 11 */ 12 13 /** 14 * Includes TMap class 15 */ 16 Prado::using('System.Collections.TMap'); 17 18 /** 19 * TAttributeCollection class 20 * 21 * TAttributeCollection implements a collection for storing attribute names and values. 22 * 23 * Besides all functionalities provided by {@link TMap}, TAttributeCollection 24 * allows you to get and set attribute values like getting and setting 25 * properties. For example, the following usages are all valid for a 26 * TAttributeCollection object: 27 * <code> 28 * $collection->Text='text'; 29 * echo $collection->Text; 30 * </code> 31 * They are equivalent to the following: 32 * <code> 33 * $collection->add('Text','text'); 34 * echo $collection->itemAt('Text'); 35 * </code> 36 * 37 * Note, attribute names are case-insensitive. They are converted to lower-case 38 * in the collection storage. 39 * 40 * @author Qiang Xue <qiang.xue@gmail.com> 41 * @version $Id: TAttributeCollection.php 1397 2006-09-07 07:55:53Z wei $ 42 * @package System.Collections 43 * @since 3.0 44 */ 45 class TAttributeCollection extends TMap 46 { 47 /** 48 * Returns a property value or an event handler list by property or event name. 49 * This method overrides the parent implementation by returning 50 * a key value if the key exists in the collection. 51 * @param string the property name or the event name 52 * @return mixed the property value or the event handler list 53 * @throws TInvalidOperationException if the property/event is not defined. 54 */ 55 public function __get($name) 56 { 57 return $this->contains($name)?$this->itemAt($name):parent::__get($name); 58 } 59 60 /** 61 * Sets value of a component property. 62 * This method overrides the parent implementation by adding a new key value 63 * to the collection. 64 * @param string the property name or event name 65 * @param mixed the property value or event handler 66 * @throws TInvalidOperationException If the property is not defined or read-only. 67 */ 68 public function __set($name,$value) 69 { 70 $this->add($name,$value); 71 } 72 73 /** 74 * Returns the item with the specified key. 75 * This overrides the parent implementation by converting the key to lower case first. 76 * @param mixed the key 77 * @return mixed the element at the offset, null if no element is found at the offset 78 */ 79 public function itemAt($key) 80 { 81 return parent::itemAt(strtolower($key)); 82 } 83 84 85 /** 86 * Adds an item into the map. 87 * This overrides the parent implementation by converting the key to lower case first. 88 * @param mixed key 89 * @param mixed value 90 */ 91 public function add($key,$value) 92 { 93 parent::add(strtolower($key),$value); 94 } 95 96 /** 97 * Removes an item from the map by its key. 98 * This overrides the parent implementation by converting the key to lower case first. 99 * @param mixed the key of the item to be removed 100 * @return mixed the removed value, null if no such key exists. 101 */ 102 public function remove($key) 103 { 104 return parent::remove(strtolower($key)); 105 } 106 107 /** 108 * Returns whether the specified is in the map. 109 * This overrides the parent implementation by converting the key to lower case first. 110 * @param mixed the key 111 * @return boolean whether the map contains an item with the specified key 112 */ 113 public function contains($key) 114 { 115 return parent::contains(strtolower($key)); 116 } 117 118 /** 119 * Determines whether a property is defined. 120 * This method overrides parent implementation by returning true 121 * if the collection contains the named key. 122 * @param string the property name 123 * @return boolean whether the property is defined 124 */ 125 public function hasProperty($name) 126 { 127 return $this->contains($name) || parent::hasProperty($name); 128 } 129 130 /** 131 * Determines whether a property can be read. 132 * This method overrides parent implementation by returning true 133 * if the collection contains the named key. 134 * @param string the property name 135 * @return boolean whether the property can be read 136 */ 137 public function canGetProperty($name) 138 { 139 return $this->contains($name) || parent::canGetProperty($name); 140 } 141 142 /** 143 * Determines whether a property can be set. 144 * This method overrides parent implementation by always returning true 145 * because you can always add a new value to the collection. 146 * @param string the property name 147 * @return boolean true 148 */ 149 public function canSetProperty($name) 150 { 151 return true; 152 } 153 } 154 155 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 21:07:04 2007 | par Balluche grâce à PHPXref 0.7 |