root/trunk/classes/phing/RuntimeConfigurable.php

Revision 307, 3.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 use phing::parser::ProjectConfigurator;
24
25 /**
26  *  Wrapper class that holds the attributes of a Task (or elements
27  *  nested below that level) and takes care of configuring that element
28  *  at runtime.
29  *
30  *  <strong>SMART-UP INLINE DOCS</strong>
31  *
32  * @author    Andreas Aderhold <andi@binarycloud.com>
33  * @author    Hans Lellelid <hans@xmpl.org>
34  * @version   $Revision: 1.6 $
35  * @package   phing
36  */
37 class RuntimeConfigurable {
38
39     private $elementTag = null;
40     private $children = array();
41     private $wrappedObject = null;
42     private $attributes = array();
43     private $characters = "";
44
45
46     /** @param proxy The element to wrap. */
47     function __construct($proxy, $elementTag) {
48         $this->wrappedObject = $proxy;
49         $this->elementTag = $elementTag;
50     }
51
52     function setProxy($proxy) {
53         $this->wrappedObject = $proxy;
54     }
55
56     /** Set's the attributes for the wrapped element. */
57     function setAttributes($attributes) {
58         $this->attributes = $attributes;
59     }
60
61     /** Returns the AttributeList of the wrapped element. */
62     function getAttributes() {
63         return $this->attributes;
64     }
65
66     /** Adds child elements to the wrapped element. */
67     function addChild(RuntimeConfigurable $child) {
68         $this->children[] = $child;
69     }
70
71     /** Returns the child with index */
72     function getChild($index) {
73         return $this->children[(int)$index];
74     }
75
76     /** Add characters from #PCDATA areas to the wrapped element. */
77     function addText($data) {
78         $this->characters .= (string) $data;
79     }
80
81     function getElementTag() {
82         return $this->elementTag;
83     }
84
85
86     /** Configure the wrapped element and all children. */
87     function maybeConfigure(Project $project) {
88         $id = null;
89
90         // DataType configured in ProjectConfigurator
91         //        if ( is_a($this->wrappedObject, "DataType") )
92         //            return;
93
94         if ($this->attributes || $this->characters) {
95             ProjectConfigurator::configure($this->wrappedObject, $this->attributes, $project);
96
97             if (isset($this->attributes["id"])) {
98                 $id = $this->attributes["id"];
99             }
100
101             $this->attributes = null;
102
103             if ($this->characters) {
104                 ProjectConfigurator::addText($project, $this->wrappedObject, (string) $this->characters);
105                 $this->characters="";
106             }
107             if ($id !== null) {
108                 $project->addReference($id, $this->wrappedObject);
109             }
110         }
111
112         if ( is_array($this->children) && !empty($this->children) ) {
113             // Configure all child of this object ...
114             foreach($this->children as $child) {
115                 $child->maybeConfigure($project);
116                 ProjectConfigurator::storeChild($project, $this->wrappedObject, $child->wrappedObject, strtolower($child->getElementTag()));
117             }
118         }
119     }
120 }
121
122
Note: See TracBrowser for help on using the browser.