Example #1
0
 /**
  * Set a new field
  *
  * @param Field $field A instance from Field
  *
  * @throws Exception\FieldAlreadyRegistered
  *
  * @return $this Current instance of Input instance
  */
 public function field(Field $field)
 {
     $fieldName = $field->field();
     $fieldData = $this->source->get($fieldName);
     if (isset($this->fields[$fieldName])) {
         throw new Exception\FieldAlreadyRegistered($fieldName);
     }
     // Import the value into field instance
     if (!$field->import($fieldData)) {
         if ($errors = $field->errors()) {
             foreach ($errors as $error) {
                 $this->error(new Error($error->type(), $error->code(), $fieldName, $error->data()));
             }
         } else {
             $this->error(new Error('ERROR', 'FIELD_UNKNOWN_ERROR', $fieldName));
         }
     }
     $this->fields[$fieldName] = $field;
     return $this;
 }
Example #2
0
 /**
  * Add a sub field
  *
  * @param Base $field Field Instance of Field object
  *
  * @throws Exception\FieldAlreadyRegistered
  *
  * @return $this Current instance
  */
 public function sub(Base $field)
 {
     $fieldName = $field->field();
     if (isset($this->fields[$fieldName])) {
         throw new Exception\FieldAlreadyRegistered($fieldName, $this->field());
     }
     $this->fields[$fieldName] = $field;
     return $this;
 }
Example #3
0
 /**
  * Add a sub field
  *
  * @param Field Instance of Field object
  *
  * @return object Current instance
  */
 public function add(Base $field)
 {
     $fieldName = $field->field();
     if (isset($this->fields[$fieldName])) {
         throw new Exception\FieldAlreadyRegistered($fieldName, $this->field());
         return false;
         // No needed
     }
     $this->fields[$fieldName] = $field;
     return $this;
 }