123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216 |
- <?php
- require_once 'phing/Task.php';
- class UnknownElement extends Task {
- private $elementName;
- private $realThing;
- private $children = array();
-
- function __construct($elementName) {
- $this->elementName = (string) $elementName;
- }
-
- public function getTag() {
- return (string) $this->elementName;
- }
-
- public function maybeConfigure() {
-
- $this->realThing = $this->makeObject($this, $this->wrapper);
- $this->wrapper->setProxy($this->realThing);
- if ($this->realThing instanceof Task) {
- $this->realThing->setRuntimeConfigurableWrapper($this->wrapper);
- }
-
- $this->handleChildren($this->realThing, $this->wrapper);
- $this->wrapper->maybeConfigure($this->getProject());
-
- }
-
- public function main() {
-
- if ($this->realThing === null) {
-
-
- throw new BuildException("Should not be executing UnknownElement::main() -- task/type: {$this->elementName}");
- }
-
- if ($this->realThing instanceof Task) {
- $this->realThing->main();
- }
-
- }
-
- public function addChild(UnknownElement $child) {
- $this->children[] = $child;
- }
-
- function handleChildren(ProjectComponent $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) {
- $realChild = $this->makeTask($child, $childWrapper, false);
- $parent->addTask($realChild);
- } else {
- $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);
- }
-
- if ($realChild instanceof ProjectComponent) {
- $child->handleChildren($realChild, $childWrapper);
- }
-
- if ($realChild instanceof Task) {
- $realChild->maybeConfigure();
- }
- }
- }
-
- protected function makeObject(UnknownElement $ue, RuntimeConfigurable $w) {
- $o = $this->makeTask($ue, $w, true);
- if ($o === null) {
- $o = $this->project->createDataType($ue->getTag());
- }
- if ($o === null) {
- throw new BuildException("Could not create task/type: '".$ue->getTag()."'. Make sure that this class has been declared using taskdef / typedef.");
- }
- return $o;
- }
-
-
- protected function makeTask(UnknownElement $ue, RuntimeConfigurable $w, $onTopLevel = false) {
- $task = $this->project->createTask($ue->getTag());
- if ($task === null) {
- if (!$onTopLevel) {
- throw new BuildException("Could not create task of type: '".$this->elementName."'. Make sure that this class has been declared using taskdef.");
- }
- return null;
- }
-
-
- $task->setLocation($this->getLocation());
- $attrs = $w->getAttributes();
- if (isset($attrs['id'])) {
- $this->project->addReference($attrs['id'], $task);
- }
-
- $task->setOwningTarget($this->target);
- $task->init();
- return $task;
- }
-
- function getTaskName() {
- return $this->realThing === null ? parent::getTaskName() : $this->realThing->getTaskName();
- }
- }
|