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 / AdhocTask.php next >
Encoding:
PHP Script  |  2007-02-05  |  2.8 KB  |  89 lines

  1. <?php
  2. /*
  3.  *  $Id: AdhocTask.php 144 2007-02-05 15:19:00Z hans $
  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/Task.php';
  23.  
  24. /**
  25.  * Abstract class for creating adhoc Phing components in buildfile.
  26.  *
  27.  * By itself this class can be used to declare a single class within your buildfile.
  28.  * You can then reference this class in any task that takes custom classes (selectors,
  29.  * mappers, filters, etc.)
  30.  * 
  31.  * Subclasses exist for conveniently declaring and registering tasks and types.
  32.  * 
  33.  * @author   Hans Lellelid <hans@xmpl.org>
  34.  * @version  $Revision: 1.6 $
  35.  * @package  phing.tasks.system
  36.  */
  37. class AdhocTask extends Task {
  38.             
  39.     /**
  40.      * The PHP script
  41.      * @var string
  42.      */
  43.     protected $script;
  44.     
  45.     protected $newClasses = array();
  46.     
  47.     /**
  48.      * Main entry point
  49.      */
  50.     public function main() {    
  51.         $this->execute();        
  52.         if ($this->newClasses) {
  53.             foreach($this->newClasses as $classname) {
  54.                 $this->log("Added adhoc class " . $classname, Project::MSG_VERBOSE);
  55.             }
  56.         } else {
  57.             $this->log("Adhoc task executed but did not result in any new classes.", Project::MSG_VERBOSE);
  58.         }
  59.     }
  60.     
  61.     /**
  62.      * Get array of names of newly defined classes.
  63.      * @return array
  64.      */
  65.     protected function getNewClasses() {
  66.         return $this->newClasses;
  67.     }
  68.     
  69.     /**
  70.      * Load the adhoc class, and perform any core validation.
  71.      * @return string The classname of the ProjectComponent class.
  72.      * @throws BuildException - if more than one class is defined.
  73.      */
  74.     protected function execute() {
  75.         $classes = get_declared_classes();        
  76.         eval($this->script);        
  77.         $this->newClasses = array_diff(get_declared_classes(), $classes);        
  78.     }
  79.             
  80.     /**
  81.      * Set the script.
  82.      * @param string $script
  83.      */
  84.     public function addText($script) {
  85.         $this->script = $script;
  86.     }
  87.            
  88. }
  89.