Example #1
0
 /**
  * Add a field
  *
  * Supports a field instance or a config array, in that case a new
  * field instance wil be created based on the options.
  *
  * @throws InvalidArgumentException
  * @param  Field|array              $field
  * @return self                     Provides fluent interface
  */
 public function addField($field)
 {
     if (is_array($field)) {
         $field = new Field($field);
     }
     $key = $field->getKey();
     if (0 === strlen($key)) {
         throw new InvalidArgumentException('A field must have a key value');
     }
     //double add calls for the same field are ignored, but non-unique keys cause an exception
     //@todo add trigger_error with a notice for double add calls?
     if (array_key_exists($key, $this->fields) && $this->fields[$key] !== $field) {
         throw new InvalidArgumentException('A field must have a unique key value');
     } else {
         $this->fields[$key] = $field;
     }
     return $this;
 }
Example #2
0
 public function testSetAndGetKey()
 {
     $this->field->setKey('testkey');
     $this->assertEquals('testkey', $this->field->getKey());
 }