. */ require_once 'phing/parser/AbstractHandler.php'; /** * The target handler class. * * This class handles the occurance of a tag and it's possible * nested tags (datatypes and tasks). * * @author Andreas Aderhold * @copyright 2001,2002 THYRELL. All rights reserved * @version $Revision: 1.10 $ * @package phing.parser */ class TargetHandler extends AbstractHandler { /** * Reference to the target object that represents the currently parsed * target. * @var object the target instance */ private $target; /** * The phing project configurator object * @var ProjectConfigurator */ private $configurator; /** * Constructs a new TargetHandler * * @param object the ExpatParser object * @param object the parent handler that invoked this handler * @param object the ProjectConfigurator object */ function __construct(AbstractSAXParser $parser, AbstractHandler $parentHandler, ProjectConfigurator $configurator) { parent::__construct($parser, $parentHandler); $this->configurator = $configurator; } /** * Executes initialization actions required to setup the data structures * related to the tag. *

* This includes: *

* * @param string the tag that comes in * @param array attributes the tag carries * @throws ExpatParseException if attributes are incomplete or invalid */ function init($tag, $attrs) { $name = null; $depends = ""; $ifCond = null; $unlessCond = null; $id = null; $description = null; foreach($attrs as $key => $value) { if ($key==="name") { $name = (string) $value; } else if ($key==="depends") { $depends = (string) $value; } else if ($key==="if") { $ifCond = (string) $value; } else if ($key==="unless") { $unlessCond = (string) $value; } else if ($key==="id") { $id = (string) $value; } else if ($key==="description") { $description = (string)$value; } else { throw new ExpatParseException("Unexpected attribute '$key'", $this->parser->getLocation()); } } if ($name === null) { throw new ExpatParseException("target element appears without a name attribute", $this->parser->getLocation()); } // shorthand $project = $this->configurator->project; $this->target = new Target(); $this->target->setName($name); $this->target->setIf($ifCond); $this->target->setUnless($unlessCond); $this->target->setDescription($description); $project->addTarget($name, $this->target); if ($id !== null && $id !== "") { $project->addReference($id, $this->target); } // take care of dependencies if (strlen($depends) > 0) { $this->target->setDepends($depends); } } /** * Checks for nested tags within the current one. Creates and calls * handlers respectively. * * @param string the tag that comes in * @param array attributes the tag carries */ function startElement($name, $attrs) { // shorthands $project = $this->configurator->project; $types = $project->getDataTypeDefinitions(); if (isset($types[$name])) { $th = new DataTypeHandler($this->parser, $this, $this->configurator, $this->target); $th->init($name, $attrs); } else { $tmp = new TaskHandler($this->parser, $this, $this->configurator, $this->target, null, $this->target); $tmp->init($name, $attrs); } } }