Example #1
0
 /**
  * @inheritdoc
  */
 public function offsetSet($offset, $item)
 {
     if ($offset == null) {
         $offset = $this->count();
     }
     if ($this->offsetExists($offset)) {
         $this->data[$offset]->setValue($item);
     } else {
         $field = BaseField::createField($this->_fieldConfig)->link($this, $offset);
         if ($item !== null) {
             $field->setValue($item);
         }
         $this->data[$offset] = $field;
         $rules = $field->rules();
         foreach ($rules as $rule) {
             $this->addRule((string) $rule[0], $rule[1], array_slice($rule, 2));
         }
     }
 }
Example #2
0
 /**
  * Defines an attribute.
  * @param string $name the attribute name
  * @param BaseField|string|array $field the attribute value
  */
 public function defineAttribute($name, $field)
 {
     $field = BaseField::createField($field);
     $field->link($this, $name);
     $this->_attributes[$name] = $field;
 }