public function testElementCreators() { try { $ihtmp = IntrospectionHelper::getHelper('IHCreatorFail1'); $this->fail("create cannot take param"); } catch (BuildException $be) { } try { $ihtmp = IntrospectionHelper::getHelper('IHCreatorFail2'); $this->fail("no class hint for add"); } catch (BuildException $be) { } try { $ihtmp = IntrospectionHelper::getHelper('IHCreatorFail3'); $this->fail("no class hint for addconfigured"); } catch (BuildException $be) { } $ih = IntrospectionHelper::getHelper('IHProjectComponent'); $this->assertEquals("test", $ih->createElement($this->p, new IHProjectComponent(), "one")); }
/** * Executes initialization actions required to setup the data structures * related to the tag. * <p> * This includes: * <ul> * <li>creation of the nested element</li> * <li>calling the setters for attributes</li> * <li>adding the element to the container object</li> * <li>adding a reference to the element (if id attribute is given)</li> * </ul> * * @param string the tag that comes in * @param array attributes the tag carries * @throws ExpatParseException if the setup process fails * @access public */ function init($propType, $attrs) { $configurator = $this->configurator; $project = $this->configurator->project; // introspect the parent class that is custom $parentClass = get_class($this->parent); $ih = IntrospectionHelper::getHelper($parentClass); try { if ($this->parent instanceof UnknownElement) { $this->child = new UnknownElement(strtolower($propType)); $this->parent->addChild($this->child); } else { $this->child = $ih->createElement($project, $this->parent, strtolower($propType)); } $configurator->configureId($this->child, $attrs); if ($this->parentWrapper !== null) { $this->childWrapper = new RuntimeConfigurable($this->child, $propType); $this->childWrapper->setAttributes($attrs); $this->parentWrapper->addChild($this->childWrapper); } else { $configurator->configure($this->child, $attrs, $project); $ih->storeElement($project, $this->parent, $this->child, strtolower($propType)); } } catch (BuildException $exc) { throw new ExpatParseException("Error initializing nested element <{$propType}>", $exc, $this->parser->getLocation()); } }
/** * Stores a configured child element into its parent object * * @param object the project this element belongs to * @param object the parent element * @param object the child element * @param string the XML tagname * @access public */ public static function storeChild($project, $parent, $child, $tag) { $ih = IntrospectionHelper::getHelper(get_class($parent)); $ih->storeElement($project, $parent, $child, $tag); }
/** * Handle child elemets of the unknown element, if any. * * @param object $parent The parent object the unkown element belongs to * @param object $parentWrapper The parent wrapper object */ public function handleChildren($parent, $parentWrapper) { if ($parent instanceof TaskAdapter) { $parent = $parent->getProxy(); } $parentClass = get_class($parent); $ih = IntrospectionHelper::getHelper($parentClass); for ($i = 0, $childrenCount = count($this->children); $i < $childrenCount; $i++) { $childWrapper = $parentWrapper->getChild($i); $child = $this->children[$i]; $realChild = null; if ($parent instanceof TaskContainer) { $parent->addTask($child); continue; } $project = $this->project === null ? $parent->project : $this->project; $realChild = $ih->createElement($project, $parent, $child->getTag()); $childWrapper->setProxy($realChild); if ($realChild instanceof Task) { $realChild->setRuntimeConfigurableWrapper($childWrapper); } $childWrapper->maybeConfigure($this->project); $child->handleChildren($realChild, $childWrapper); } }