/** * Adds a field to the registry. * * @param FormField $field The field * * @throws \InvalidArgumentException when the name is malformed */ public function add(FormField $field) { $segments = $this->getSegments($field->getName()); $target =& $this->fields; while ($segments) { if (!is_array($target)) { $target = array(); } $path = array_shift($segments); if ('' === $path) { $target =& $target[]; } else { $target =& $target[$path]; } } $target = $field; }
/** * Sets a named field. * * @param string $name The field name * * @return FormField The field instance */ public function set(Field\FormField $field) { $this->fields[$field->getName()] = $field; }