/** * @return array */ public function getFields() { if (null === $this->fields) { $this->fields = []; $definition = is_array(static::fields()) ? static::fields() : []; foreach ($definition as $key => $field) { if (is_string($key) && is_array($field)) { $type = isset($field['type']) ? $field['type'] : 'raw'; $type = $this->getType($type); $default = isset($field['default']) ? $field['default'] : null; $required = isset($field['required']) && $field['required'] !== false; $field = new Field($key, $type, $default, $required); } if ($field instanceof FieldInterface) { $this->fields[$field->getName()] = $field; if ($field->getRequired()) { $this->required[] = $field->getName(); } parent::offsetSet($field->getName(), $field->getDefault()); } } $this->required = array_unique($this->required); } return $this->fields; }