private function resolve() { $key = $this->resolveProperty('key'); if (isset($this->fields[$key])) { $field = $this->fields[$key]; } elseif ($this->default !== null) { $field = $this->default; } else { throw new InvalidKeyException("Value '{$key}' does not correspond to a valid conditional key. Presented keys: '" . implode("', '", array_keys($this->fields)) . "'"); } // get form cache if ($field instanceof AbstractField) { return $field; } $field = Factory::get($field); $field->setDataSet($this->getDataSet()); // cache field instance if (isset($this->fields[$key])) { $this->fields[$key] = $field; } else { $this->default = $field; } return $field; }
/** * Recursively creates field instances form their declarations. * * @param array $fieldArray Array of declarations. * @throws ConfigurationException If one of declarations are invalid. */ private function initFromArray(array $fieldArray = []) { foreach ($fieldArray as $fieldName => $fieldParams) { $this->addField($fieldName, Factory::get($fieldParams)); } }
/** * @param array|AbstractField $field * @return $this */ public function setField($field) { if (is_array($field)) { $field = Factory::get($field); } $this->field = $field; return $this; }