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 / AdhocTaskdefTask.php < prev    next >
Encoding:
PHP Script  |  2007-02-05  |  3.0 KB  |  91 lines

  1. <?php
  2.  
  3. /*
  4.  * $Id: AdhocTaskdefTask.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/tasks/system/AdhocTask.php';
  24.  
  25. /**
  26.  * A class for creating adhoc tasks in build file.
  27.  * 
  28.  * <target name="test-adhoc">
  29.  *        <adhoc-task name="foo"><![CDATA[
  30.  *
  31.  *            class FooTest extends Task {
  32.  *                private $bar;
  33.  *                
  34.  *                function setBar($bar) {
  35.  *                    $this->bar = $bar;
  36.  *                }
  37.  *                
  38.  *                function main() {
  39.  *                    $this->log("In FooTest: " . $this->bar);
  40.  *                }
  41.  *            }
  42.  *
  43.  *        ]]></adhoc-task>
  44.  * 
  45.  *      <foo bar="B.L.I.N.G"/>
  46.  * </target>
  47.  *  
  48.  * @author    Hans Lellelid <hans@xmpl.org>
  49.  * @version   $Revision: 1.5 $
  50.  * @package   phing.tasks.system
  51.  */
  52. class AdhocTaskdefTask extends AdhocTask {
  53.  
  54.     /**
  55.      * The tag that refers to this task.
  56.      */
  57.     private $name;
  58.     
  59.     /**
  60.      * Set the tag that will represent this adhoc task/type.
  61.      * @param string $name
  62.      */       
  63.     public function setName($name) {
  64.         $this->name = $name;
  65.     }
  66.     
  67.     /** Main entry point */
  68.     public function main() {        
  69.         if ($this->name === null) {
  70.             throw new BuildException("The name attribute is required for adhoc task definition.",$this->location);
  71.         }
  72.         
  73.         $this->execute();
  74.         
  75.         $classes = $this->getNewClasses();
  76.         if (count($classes) !== 1) {
  77.             throw new BuildException("You must define one (and only one) class for AdhocTaskdefTask.");
  78.         }
  79.         $classname = array_shift($classes);
  80.         
  81.         // instantiate it to make sure it is an instance of Task
  82.         $t = new $classname();
  83.         if (!($t instanceof Task)) {
  84.             throw new BuildException("The adhoc class you defined must be an instance of phing.Task", $this->location);
  85.         }
  86.         
  87.         $this->log("Task " . $this->name . " will be handled by class " . $classname, Project::MSG_VERBOSE);
  88.         $this->project->addTaskDefinition($this->name, $classname);        
  89.     }
  90. }
  91.