summaryrefslogtreecommitdiff
path: root/framework
diff options
context:
space:
mode:
authorxue <>2006-01-21 15:16:28 +0000
committerxue <>2006-01-21 15:16:28 +0000
commitadb9a7864e6fce08426af0b41bbc726388e296a7 (patch)
tree27dbe974265c776405d1a520219bd5bfc8b88882 /framework
parentc5e3052cdab7d0d8d86ddd272a906e850e0bc90a (diff)
Diffstat (limited to 'framework')
-rw-r--r--framework/Collections/TAttributeCollection.php113
-rw-r--r--framework/TComponent.php6
-rw-r--r--framework/Web/UI/TControl.php11
3 files changed, 124 insertions, 6 deletions
diff --git a/framework/Collections/TAttributeCollection.php b/framework/Collections/TAttributeCollection.php
new file mode 100644
index 00000000..c8870919
--- /dev/null
+++ b/framework/Collections/TAttributeCollection.php
@@ -0,0 +1,113 @@
+<?php
+/**
+ * TAttributeCollection classes
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Revision: $ $Date: $
+ * @package System.Collections
+ */
+
+/**
+ * Includes TMap class
+ */
+Prado::using('System.Collections.TMap');
+
+/**
+ * TAttributeCollection class
+ *
+ * TAttributeCollection implements a collection for storing attribute names and values.
+ *
+ * Besides all functionalities provided by {@link TMap}, TAttributeCollection
+ * allows you to get and set attribute values like getting and setting
+ * properties. For example, the following usages are all valid for a
+ * TAttributeCollection object:
+ * <code>
+ * $collection->Text='text';
+ * echo $collection->Text;
+ * </code>
+ * They are equivalent to the following:
+ * <code>
+ * $collection->add('Text','text');
+ * echo $collection->itemAt('Text');
+ * </code>
+ *
+ * Note, attribute names are case-insensitive. They are converted to lower-case
+ * in the collection storage.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Revision: $ $Date: $
+ * @package System.Collections
+ * @since 3.0
+ */
+class TAttributeCollection extends TMap
+{
+ /**
+ * Returns a property value or an event handler list by property or event name.
+ * This method overrides the parent implementation by returning
+ * a key value if the key exists in the collection.
+ * @param string the property name or the event name
+ * @return mixed the property value or the event handler list
+ * @throws TInvalidOperationException if the property/event is not defined.
+ */
+ public function __get($name)
+ {
+ $name=strtolower($name);
+ return $this->contains($name)?$this->itemAt($name):parent::__get($name);
+ }
+
+ /**
+ * Sets value of a component property.
+ * This method overrides the parent implementation by adding a new key value
+ * to the collection.
+ * @param string the property name or event name
+ * @param mixed the property value or event handler
+ * @throws TInvalidOperationException If the property is not defined or read-only.
+ */
+ public function __set($name,$value)
+ {
+ $this->add(strtolower($name),$value);
+ }
+
+ /**
+ * Determines whether a property is defined.
+ * This method overrides parent implementation by returning true
+ * if the collection contains the named key.
+ * @param string the property name
+ * @return boolean whether the property is defined
+ */
+ public function hasProperty($name)
+ {
+ $name=strtolower($name);
+ return $this->contains($name) || parent::hasProperty($name);
+ }
+
+ /**
+ * Determines whether a property can be read.
+ * This method overrides parent implementation by returning true
+ * if the collection contains the named key.
+ * @param string the property name
+ * @return boolean whether the property can be read
+ */
+ public function canGetProperty($name)
+ {
+ $name=strtolower($name);
+ return $this->contains($name) || parent::canGetProperty($name);
+ }
+
+ /**
+ * Determines whether a property can be set.
+ * This method overrides parent implementation by always returning true
+ * because you can always add a new value to the collection.
+ * @param string the property name
+ * @return boolean true
+ */
+ public function canSetProperty($name)
+ {
+ return true;
+ }
+}
+
+?> \ No newline at end of file
diff --git a/framework/TComponent.php b/framework/TComponent.php
index 0befc27f..aa060750 100644
--- a/framework/TComponent.php
+++ b/framework/TComponent.php
@@ -169,7 +169,7 @@ class TComponent
* @param string the property name
* @return boolean whether the property is defined
*/
- final public function hasProperty($name)
+ public function hasProperty($name)
{
return method_exists($this,'get'.$name) || method_exists($this,'set'.$name);
}
@@ -181,7 +181,7 @@ class TComponent
* @param string the property name
* @return boolean whether the property can be read
*/
- final public function canGetProperty($name)
+ public function canGetProperty($name)
{
return method_exists($this,'get'.$name);
}
@@ -193,7 +193,7 @@ class TComponent
* @param string the property name
* @return boolean whether the property can be written
*/
- final public function canSetProperty($name)
+ public function canSetProperty($name)
{
return method_exists($this,'set'.$name);
}
diff --git a/framework/Web/UI/TControl.php b/framework/Web/UI/TControl.php
index f9c07a8a..6448ffcd 100644
--- a/framework/Web/UI/TControl.php
+++ b/framework/Web/UI/TControl.php
@@ -11,6 +11,11 @@
*/
/**
+ * Includes TAttributeCollection class
+ */
+Prado::using('System.Collections.TAttributeCollection');
+
+/**
* TControl class
*
* TControl is the base class for all components on a page hierarchy.
@@ -488,7 +493,7 @@ class TControl extends TComponent
return $attributes;
else
{
- $attributes=new TMap;
+ $attributes=new TAttributeCollection;
$this->setViewState('Attributes',$attributes,null);
return $attributes;
}
@@ -1549,12 +1554,12 @@ interface IPostBackEventHandler
* @param string the parameter associated with the postback event
*/
public function raisePostBackEvent($param);
-
+
/**
* Return an array of postback options.
* The array of options are serialized to passed to corresponding javascript component code.
* @return array options for javascript postback control
- */
+ */
public function getPostBackOptions();
}