[ Index ]
 

Code source de Symfony 1.0.0

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/lib/vendor/phing/parser/ -> TaskHandler.php (source)

   1  <?php
   2  /*
   3   *  $Id: TaskHandler.php 3076 2006-12-18 08:52:12Z fabien $
   4   *
   5   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
   6   * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
   7   * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
   8   * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
   9   * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  10   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  11   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  12   * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  13   * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  14   * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  15   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  16   *
  17   * This software consists of voluntary contributions made by many individuals
  18   * and is licensed under the LGPL. For more information please see
  19   * <http://phing.info>.
  20   */
  21  
  22  include_once 'phing/UnknownElement.php';
  23  
  24  /**
  25   * The task handler class.
  26   *
  27   * This class handles the occurance of a <task> tag and it's possible
  28   * nested tags (datatypes and tasks) that may be unknown off bat and are
  29   * initialized on the fly.
  30   *
  31   * @author      Andreas Aderhold <andi@binarycloud.com>
  32   * @copyright © 2001,2002 THYRELL. All rights reserved
  33   * @version   $Revision: 1.10 $
  34   * @package   phing.parser
  35   */
  36  class TaskHandler extends AbstractHandler {
  37  
  38      /**
  39       * Reference to the target object that contains the currently parsed
  40       * task
  41       * @var object the target instance
  42       */
  43      private $target;
  44  
  45      /**
  46       * Reference to the target object that represents the currently parsed
  47       * target. This must not necessarily be a target, hence extra variable.
  48       * @var object the target instance
  49       */
  50      private $container;
  51  
  52      /**
  53       * Reference to the task object that represents the currently parsed
  54       * target.
  55       * @var Task
  56       */
  57      private $task;
  58      
  59      /**
  60        * Wrapper for the parent element, if any. The wrapper for this
  61       * element will be added to this wrapper as a child.
  62       * @var RuntimeConfigurable
  63       */
  64      private $parentWrapper;
  65      
  66      /**
  67       * Wrapper for this element which takes care of actually configuring
  68       * the element, if this element is contained within a target.
  69       * Otherwise the configuration is performed with the configure method.
  70       * @see ProjectHelper::configure(Object,AttributeList,Project)
  71       */
  72      private $wrapper;
  73  
  74      /**
  75       * The phing project configurator object
  76       * @var ProjectConfigurator
  77       */
  78      private $configurator;
  79  
  80      /**
  81       * Constructs a new TaskHandler and sets up everything.
  82       *
  83       * @param AbstractSAXParser The ExpatParser object
  84       * @param object $parentHandler The parent handler that invoked this handler
  85       * @param ProjectConfigurator $configurator
  86       * @param TaskContainer $container The container object this task is contained in (null for top-level tasks).
  87       * @param RuntimeConfigurable $parentWrapper  Wrapper for the parent element, if any.
  88       * @param Target $target The target object this task is contained in (null for top-level tasks).
  89       */
  90      function __construct(AbstractSAXParser $parser, $parentHandler, ProjectConfigurator $configurator, $container = null, $parentWrapper = null, $target = null) {
  91          
  92          parent::__construct($parser, $parentHandler);
  93      
  94          if (($container !== null) && !($container instanceof TaskContainer)) {
  95              throw new Exception("Argument expected to be a TaskContainer, got something else");
  96          }
  97          if (($parentWrapper !== null) && !($parentWrapper instanceof RuntimeConfigurable)) {
  98              throw new Exception("Argument expected to be a RuntimeConfigurable, got something else.");
  99          }
 100          if (($target !== null) && !($target instanceof Target)) {
 101              throw new Exception("Argument expected to be a Target, got something else");
 102          }
 103  
 104          $this->configurator = $configurator;
 105          $this->container = $container;
 106          $this->parentWrapper = $parentWrapper;
 107          $this->target = $target;
 108      }
 109  
 110      /**
 111       * Executes initialization actions required to setup the data structures
 112       * related to the tag.
 113       * <p>
 114       * This includes:
 115       * <ul>
 116       * <li>creation of the task object</li>
 117       * <li>calling the setters for attributes</li>
 118       * <li>adding the task to the container object</li>
 119       * <li>adding a reference to the task (if id attribute is given)</li>
 120       * <li>executing the task if the container is the &lt;project&gt;
 121       * element</li>
 122       * </ul>
 123       *
 124       * @param string $tag The tag that comes in
 125       * @param array $attrs Attributes the tag carries
 126       * @throws ExpatParseException if attributes are incomplete or invalid
 127       */
 128      function init($tag, $attrs) {
 129          // shorthands
 130          try {
 131              $configurator = $this->configurator;
 132              $project = $this->configurator->project;
 133              
 134              $this->task = $project->createTask($tag);
 135          } catch (BuildException $be) {
 136              // swallow here, will be thrown again in
 137              // UnknownElement->maybeConfigure if the problem persists.
 138              print("Swallowing exception: ".$be->getMessage() . "\n");
 139          }
 140  
 141          // the task is not known of bat, try to load it on thy fly
 142          if ($this->task === null) {
 143              $this->task = new UnknownElement($tag);
 144              $this->task->setProject($project);
 145              $this->task->setTaskType($tag);
 146              $this->task->setTaskName($tag);
 147          }
 148  
 149          // add file position information to the task (from parser)
 150          // should be used in task exceptions to provide details
 151          $this->task->setLocation($this->parser->getLocation());
 152          $configurator->configureId($task, $attrs);
 153          
 154          if ($this->container) {
 155              $this->container->addTask($this->task);
 156          }
 157          
 158          // Top level tasks don't have associated targets
 159          // FIXME: if we do like Ant 1.6 and create an implicitTarget in the projectconfigurator object
 160          // then we don't need to check for null here ... but there's a lot of stuff that will break if we
 161          // do that at this point.
 162          if ($this->target !== null) {
 163              $this->task->setOwningTarget($this->target);
 164              $this->task->init();
 165              $this->wrapper = $this->task->getRuntimeConfigurableWrapper();
 166              $this->wrapper->setAttributes($attrs);
 167              /*
 168              Commenting this out as per thread on Premature configurate of ReuntimeConfigurables 
 169              with Matthias Pigulla: http://phing.tigris.org/servlets/ReadMsg?list=dev&msgNo=251
 170              
 171              if ($this->parentWrapper !== null) { // this may not make sense only within this if-block, but it
 172                                                  // seems to address current use cases adequately
 173                  $this->parentWrapper->addChild($this->wrapper);
 174              }
 175              */
 176          } else {
 177              $this->task->init();
 178              $configurator->configure($this->task, $attrs, $project);
 179          }
 180      }
 181  
 182      /**
 183       * Executes the task at once if it's directly beneath the <project> tag.
 184       */
 185      protected function finished() {
 186          if ($this->task !== null && $this->target === null && $this->container === null) {
 187              try {
 188                  $this->task->main();
 189              } catch (Exception $e) {
 190                  $this->task->log($e->getMessage(), PROJECT_MSG_ERR);
 191                  throw $e;
 192              }
 193          }
 194      }
 195  
 196      /**
 197       * Handles character data.
 198       *
 199       * @param string $data The CDATA that comes in
 200       */
 201      function characters($data) {
 202          if ($this->wrapper === null) {
 203              $configurator = $this->configurator;
 204              $project = $this->configurator->project;
 205              try { // try
 206                  $configurator->addText($project, $this->task, $data);
 207              } catch (BuildException $exc) {
 208                  throw new ExpatParseException($exc->getMessage(), $this->parser->getLocation());
 209              }
 210          } else {
 211              $this->wrapper->addText($data);
 212          }
 213      }
 214  
 215      /**
 216       * Checks for nested tags within the current one. Creates and calls
 217       * handlers respectively.
 218       *
 219       * @param string $name The tag that comes in
 220       * @param array $attrs Attributes the tag carries
 221       */
 222      function startElement($name, $attrs) {
 223          $project = $this->configurator->project;
 224          if ($this->task instanceof TaskContainer) {
 225              //print("TaskHandler::startElement() (TaskContainer) name = $name, attrs = " . implode(",",$attrs) . "\n");
 226              $th = new TaskHandler($this->parser, $this, $this->configurator, $this->task, $this->wrapper, $this->target);
 227              $th->init($name, $attrs);
 228          } else {
 229              //print("TaskHandler::startElement() name = $name, attrs = " . implode(",",$attrs) . "\n");
 230              $tmp = new NestedElementHandler($this->parser, $this, $this->configurator, $this->task, $this->wrapper, $this->target);
 231              $tmp->init($name, $attrs);
 232          }
 233      }
 234  }


Généré le : Fri Mar 16 22:42:14 2007 par Balluche grâce à PHPXref 0.7