From 01bc363ac789cfb9d644ce82a949da5cd7e1c220 Mon Sep 17 00:00:00 2001 From: xue <> Date: Tue, 31 Jan 2006 00:01:49 +0000 Subject: Modified TList and TMap implementation so that they can be more easily extended. --- framework/Collections/TAttributeCollection.php | 50 ++++++++++- framework/Collections/TList.php | 108 ++++------------------- framework/Collections/TMap.php | 71 ++------------- framework/Data/TXmlDocument.php | 47 +++++----- framework/Exceptions/messages.txt | 22 ++++- framework/Security/TAuthorizationRule.php | 18 ++-- framework/TComponent.php | 4 +- framework/Web/THttpRequest.php | 42 +++++---- framework/Web/UI/TControl.php | 43 +++++---- framework/Web/UI/TTemplateControl.php | 2 +- framework/Web/UI/WebControls/TDataGrid.php | 34 ++++--- framework/Web/UI/WebControls/TDataList.php | 17 ++-- framework/Web/UI/WebControls/TDataSourceView.php | 2 +- framework/Web/UI/WebControls/TListControl.php | 21 +---- framework/Web/UI/WebControls/TRepeater.php | 17 ++-- framework/Web/UI/WebControls/TTable.php | 83 +++++++++-------- 16 files changed, 271 insertions(+), 310 deletions(-) (limited to 'framework') diff --git a/framework/Collections/TAttributeCollection.php b/framework/Collections/TAttributeCollection.php index c8870919..abeb3c53 100644 --- a/framework/Collections/TAttributeCollection.php +++ b/framework/Collections/TAttributeCollection.php @@ -54,7 +54,6 @@ class TAttributeCollection extends TMap */ public function __get($name) { - $name=strtolower($name); return $this->contains($name)?$this->itemAt($name):parent::__get($name); } @@ -68,7 +67,52 @@ class TAttributeCollection extends TMap */ public function __set($name,$value) { - $this->add(strtolower($name),$value); + $this->add($name,$value); + } + + /** + * Returns the item with the specified key. + * This overrides the parent implementation by converting the key to lower case first. + * @param mixed the key + * @return mixed the element at the offset, null if no element is found at the offset + */ + public function itemAt($key) + { + return parent::itemAt(strtolower($key)); + } + + + /** + * Adds an item into the map. + * This overrides the parent implementation by converting the key to lower case first. + * @param mixed key + * @param mixed value + */ + public function add($key,$value) + { + parent::add(strtolower($key),$value); + } + + /** + * Removes an item from the map by its key. + * This overrides the parent implementation by converting the key to lower case first. + * @param mixed the key of the item to be removed + * @return mixed the removed value, null if no such key exists. + */ + public function remove($key) + { + return parent::remove(strtolower($key)); + } + + /** + * Returns whether the specified is in the map. + * This overrides the parent implementation by converting the key to lower case first. + * @param mixed the key + * @return boolean whether the map contains an item with the specified key + */ + public function contains($key) + { + return parent::contains(strtolower($key)); } /** @@ -80,7 +124,6 @@ class TAttributeCollection extends TMap */ public function hasProperty($name) { - $name=strtolower($name); return $this->contains($name) || parent::hasProperty($name); } @@ -93,7 +136,6 @@ class TAttributeCollection extends TMap */ public function canGetProperty($name) { - $name=strtolower($name); return $this->contains($name) || parent::canGetProperty($name); } diff --git a/framework/Collections/TList.php b/framework/Collections/TList.php index 2946053b..f2628231 100644 --- a/framework/Collections/TList.php +++ b/framework/Collections/TList.php @@ -29,10 +29,8 @@ * Note, count($list) will always return 1. You should use {@link getCount()} * to determine the number of items in the list. * - * To extend TList by doing additional operations with each added or removed item, - * you can override {@link addedItem} and {@link removedItem}. - * You can also override {@link canAddItem} and {@link canRemoveItem} to - * control whether to add or remove a particular item. + * To extend TList by doing additional operations with each addition or removal + * operations, override {@link insertAt()}, and {@link removeAt()}. * * @author Qiang Xue * @version $Revision: $ $Date: $ @@ -101,17 +99,10 @@ class TList extends TComponent implements IteratorAggregate,ArrayAccess /** * Appends an item at the end of the list. * @param mixed new item - * @throws TInvalidOperationException If the item is not allowed to be added */ public function add($item) { - if($this->canAddItem($item)) - { - $this->_d[$this->_c++]=$item; - $this->addedItem($item); - } - else - throw new TInvalidOperationException('list_addition_disallowed'); + $this->insertAt($this->_c,$item); } /** @@ -121,26 +112,18 @@ class TList extends TComponent implements IteratorAggregate,ArrayAccess * @param integer the speicified position. * @param mixed new item * @throws TInvalidDataValueException If the index specified exceeds the bound - * @throws TInvalidOperationException If the item is not allowed to be added */ - public function insert($index,$item) + public function insertAt($index,$item) { - if($this->canAddItem($item)) + if($index===$this->_c) + $this->_d[$this->_c++]=$item; + else if($index>=0 && $index<$this->_c) { - if($index===$this->_c) - $this->add($item); - else if($index>=0 && $index<$this->_c) - { - array_splice($this->_d,$index,0,array($item)); - $this->_c++; - $this->addedItem($item); - } - else - throw new TInvalidDataValueException('list_index_invalid',$index); + array_splice($this->_d,$index,0,array($item)); + $this->_c++; } else - throw new TInvalidOperationException('list_addition_disallowed'); - + throw new TInvalidDataValueException('list_index_invalid',$index); } /** @@ -148,18 +131,12 @@ class TList extends TComponent implements IteratorAggregate,ArrayAccess * The list will first search for the item. * The first item found will be removed from the list. * @param mixed the item to be removed. - * @throws TInvalidOperationException If the item cannot be removed * @throws TInvalidDataValueException If the item does not exist */ public function remove($item) { if(($index=$this->indexOf($item))>=0) - { - if($this->canRemoveItem($item)) - $this->removeAt($index); - else - throw new TInvalidOperationException('list_item_unremovable'); - } + $this->removeAt($index); else throw new TInvalidDataValueException('list_item_inexistent'); } @@ -169,25 +146,18 @@ class TList extends TComponent implements IteratorAggregate,ArrayAccess * @param integer the index of the item to be removed. * @return mixed the removed item. * @throws TOutOfRangeException If the index specified exceeds the bound - * @throws TInvalidOperationException If the item cannot be removed */ public function removeAt($index) { if(isset($this->_d[$index])) { $item=$this->_d[$index]; - if($this->canRemoveItem($item)) - { - if($index===$this->_c-1) - unset($this->_d[$index]); - else - array_splice($this->_d,$index,1); - $this->_c--; - $this->removedItem($item); - return $item; - } + if($index===$this->_c-1) + unset($this->_d[$index]); else - throw new TInvalidOperationException('list_item_unremovable'); + array_splice($this->_d,$index,1); + $this->_c--; + return $item; } else throw new TInvalidDataValueException('list_index_invalid',$index); @@ -303,11 +273,11 @@ class TList extends TComponent implements IteratorAggregate,ArrayAccess public function offsetSet($offset,$item) { if($offset===null || $offset===$this->_c) - $this->add($item); + $this->insertAt($this->_c,$item); else { $this->removeAt($offset); - $this->insert($offset,$item); + $this->insertAt($offset,$item); } } @@ -321,48 +291,6 @@ class TList extends TComponent implements IteratorAggregate,ArrayAccess { $this->removeAt($offset); } - - /** - * This method is invoked after an item is successfully added to the list. - * You can override this method to provide customized processing of the addition. - * @param mixed the newly added item - */ - protected function addedItem($item) - { - } - - /** - * This method is invoked after an item is successfully removed from the list. - * You can override this method to provide customized processing of the removal. - * @param mixed the removed item - */ - protected function removedItem($item) - { - } - - /** - * This method is invoked before adding an item to the list. - * If it returns true, the item will be added to the list, otherwise not. - * You can override this method to decide whether a specific can be added. - * @param mixed item to be added - * @return boolean whether the item can be added to the list - */ - protected function canAddItem($item) - { - return true; - } - - /** - * This method is invoked before removing an item from the list. - * If it returns true, the item will be removed from the list, otherwise not. - * You can override this method to decide whether a specific can be removed. - * @param mixed item to be removed - * @return boolean whether the item can be removed to the list - */ - protected function canRemoveItem($item) - { - return true; - } } diff --git a/framework/Collections/TMap.php b/framework/Collections/TMap.php index d5a44322..be37a46b 100644 --- a/framework/Collections/TMap.php +++ b/framework/Collections/TMap.php @@ -100,19 +100,12 @@ class TMap extends TComponent implements IteratorAggregate,ArrayAccess * Note, if the specified key already exists, the old value will be removed first. * @param mixed key * @param mixed value - * @throws TInvalidOperationException if the item cannot be added */ public function add($key,$value) { - if($this->canAddItem($key,$value)) - { - if(isset($this->_d[$key])) - $this->remove($key); - $this->_d[$key]=$value; - $this->addedItem($key,$value); - } - else - throw new TInvalidOperationException('map_addition_disallowed'); + if(isset($this->_d[$key])) + $this->remove($key); + $this->_d[$key]=$value; } /** @@ -126,14 +119,8 @@ class TMap extends TComponent implements IteratorAggregate,ArrayAccess if(isset($this->_d[$key])) { $value=$this->_d[$key]; - if($this->canRemoveItem($key,$value)) - { - unset($this->_d[$key]); - $this->removedItem($key,$value); - return $value; - } - else - throw new TInvalidOperationException('map_item_unremovable'); + unset($this->_d[$key]); + return $value; } else return null; @@ -220,7 +207,7 @@ class TMap extends TComponent implements IteratorAggregate,ArrayAccess */ public function offsetGet($offset) { - return isset($this->_d[$offset]) ? $this->_d[$offset] : null; + return $this->itemAt($offset); } /** @@ -243,52 +230,6 @@ class TMap extends TComponent implements IteratorAggregate,ArrayAccess { $this->remove($offset); } - - /** - * This method is invoked after an item is successfully added to the map. - * You can override this method provide customized processing of the addition. - * @param string key to the item - * @param mixed the newly added item - */ - protected function addedItem($key,$item) - { - } - - /** - * This method is invoked after an item is successfully removed from the map. - * You can override this method provide customized processing of the removal. - * @param string key to the item - * @param mixed the removed item - */ - protected function removedItem($key,$item) - { - } - - /** - * This method is invoked before adding an item to the map. - * If it returns true, the item will be added to the map, otherwise not. - * You can override this method to decide whether a specific can be added. - * @param string key to the item - * @param mixed item to be added - * @return boolean whether the item can be added to the map - */ - protected function canAddItem($key,$item) - { - return true; - } - - /** - * This method is invoked before removing an item from the map. - * If it returns true, the item will be removed from the map, otherwise not. - * You can override this method to decide whether a specific can be removed. - * @param string key to the item - * @param mixed item to be removed - * @return boolean whether the item can be removed to the map - */ - protected function canRemoveItem($key,$item) - { - return true; - } } /** diff --git a/framework/Data/TXmlDocument.php b/framework/Data/TXmlDocument.php index 0b37258d..bb22b254 100644 --- a/framework/Data/TXmlDocument.php +++ b/framework/Data/TXmlDocument.php @@ -416,36 +416,41 @@ class TXmlElementList extends TList return $this->_o; } - /** - * Overrides the parent implementation with customized processing of the newly added item. - * @param mixed the newly added item - */ - protected function addedItem($item) - { - if($item->getParent()!==null) - $item->getParent()->getElements()->remove($item); - $item->setParent($this->_o); - } /** - * Overrides the parent implementation with customized processing of the removed item. - * @param mixed the removed item + * Inserts an item at the specified position. + * This overrides the parent implementation by performing additional + * operations for each newly added TXmlElement object. + * @param integer the speicified position. + * @param mixed new item + * @throws TInvalidDataTypeException if the item to be inserted is not a TXmlElement object. */ - protected function removedItem($item) + public function insertAt($index,$item) { - $item->setParent(null); + if($item instanceof TXmlElement) + { + parent::insertAt($index,$item); + if($item->getParent()!==null) + $item->getParent()->getElements()->remove($item); + $item->setParent($this->_o); + } + else + throw new TInvalidDataTypeException('xmlelementlist_xmlelement_required'); } /** - * This method is invoked before adding an item to the map. - * If it returns true, the item will be added to the map, otherwise not. - * You can override this method to decide whether a specific can be added. - * @param mixed item to be added - * @return boolean whether the item can be added to the map + * Removes an item at the specified position. + * This overrides the parent implementation by performing additional + * cleanup work when removing a TXmlElement object. + * @param integer the index of the item to be removed. + * @return mixed the removed item. */ - protected function canAddItem($item) + public function removeAt($index) { - return ($item instanceof TXmlElement); + $item=parent::removeAt($index); + if($item instanceof TXmlElement) + $item->setParent(null); + return $item; } } diff --git a/framework/Exceptions/messages.txt b/framework/Exceptions/messages.txt index 69015d48..8b739623 100644 --- a/framework/Exceptions/messages.txt +++ b/framework/Exceptions/messages.txt @@ -15,8 +15,6 @@ component_statements_invalid = Component '%s' is evaluating invalid PHP statem propertyvalue_enumvalue_invalid = Value '%s' is a not valid enumeration value (%s). list_index_invalid = Index '%d' is out of range. -list_addition_disallowed = The new item cannot be added to the list. -list_item_unremovable = The item cannot be removed from the list. list_item_inexistent = The item cannot be found in the list. list_data_not_iterable = Data must be either an array or an object implementing Traversable interface. @@ -111,9 +109,13 @@ template_eventhandler_invalid = An invalid event handler is attached to %s's e xmldocument_file_read_failed = TXmlDocument is unable to read file '%s'. xmldocument_file_write_failed = TXmlDocument is unable to write file '%s'. +xmlelementlist_xmlelement_required = TXmlElementList can only accept TXmlElement objects. + authorizationrule_action_invalid = TAuthorizationRule.Action can only take 'allow' or 'deny' as the value. authorizationrule_verb_invalid = TAuthorizationRule.Verb can only take 'get' or 'post' as the value. +authorizationrulecollection_authorizationrule_required = TAuthorizationRuleCollection can only accept TAuthorizationRule objects. + usermanager_userfile_invalid = TUserManager.UserFile '%s' is not a valid file. usermanager_userfile_unchangeable = TUserManager.UserFile cannot be modified. The user module has been initialized already. @@ -141,6 +143,8 @@ control_enabletheming_unchangeable = %s.EnableTheming cannot be modified after control_stylesheet_applied = StyleSheet skin has already been applied to %s. control_id_nonunique = %s.ID '%s' is not unique among all controls under the same naming container. +controllist_control_required = TControlList can only accept strings or TControl objects. + webcontrol_accesskey_invalid = %s.AccessKey '%s' is invalid. It must be a single character only. webcontrol_style_invalid = %s.Style must take string value only. @@ -189,4 +193,16 @@ comparevalidator_controltocompare_invalid = TCompareValidator.ControlToCompare c repeater_template_required = TRepeater.%s requires a template instance implementing ITemplate interface. datalist_template_required = TDataList.%s requires a template instance implementing ITemplate interface. -templatecolumn_template_required = TTemplateColumn.%s requires a template instance implementing ITemplate interface. \ No newline at end of file +templatecolumn_template_required = TTemplateColumn.%s requires a template instance implementing ITemplate interface. + +repeateritemcollection_repeateritem_required = TRepeaterItemCollection can only accept TRepeaterItem objects. + +datagriditemcollection_datagriditem_required = TDataGridItemCollection can only accept TDataGridItem objects. + +datagridcolumncollection_datagridcolumn_required = TDataGridColumnCollection can only accept TDataGridColumn objects. + +datalistitemcollection_datalistitem_required = TDataListItemCollection can only accept TDataListItem objects. + +tablerowcollection_tablerow_required = TTableRowCollection can only accept TTableRow objects. + +tablecellcollection_tablerow_required = TTableCellCollection can only accept TTableCell objects. \ No newline at end of file diff --git a/framework/Security/TAuthorizationRule.php b/framework/Security/TAuthorizationRule.php index 2ee6de49..81955a44 100644 --- a/framework/Security/TAuthorizationRule.php +++ b/framework/Security/TAuthorizationRule.php @@ -200,13 +200,19 @@ class TAuthorizationRuleCollection extends TList } /** - * Ensures that only instance of TAuthorizationRule is added to the collection. - * @param mixed item to be added to the collection - * @return boolean whether the item can be added to the collection - */ - protected function canAddItem($item) + * Inserts an item at the specified position. + * This overrides the parent implementation by performing additional + * operations for each newly added TAuthorizationRule object. + * @param integer the speicified position. + * @param mixed new item + * @throws TInvalidDataTypeException if the item to be inserted is not a TAuthorizationRule object. + */ + public function insertAt($index,$item) { - return ($item instanceof TAuthorizationRule); + if($item instanceof TAuthorizationRule) + parent::insertAt($index,$item); + else + throw new TInvalidDataTypeException('authorizationrulecollection_authorizationrule_required'); } } diff --git a/framework/TComponent.php b/framework/TComponent.php index cc5fa1b5..6641fd1a 100644 --- a/framework/TComponent.php +++ b/framework/TComponent.php @@ -300,12 +300,12 @@ class TComponent * getting and setting properties, e.g., * * $component->OnClick[]=array($object,'buttonClicked'); - * $component->OnClick->insert(0,array($object,'buttonClicked')); + * $component->OnClick->insertAt(0,array($object,'buttonClicked')); * * which are equivalent to the following * * $component->getEventHandlers('OnClick')->add(array($object,'buttonClicked')); - * $component->getEventHandlers('OnClick')->insert(0,array($object,'buttonClicked')); + * $component->getEventHandlers('OnClick')->insertAt(0,array($object,'buttonClicked')); * * * @param string the event name diff --git a/framework/Web/THttpRequest.php b/framework/Web/THttpRequest.php index 2a3a35aa..ba626d07 100644 --- a/framework/Web/THttpRequest.php +++ b/framework/Web/THttpRequest.php @@ -140,7 +140,7 @@ class THttpRequest extends TMap implements IModule $_COOKIE=$this->stripSlashes($_COOKIE); } - $this->copyfrom(array_merge($_GET,$_POST)); + $this->copyFrom(array_merge($_GET,$_POST)); $this->_initialized=true; $this->getApplication()->setRequest($this); @@ -487,32 +487,38 @@ class THttpCookieCollection extends TList } /** - * Adds the cookie if owner of this collection is of THttpResponse. - * This method will be invoked whenever an item is added to the collection. + * Inserts an item at the specified position. + * This overrides the parent implementation by performing additional + * operations for each newly added THttpCookie object. + * @param integer the speicified position. + * @param mixed new item + * @throws TInvalidDataTypeException if the item to be inserted is not a THttpCookie object. */ - protected function addedItem($item) + public function insertAt($index,$item) { - if($this->_o instanceof THttpResponse) - $this->_o->addCookie($item); + if($item instanceof THttpCookie) + { + parent::insertAt($index,$item); + if($this->_o instanceof THttpResponse) + $this->_o->addCookie($item); + } + else + throw new TInvalidDataTypeException('authorizationrulecollection_authorizationrule_required'); } /** - * Removes the cookie if owner of this collection is of THttpResponse. - * This method will be invoked whenever an item is removed from the collection. + * Removes an item at the specified position. + * This overrides the parent implementation by performing additional + * cleanup work when removing a TCookie object. + * @param integer the index of the item to be removed. + * @return mixed the removed item. */ - protected function removedItem($item) + public function removeAt($index) { + $item=parent::removeAt($index); if($this->_o instanceof THttpResponse) $this->_o->removeCookie($item); - } - - /** - * Restricts acceptable item of this collection to THttpCookie. - * This method will be invoked whenever an item is to be added into the collection. - */ - protected function canAddItem($item) - { - return ($item instanceof THttpCookie); + return $item; } } diff --git a/framework/Web/UI/TControl.php b/framework/Web/UI/TControl.php index 7b9fee4e..ee1b8e11 100644 --- a/framework/Web/UI/TControl.php +++ b/framework/Web/UI/TControl.php @@ -1487,32 +1487,39 @@ class TControlList extends TList } /** - * Overrides the parent implementation with customized processing of the newly added item. - * @param mixed the newly added item - */ - protected function addedItem($item) - { - if($item instanceof TControl) + * Inserts an item at the specified position. + * This overrides the parent implementation by performing additional + * operations for each newly added child control. + * @param integer the speicified position. + * @param mixed new item + * @throws TInvalidDataTypeException if the item to be inserted is neither a string nor a TControl. + */ + public function insertAt($index,$item) + { + if(is_string($item)) + parent::insertAt($index,$item); + else if($item instanceof TControl) + { + parent::insertAt($index,$item); $this->_o->addedControl($item); + } + else + throw new TInvalidDataTypeException('controllist_control_required'); } /** - * Overrides the parent implementation with customized processing of the removed item. - * @param mixed the removed item + * Removes an item at the specified position. + * This overrides the parent implementation by performing additional + * cleanup work when removing a child control. + * @param integer the index of the item to be removed. + * @return mixed the removed item. */ - protected function removedItem($item) + public function removeAt($index) { + $item=parent::removeAt($index); if($item instanceof TControl) $this->_o->removedControl($item); - } - - /** - * Only string or instance of TControl can be added into collection. - * @param mixed the item to be added - */ - protected function canAddItem($item) - { - return is_string($item) || ($item instanceof TControl); + return $item; } /** diff --git a/framework/Web/UI/TTemplateControl.php b/framework/Web/UI/TTemplateControl.php index 79ada7d4..d7f1868b 100644 --- a/framework/Web/UI/TTemplateControl.php +++ b/framework/Web/UI/TTemplateControl.php @@ -165,7 +165,7 @@ class TTemplateControl extends TControl implements INamingContainer if(isset($this->_placeholders[$id])) { list($parent,$loc)=$this->_placeholders[$id]; - $parent->getControls()->insert($loc,$content); + $parent->getControls()->insertAt($loc,$content); } } diff --git a/framework/Web/UI/WebControls/TDataGrid.php b/framework/Web/UI/WebControls/TDataGrid.php index 646ead01..0aad717d 100644 --- a/framework/Web/UI/WebControls/TDataGrid.php +++ b/framework/Web/UI/WebControls/TDataGrid.php @@ -1553,15 +1553,18 @@ class TDataGridItem extends TTableRow implements INamingContainer class TDataGridItemCollection extends TList { /** - * Returns true only when the item to be added is a {@link TDataGridItem}. - * This method is invoked before adding an item to the list. - * If it returns true, the item will be added to the list, otherwise not. - * @param mixed item to be added - * @return boolean whether the item can be added to the list + * Inserts an item at the specified position. + * This overrides the parent implementation by inserting only TDataGridItem. + * @param integer the speicified position. + * @param mixed new item + * @throws TInvalidDataTypeException if the item to be inserted is not a TDataGridItem. */ - protected function canAddItem($item) + public function insertAt($index,$item) { - return ($item instanceof TDataGridItem); + if($item instanceof TDataGridItem) + parent::insertAt($index,$item); + else + throw new TInvalidDataTypeException('datagriditemcollection_datagriditem_required'); } } @@ -1578,15 +1581,18 @@ class TDataGridItemCollection extends TList class TDataGridColumnCollection extends TList { /** - * Returns true only when the item to be added is a {@link TDataGridItem}. - * This method is invoked before adding an item to the list. - * If it returns true, the item will be added to the list, otherwise not. - * @param mixed item to be added - * @return boolean whether the item can be added to the list + * Inserts an item at the specified position. + * This overrides the parent implementation by inserting only TDataGridColumn. + * @param integer the speicified position. + * @param mixed new item + * @throws TInvalidDataTypeException if the item to be inserted is not a TDataGridColumn. */ - protected function canAddItem($item) + public function insertAt($index,$item) { - return ($item instanceof TDataGridColumn); + if($item instanceof TDataGridColumn) + parent::insertAt($index,$item); + else + throw new TInvalidDataTypeException('datagridcolumncollection_datagridcolumn_required'); } } diff --git a/framework/Web/UI/WebControls/TDataList.php b/framework/Web/UI/WebControls/TDataList.php index c0d74974..47b60cd6 100644 --- a/framework/Web/UI/WebControls/TDataList.php +++ b/framework/Web/UI/WebControls/TDataList.php @@ -1354,15 +1354,18 @@ class TDataListItem extends TWebControl implements INamingContainer class TDataListItemCollection extends TList { /** - * Returns true only when the item to be added is a {@link TDataListItem}. - * This method is invoked before adding an item to the list. - * If it returns true, the item will be added to the list, otherwise not. - * @param mixed item to be added - * @return boolean whether the item can be added to the list + * Inserts an item at the specified position. + * This overrides the parent implementation by inserting only TDataListItem. + * @param integer the speicified position. + * @param mixed new item + * @throws TInvalidDataTypeException if the item to be inserted is not a TDataListItem. */ - protected function canAddItem($item) + public function insertAt($index,$item) { - return ($item instanceof TDataListItem); + if($item instanceof TDataListItem) + parent::insertAt($index,$item); + else + throw new TInvalidDataTypeException('datalistitemcollection_datalistitem_required'); } } diff --git a/framework/Web/UI/WebControls/TDataSourceView.php b/framework/Web/UI/WebControls/TDataSourceView.php index ab79e74c..c20556bb 100644 --- a/framework/Web/UI/WebControls/TDataSourceView.php +++ b/framework/Web/UI/WebControls/TDataSourceView.php @@ -103,7 +103,7 @@ abstract class TDataSourceView extends TComponent * @param array|TMap * @return integer affected rows */ - public function insert($values) + public function insertAt($values) { throw new TNotSupportedException('datasourceview_insert_unsupported'); } diff --git a/framework/Web/UI/WebControls/TListControl.php b/framework/Web/UI/WebControls/TListControl.php index 6faccf31..8d2959b4 100644 --- a/framework/Web/UI/WebControls/TListControl.php +++ b/framework/Web/UI/WebControls/TListControl.php @@ -566,21 +566,6 @@ abstract class TListControl extends TDataBoundControl */ class TListItemCollection extends TList { - /** - * Appends an item to the collection. - * @param TListItem the item to be appended. - * @throws TInvalidDataTypeException if the item being appended is neither a string nor a TListItem - */ - public function add($item) - { - if(is_string($item)) - parent::add(new TListItem($item)); - else if($item instanceof TListItem) - parent::add($item); - else - throw new TInvalidDataTypeException('listitemcollection_item_invalid'); - } - /** * Inserts an item into the collection. * @param integer the location where the item will be inserted. @@ -588,12 +573,12 @@ class TListItemCollection extends TList * @param TListItem the item to be inserted. * @throws TInvalidDataTypeException if the item being inserted is neither a string nor TListItem */ - public function insert($index,$item) + public function insertAt($index,$item) { if(is_string($item)) - parent::insert($index,new TListItem($item)); + parent::insertAt($index,new TListItem($item)); else if($item instanceof TListItem) - parent::insert($index,$item); + parent::insertAt($index,$item); else throw new TInvalidDataTypeException('listitemcollection_item_invalid'); } diff --git a/framework/Web/UI/WebControls/TRepeater.php b/framework/Web/UI/WebControls/TRepeater.php index 6aa6b461..a122f387 100644 --- a/framework/Web/UI/WebControls/TRepeater.php +++ b/framework/Web/UI/WebControls/TRepeater.php @@ -661,15 +661,18 @@ class TRepeaterItem extends TControl implements INamingContainer class TRepeaterItemCollection extends TList { /** - * Returns true only when the item to be added is a {@link TRepeaterItem}. - * This method is invoked before adding an item to the list. - * If it returns true, the item will be added to the list, otherwise not. - * @param mixed item to be added - * @return boolean whether the item can be added to the list + * Inserts an item at the specified position. + * This overrides the parent implementation by inserting only TRepeaterItem. + * @param integer the speicified position. + * @param mixed new item + * @throws TInvalidDataTypeException if the item to be inserted is not a TRepeaterItem. */ - protected function canAddItem($item) + public function insertAt($index,$item) { - return ($item instanceof TRepeaterItem); + if($item instanceof TRepeaterItem) + parent::insertAt($index,$item); + else + throw new TInvalidDataTypeException('repeateritemcollection_repeateritem_required'); } } diff --git a/framework/Web/UI/WebControls/TTable.php b/framework/Web/UI/WebControls/TTable.php index dab0fb60..fb70e66c 100644 --- a/framework/Web/UI/WebControls/TTable.php +++ b/framework/Web/UI/WebControls/TTable.php @@ -712,32 +712,38 @@ class TTableRowCollection extends TList } /** - * Only string or instance of TControl can be added into collection. - * @param mixed the item to be added + * Inserts an item at the specified position. + * This overrides the parent implementation by performing additional + * operations for each newly added table row. + * @param integer the speicified position. + * @param mixed new item + * @throws TInvalidDataTypeException if the item to be inserted is not a TTableRow object. */ - protected function canAddItem($item) + public function insertAt($index,$item) { - return ($item instanceof TTableRow); - } - - /** - * Overrides the parent implementation with customized processing of the newly added item. - * @param mixed the newly added item - */ - protected function addedItem($item) - { - if($this->_owner) - $this->_owner->getControls()->add($item); + if($item instanceof TTableRow) + { + parent::insertAt($index,$item); + if($this->_owner) + $this->_owner->getControls()->insertAt($index,$item); + } + else + throw new TInvalidDataTypeException('tablerowcollection_tablerow_required'); } /** - * Overrides the parent implementation with customized processing of the removed item. - * @param mixed the removed item + * Removes an item at the specified position. + * This overrides the parent implementation by performing additional + * cleanup work when removing a table row. + * @param integer the index of the item to be removed. + * @return mixed the removed item. */ - protected function removedItem($item) + public function removeAt($index) { - if($this->_owner) + $item=parent::removeAt($index); + if($item instanceof TTableRow) $this->_owner->getControls()->remove($item); + return $item; } } @@ -768,33 +774,40 @@ class TTableCellCollection extends TList $this->_owner=$owner; } - /** - * Only string or instance of TTableCell can be added into collection. - * @param mixed the item to be added - */ - protected function canAddItem($item) - { - return ($item instanceof TTableCell); - } /** - * Overrides the parent implementation with customized processing of the newly added item. - * @param mixed the newly added item + * Inserts an item at the specified position. + * This overrides the parent implementation by performing additional + * operations for each newly added table cell. + * @param integer the speicified position. + * @param mixed new item + * @throws TInvalidDataTypeException if the item to be inserted is not a TTableCell object. */ - protected function addedItem($item) + public function insertAt($index,$item) { - if($this->_owner) - $this->_owner->getControls()->add($item); + if($item instanceof TTableCell) + { + parent::insertAt($index,$item); + if($this->_owner) + $this->_owner->getControls()->insertAt($index,$item); + } + else + throw new TInvalidDataTypeException('tablecellcollection_tablecell_required'); } /** - * Overrides the parent implementation with customized processing of the removed item. - * @param mixed the removed item + * Removes an item at the specified position. + * This overrides the parent implementation by performing additional + * cleanup work when removing a table cell. + * @param integer the index of the item to be removed. + * @return mixed the removed item. */ - protected function removedItem($item) + public function removeAt($index) { - if($this->_owner) + $item=parent::removeAt($index); + if($item instanceof TTableCell) $this->_owner->getControls()->remove($item); + return $item; } } ?> \ No newline at end of file -- cgit v1.2.3