/** * Factory method * * @param string $type Element type * @param array $options Element options * @param array $attr HTML attributes * @return Element */ public function build($type, array $options = [], array $attr = []) { if (isset($this->builder)) { return $this->builder->build($type, $options, $attr); } $this->convertCustomType($type, $options, $attr); if (is_string($type) && $type[0] === ':') { $method = 'build' . str_replace(' ', '', ucwords(preg_replace('/[^a-zA-Z0-9]/', ' ', substr($type, 1)))); if (!method_exists($this, $method)) { throw new \Exception("Unknown field '" . substr($type, 1) . "'"); } return $this->{$method}(null, $options, $attr); } $element = FormBuilder::element($type, $options, $attr); $element->builder = $this; return $element; }