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 / tasks / system / TaskdefTask.php < prev    next >
Encoding:
PHP Script  |  2007-02-05  |  4.1 KB  |  128 lines

  1. <?php
  2.  
  3. /*
  4.  * $Id: TaskdefTask.php 144 2007-02-05 15:19:00Z hans $
  5.  *
  6.  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  7.  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  8.  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  9.  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  10.  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  11.  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  12.  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  13.  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  14.  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  15.  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  16.  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  17.  *
  18.  * This software consists of voluntary contributions made by many individuals
  19.  * and is licensed under the LGPL. For more information please see
  20.  * <http://phing.info>.
  21.  */
  22.  
  23. require_once 'phing/Task.php';
  24.  
  25. /**
  26.  * Register a task for use within a buildfile.
  27.  * 
  28.  * This is for registering your own tasks -- or any non-core Task -- for use within a buildfile.
  29.  * If you find that you are using a particular class frequently, you may want to edit the 
  30.  * phing/tasks/defaults.properties file so that it is included by default. You may also
  31.  * want to submit it (if LGPL or compatible license) to be included in Phing distribution.
  32.  * 
  33.  * <pre>
  34.  *   <taskdef name="mytag" classname="path.to.MyHandlingClass"/>
  35.  *   .
  36.  *   .
  37.  *   <mytag param1="val1" param2="val2"/>
  38.  * </pre>
  39.  * 
  40.  * TODO:
  41.  *    -- possibly refactor since this is almost the same as TypeDefTask
  42.  *      (right now these are just too simple to really justify creating an abstract class)
  43.  * 
  44.  * @author    Hans Lellelid <hans@xmpl.org>
  45.  * @version   $Revision: 1.11 $
  46.  * @package   phing.tasks.system
  47.  */
  48. class TaskdefTask extends Task {
  49.  
  50.     /** Tag name for task that will be used in XML */
  51.     private $name;
  52.     
  53.     /**
  54.      * Classname of task to register.
  55.      * This can be a dot-path -- relative to a location on PHP include_path.
  56.      * E.g. path.to.MyClass ->  path/to/MyClass.php
  57.      * @var string
  58.      */
  59.     private $classname;
  60.     
  61.     /**
  62.      * Path to add to PHP include_path to aid in finding specified class.
  63.      * @var Path
  64.      */
  65.     private $classpath;
  66.     
  67.     /**
  68.      * Refid to already defined classpath
  69.      */
  70.     private $classpathId;
  71.     
  72.     /**
  73.      * Set the classpath to be used when searching for component being defined
  74.      * 
  75.      * @param Path $classpath An Path object containing the classpath.
  76.      */
  77.     public function setClasspath(Path $classpath) {
  78.         if ($this->classpath === null) {
  79.             $this->classpath = $classpath;
  80.         } else {
  81.             $this->classpath->append($classpath);
  82.         }
  83.     }
  84.  
  85.     /**
  86.      * Create the classpath to be used when searching for component being defined
  87.      */ 
  88.     public function createClasspath() {
  89.         if ($this->classpath === null) {
  90.             $this->classpath = new Path($this->project);
  91.         }
  92.         return $this->classpath->createPath();
  93.     }
  94.  
  95.     /**
  96.      * Reference to a classpath to use when loading the files.
  97.      */
  98.     public function setClasspathRef(Reference $r) {
  99.         $this->classpathId = $r->getRefId();
  100.         $this->createClasspath()->setRefid($r);
  101.     }
  102.  
  103.     /**
  104.      * Sets the name that will be used in XML buildfile.
  105.      * @param string $name
  106.      */
  107.     public function setName($name)    {
  108.         $this->name = $name;
  109.     }
  110.     
  111.     /**
  112.      * Sets the class name / dotpath to use.
  113.      * @param string $class
  114.      */
  115.     public function setClassname($class) {
  116.         $this->classname = $class;
  117.     }
  118.     
  119.     /** Main entry point */
  120.     public function main() {
  121.         if ($this->name === null || $this->classname === null) {
  122.             throw new BuildException("You must specify name and class attributes for <taskdef>.");
  123.         }
  124.         $this->log("Task " . $this->name . " will be handled by class " . $this->classname, Project::MSG_VERBOSE);
  125.         $this->project->addTaskDefinition($this->name, $this->classname, $this->classpath);
  126.     }
  127. }
  128.