Ejemplo n.º 1
0
 public function testCanNotAddWhenReadOnly()
 {
     $list = new TList(array(), true);
     try {
         $list->add(1);
         self::fail('An expected TInvalidOperationException was not raised');
     } catch (TInvalidOperationException $e) {
     }
 }
Ejemplo n.º 2
0
 public function getValidators($validationGroup = null)
 {
     if (!$this->_validators) {
         $this->_validators = new TList();
     }
     if (empty($validationGroup) === true) {
         return $this->_validators;
     } else {
         $list = new TList();
         foreach ($this->_validators as $validator) {
             if ($validator->getValidationGroup() === $validationGroup) {
                 $list->add($validator);
             }
         }
         return $list;
     }
 }
Ejemplo n.º 3
0
 /**
  * Validates if the parameter is a valid data source.
  * If it is a string or an array, it will be converted as a TList object.
  * @return Traversable the data that is traversable
  * @throws TInvalidDataTypeException if the data is neither null nor Traversable
  */
 protected function validateDataSource($value)
 {
     if (is_string($value)) {
         $list = new TList();
         foreach (TPropertyValue::ensureArray($value) as $key => $value) {
             if (is_array($value)) {
                 $list->add($value);
             } else {
                 $list->add(array($value, is_string($key) ? $key : $value));
             }
         }
         return $list;
     } else {
         if (is_array($value)) {
             return new TMap($value);
         } else {
             if ($value instanceof Traversable || $value === null) {
                 return $value;
             } else {
                 throw new TInvalidDataTypeException('databoundcontrol_datasource_invalid', get_class($this));
             }
         }
     }
 }
Ejemplo n.º 4
0
 /**
  * Validates if the parameter is a valid data source.
  * If it is a string or an array, it will be converted as a TList object.
  * @param Traversable|array|string data source to be validated
  * @return Traversable the data that is traversable
  * @throws TInvalidDataTypeException if the data is neither null nor Traversable
  */
 protected function validateDataSource($value)
 {
     if (is_string($value)) {
         $list = new TList();
         foreach (TPropertyValue::ensureArray($value) as $key => $value) {
             if (is_array($value)) {
                 $list->add($value);
             } else {
                 $list->add(array($value, is_string($key) ? $key : $value));
             }
         }
         return $list;
     } else {
         if (is_array($value)) {
             return new TMap($value);
         } else {
             if ($value instanceof TDbDataReader) {
                 // read array from TDbDataReader since it's forward-only stream and can only be traversed once
                 return $value->readAll();
             } else {
                 if ($value instanceof Traversable || $value === null) {
                     return $value;
                 } else {
                     throw new TInvalidDataTypeException('databoundcontrol_datasource_invalid', get_class($this));
                 }
             }
         }
     }
 }
Ejemplo n.º 5
0
 /**
  * @return TList list of all child elements that have the specified tag-name
  */
 public function getElementsByTagName($tagName)
 {
     $list = new TList();
     if ($this->_elements) {
         foreach ($this->_elements as $element) {
             if ($element->_tagName === $tagName) {
                 $list->add($element);
             }
         }
     }
     return $list;
 }