/** * Gets the correct phElementFactory instance for creating * the right phElement for $e * @param SimpleXMLElement $e * @return phElementFactory */ public static function getFactory(SimpleXMLElement $e) { if (self::$_factories === null) { self::$_factories = self::loadFactories(); } foreach (self::$_factories as $f) { if ($f->canHandle($e)) { return $f; } } }
/** * Parses the view and sets up the data items and elements that appear there * * @throws phFormException */ protected function initialize() { if ($this->_initialized) { return; } /* * before initialising call the forms * preInitialize method so it can setup * any custom vars for the view */ $this->_form->preInitialize(); $dom = $this->parseDom($this->_template); $this->_dataCollection = new phCompositeDataCollection(); foreach ($this->_names as $rewrittenName => $name) { $nameInfo = new phNameInfo($name); $elements = $dom->xpath("//*[@name='{$rewrittenName}']"); if (!sizeof($elements)) { throw new phFormException("No elements found with the name of '{$name}'"); } $phElements = array(); foreach ($elements as $element) { if (!strlen((string) $element->attributes()->id)) { throw new phFormException("You must specify an id for the element with name '{$nameInfo->getName()}'"); } $f = phElementFactory::getFactory($element); if ($f === null) { $realId = $this->getRealId((string) $element->attributes()->id); throw new phFormException("no factory exists for handling the element with ID '{$realId}' which is of the type '{$element->getName()}'"); } $phElement = $f->createPhElement($element, $this); $this->_elements[$this->getRealId((string) $element->attributes()->id)] = $phElement; $this->_dataCollection->register($phElement, $nameInfo); } } $this->_dom = $dom; $this->_initialized = true; /* * now we are initialised call the forms postInitialize method so it * can do any setup like adding validators */ $this->_form->postInitialize(); }