123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235 |
- <?php
- include_once 'phing/UnknownElement.php';
- class TaskHandler extends AbstractHandler {
-
- private $target;
-
- private $container;
-
- private $task;
-
-
- private $parentWrapper;
-
-
- private $wrapper;
-
- private $configurator;
-
- function __construct(AbstractSAXParser $parser, $parentHandler, ProjectConfigurator $configurator, $container = null, $parentWrapper = null, $target = null) {
-
- parent::__construct($parser, $parentHandler);
-
- if (($container !== null) && !($container instanceof TaskContainer)) {
- throw new Exception("Argument expected to be a TaskContainer, got something else");
- }
- if (($parentWrapper !== null) && !($parentWrapper instanceof RuntimeConfigurable)) {
- throw new Exception("Argument expected to be a RuntimeConfigurable, got something else.");
- }
- if (($target !== null) && !($target instanceof Target)) {
- throw new Exception("Argument expected to be a Target, got something else");
- }
- $this->configurator = $configurator;
- $this->container = $container;
- $this->parentWrapper = $parentWrapper;
- $this->target = $target;
- }
-
- function init($tag, $attrs) {
-
- try {
- $configurator = $this->configurator;
- $project = $this->configurator->project;
-
- $this->task = $project->createTask($tag);
- } catch (BuildException $be) {
-
-
- print("Swallowing exception: ".$be->getMessage() . "\n");
- }
-
- if ($this->task === null) {
- $this->task = new UnknownElement($tag);
- $this->task->setProject($project);
- $this->task->setTaskType($tag);
- $this->task->setTaskName($tag);
- }
-
-
- $this->task->setLocation($this->parser->getLocation());
- $configurator->configureId($this->task, $attrs);
-
- if ($this->container) {
- $this->container->addTask($this->task);
- }
-
-
-
-
-
- if ($this->target !== null) {
- $this->task->setOwningTarget($this->target);
- $this->task->init();
- $this->wrapper = $this->task->getRuntimeConfigurableWrapper();
- $this->wrapper->setAttributes($attrs);
-
- } else {
- $this->task->init();
- $configurator->configure($this->task, $attrs, $project);
- }
- }
-
- protected function finished() {
- if ($this->task !== null && $this->target === null && $this->container === null) {
- try {
- $this->task->perform();
- } catch (Exception $e) {
- $this->task->log($e->getMessage(), Project::MSG_ERR);
- throw $e;
- }
- }
- }
-
- function characters($data) {
- if ($this->wrapper === null) {
- $configurator = $this->configurator;
- $project = $this->configurator->project;
- try {
- $configurator->addText($project, $this->task, $data);
- } catch (BuildException $exc) {
- throw new ExpatParseException($exc->getMessage(), $this->parser->getLocation());
- }
- } else {
- $this->wrapper->addText($data);
- }
- }
-
- function startElement($name, $attrs) {
- $project = $this->configurator->project;
- if ($this->task instanceof TaskContainer) {
-
- $th = new TaskHandler($this->parser, $this, $this->configurator, $this->task, $this->wrapper, $this->target);
- $th->init($name, $attrs);
- } else {
-
- $tmp = new NestedElementHandler($this->parser, $this, $this->configurator, $this->task, $this->wrapper, $this->target);
- $tmp->init($name, $attrs);
- }
- }
- }
|