root/trunk/classes/phing/TaskAdapter.php

Revision 307, 2.8 kB (checked in by hans, 1 year ago)

Refs #188 - Adding work-in-progress (still-broken!) namespace support.

  • Property svn:keywords set to author date id revision
Line 
1 <?php
2 /*
3  *  $Id$
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 namespace phing;
23
24
25 /**
26  *  Use introspection to "adapt" an arbitrary ( not extending Task, but with
27  *  similar patterns).
28  *
29  *  @author    Andreas Aderhold <andi@binarycloud.com>
30  *  @copyright © 2001,2002 THYRELL. All rights reserved
31  *  @version   $Revision: 1.7 $
32  *  @package   phing
33  */
34 class TaskAdapter extends Task {
35     
36     /** target object */
37     private $proxy;
38     
39     /**
40      * Main entry point.
41      * @return void
42      */
43     function main() {
44     
45         if (method_exists($this->proxy, "setProject")) {
46             try {  // try to set project
47                 $this->proxy->setProject($this->project);
48             } catch (Exception $ex) {
49                 $this->log("Error setting project in " . get_class($this->proxy) . Project::MSG_ERR);
50                 throw new BuildException($ex);
51             }
52         } else {
53             throw new Exception("Error setting project in class " . get_class($this->proxy));
54         }
55               
56         if (method_exists($this->proxy, "main")) {
57             try { //try to call main
58                 $this->proxy->main($this->project);
59             } catch (Exception $ex) {
60                 $this->log("Error in " . get_class($this->proxy), Project::MSG_ERR);
61                 throw new BuildException($ex->getMessage());
62             }
63         } else {
64             throw new BuildException("Your task-like class '" . get_class($this->proxy) ."' does not have a main() method");
65         }
66     }
67
68     /**
69      * Set the target object.
70      * @param object $o
71      * @return void
72      */
73     function setProxy($o) {
74         $this->proxy = $o;
75     }
76
77     /**
78      * Gets the target object.
79      * @return object
80      */
81     function getProxy() {
82         return $this->proxy;
83     }
84
85 }
86
Note: See TracBrowser for help on using the browser.