home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Servidores / xampp-win32-1.6.7-installer.exe / php / PEAR / phing / parser / ProjectHandler.php < prev    next >
Encoding:
PHP Script  |  2007-01-25  |  5.3 KB  |  154 lines

  1. <?php
  2. /*
  3.  * $Id: ProjectHandler.php 132 2007-01-25 19:38:05Z mrook $
  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. require_once 'phing/parser/AbstractHandler.php';
  23. require_once 'phing/system/io/PhingFile.php';
  24.  
  25. /**
  26.  * Handler class for the <project> XML element This class handles all elements
  27.  * under the <project> element.
  28.  *
  29.  * @author      Andreas Aderhold <andi@binarycloud.com>
  30.  * @copyright (c) 2001,2002 THYRELL. All rights reserved
  31.  * @version   $Revision: 1.14 $ $Date: 2007-01-25 20:38:05 +0100 (Thu, 25 Jan 2007) $
  32.  * @access    public
  33.  * @package   phing.parser
  34.  */
  35. class ProjectHandler extends AbstractHandler {
  36.  
  37.     /**
  38.      * The phing project configurator object.
  39.      * @var ProjectConfigurator
  40.      */
  41.     private $configurator;
  42.  
  43.     /**
  44.      * Constructs a new ProjectHandler
  45.      *
  46.      * @param  object  the ExpatParser object
  47.      * @param  object  the parent handler that invoked this handler
  48.      * @param  object  the ProjectConfigurator object
  49.      * @access public
  50.      */
  51.     function __construct($parser, $parentHandler, $configurator) {
  52.         $this->configurator = $configurator;
  53.         parent::__construct($parser, $parentHandler);
  54.     }
  55.  
  56.     /**
  57.      * Executes initialization actions required to setup the project. Usually
  58.      * this method handles the attributes of a tag.
  59.      *
  60.      * @param  string  the tag that comes in
  61.      * @param  array   attributes the tag carries
  62.      * @param  object  the ProjectConfigurator object
  63.      * @throws ExpatParseException if attributes are incomplete or invalid
  64.      * @access public
  65.      */
  66.     function init($tag, $attrs) {
  67.         $def = null;
  68.         $name = null;
  69.         $id    = null;
  70.         $desc = null;
  71.         $baseDir = null;
  72.  
  73.         // some shorthands
  74.         $project = $this->configurator->project;
  75.         $buildFileParent = $this->configurator->buildFileParent;
  76.  
  77.         foreach ($attrs as $key => $value) {
  78.             if ($key === "default") {
  79.                 $def = $value;
  80.             } elseif ($key === "name") {
  81.                 $name = $value;
  82.             } elseif ($key === "id") {
  83.                 $id = $value;
  84.             } elseif ($key === "basedir") {
  85.                 $baseDir = $value;
  86.             } elseif ($key === "description") {
  87.                 $desc = $value;
  88.             } else {
  89.                 throw new ExpatParseException("Unexpected attribute '$key'");
  90.             }
  91.         }
  92.         if ($def === null) {
  93.             throw new ExpatParseException("The default attribute of project is required");
  94.         }
  95.         $project->setDefaultTarget($def);
  96.  
  97.         if ($name !== null) {
  98.             $project->setName($name);
  99.             $project->addReference($name, $project);
  100.         }
  101.  
  102.         if ($id !== null) {
  103.             $project->addReference($id, $project);
  104.         }
  105.         
  106.         if ($desc !== null) {
  107.             $project->setDescription($desc);
  108.         }        
  109.  
  110.         if ($project->getProperty("project.basedir") !== null) {
  111.             $project->setBasedir($project->getProperty("project.basedir"));
  112.         } else {
  113.             if ($baseDir === null) {
  114.                 $project->setBasedir($buildFileParent->getAbsolutePath());
  115.             } else {
  116.                 // check whether the user has specified an absolute path
  117.                 $f = new PhingFile($baseDir);
  118.                 if ($f->isAbsolute()) {
  119.                     $project->setBasedir($baseDir);
  120.                 } else {
  121.                     $project->setBaseDir($project->resolveFile($baseDir, $buildFileParent));
  122.                 }
  123.             }
  124.         }
  125.     }
  126.  
  127.     /**
  128.      * Handles start elements within the <project> tag by creating and
  129.      * calling the required handlers for the detected element.
  130.      *
  131.      * @param  string  the tag that comes in
  132.      * @param  array   attributes the tag carries
  133.      * @throws ExpatParseException if a unxepected element occurs
  134.      * @access public
  135.      */
  136.     function startElement($name, $attrs) {
  137.     
  138.         $project = $this->configurator->project;
  139.         $types = $project->getDataTypeDefinitions();
  140.         
  141.         if ($name == "target") {
  142.             $tf = new TargetHandler($this->parser, $this, $this->configurator);
  143.             $tf->init($name, $attrs);
  144.         } elseif (isset($types[$name])) {
  145.            $tyf = new DataTypeHandler($this->parser, $this, $this->configurator);
  146.            $tyf->init($name, $attrs);
  147.         } else {
  148.             $tf = new TaskHandler($this->parser, $this, $this->configurator);
  149.             $tf->init($name, $attrs);
  150.         }
  151.     }
  152. }
  153.  
  154.