root / phpframework / trunk / fuseboxAction.php

Revision 427, 8.3 kB (checked in by starkraving2002, 2 years ago)

fixed context reference for child verbs

  • Property svn:executable set to *
Line 
1<?php
2/*
3Fusebox Software License
4Version 1.0
5
6Copyright (c) 2003, 2004, 2005, 2006 The Fusebox Corporation. All rights reserved.
7
8Redistribution and use in source and binary forms, with or without modification, are permitted
9provided that the following conditions are met:
10
111. Redistributions of source code must retain the above copyright notice, this list of conditions
12   and the following disclaimer.
13
142. Redistributions in binary form or otherwise encrypted form must reproduce the above copyright
15   notice, this list of conditions and the following disclaimer in the documentation and/or other
16   materials provided with the distribution.
17
183. The end-user documentation included with the redistribution, if any, must include the following
19   acknowledgment:
20
21   "This product includes software developed by the Fusebox Corporation (http://www.fusebox.org/)."
22
23   Alternately, this acknowledgment may appear in the software itself, if and wherever such
24   third-party acknowledgments normally appear.
25
264. The names "Fusebox" and "Fusebox Corporation" must not be used to endorse or promote products
27   derived from this software without prior written (non-electronic) permission. For written
28   permission, please contact fusebox@fusebox.org.
29
305. Products derived from this software may not be called "Fusebox", nor may "Fusebox" appear in
31   their name, without prior written (non-electronic) permission of the Fusebox Corporation. For
32   written permission, please contact fusebox@fusebox.org.
33
34If one or more of the above conditions are violated, then this license is immediately revoked and
35can be re-instated only upon prior written authorization of the Fusebox Corporation.
36
37THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
38LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
39DISCLAIMED. IN NO EVENT SHALL THE FUSEBOX CORPORATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY
40DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
41LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
42BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
43STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
44OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
45
46-------------------------------------------------------------------------------
47
48This software consists of voluntary contributions made by many individuals on behalf of the
49Fusebox Corporation. For more information on Fusebox, please see <http://www.fusebox.org/>.
50
51*/
52class FuseboxAction { //I represent a fuseaction within a circuit.
53
54    var $circuit;
55    var $name;
56    var $customAttributes;
57    var $nChildren;
58    var $actions;
59    var $access;
60   
61    function FuseboxAction /*I am the constructor.*/ (
62            &$circuit, //I am the circuit to which this fuseaction belongs. I am required but it's faster to specify that I am not required.
63            $name, //I am the name of the fuseaction. I am required but it's faster to specify that I am not required.
64            $access, //I am the access criteria for the fuseaction. I am required but it's faster to specify that I am not required.
65            $children, //I am the verbs for this fuseaction. I am required but it's faster to specify that I am not required.
66            $global = false, //I indicate whether or not this is a globalfuseaction in fusebox.xml.
67            $customAttribs = array() //I hold the custom (namespace-qualified) attributes in the fuseaction tag.
68        ) {
69       
70        if ( isset($GLOBALS['attributes']['fusebox.debug']) && $GLOBALS['attributes']['fusebox.debug'] == 'true' ) echo '<ul><li>Starting $'.__CLASS__.'->'.__FUNCTION__.'()';
71        $i = 0;
72        $verb = "";
73        $app =& $circuit->getApplication();
74        $factory =& $app->getFuseactionFactory();
75
76        $this->circuit =& $circuit;
77        $this->name = $name;
78        $this->customAttributes = $customAttribs;
79        $this->nChildren = count($children);
80        $this->actions = array();
81        //var_dump($children);
82        $this->access = $access;
83        for ( $i = 0 ; $i < $this->nChildren ; $i++ ) {
84            $this->actions[$i] =& $factory->create($children[$i]['xmlName'],
85                    $this,$children[$i]['xmlAttributes'],$children[$i]['xmlChildren'],
86                        $global);
87        }
88       
89        if ( isset($GLOBALS['attributes']['fusebox.debug']) && $GLOBALS['attributes']['fusebox.debug'] == 'true' ) echo '</li><li>Ending $'.__CLASS__.'->'.__FUNCTION__.'()</li></ul>';
90        return $this;
91       
92    }
93   
94    function compile /*I compile this fuseaction.*/ (
95            &$writer //I am the writer object to which the compiled code should be written. I am required but it's faster to specify that I am not required.
96        ) {
97        if ( isset($GLOBALS['attributes']['fusebox.debug']) && $GLOBALS['attributes']['fusebox.debug'] == 'true' ) echo '<ul><li>Starting $'.__CLASS__.'->'.__FUNCTION__.'()';
98        $i = 0;
99        $n = 0;
100        $this->context = array();
101        for ( $i = 0 ; $i < $this->nChildren ; $i++ ) {
102            $this->actions[$i]->compile($writer,$this->context);
103        }
104        if ( isset($GLOBALS['attributes']['fusebox.debug']) && $GLOBALS['attributes']['fusebox.debug'] == 'true' ) echo '</li><li>Ending $'.__CLASS__.'->'.__FUNCTION__.'()</li></ul>';
105    }
106   
107    function getName() { //I return the name of the fuseaction.
108       
109        if ( isset($GLOBALS['attributes']['fusebox.debug']) && $GLOBALS['attributes']['fusebox.debug'] == 'true' ) echo '<ul><li>Starting $'.__CLASS__.'->'.__FUNCTION__.'()';
110        if ( isset($GLOBALS['attributes']['fusebox.debug']) && $GLOBALS['attributes']['fusebox.debug'] == 'true' ) echo '</li><li>Ending $'.__CLASS__.'->'.__FUNCTION__.'()</li></ul>';
111        return $this->name;
112       
113    }
114
115    function &getCircuit() { //I return the enclosing circuit object.
116   
117        if ( isset($GLOBALS['attributes']['fusebox.debug']) && $GLOBALS['attributes']['fusebox.debug'] == 'true' ) echo '<ul><li>Starting $'.__CLASS__.'->'.__FUNCTION__.'()';
118        if ( isset($GLOBALS['attributes']['fusebox.debug']) && $GLOBALS['attributes']['fusebox.debug'] == 'true' ) echo '</li><li>Ending $'.__CLASS__.'->'.__FUNCTION__.'()</li></ul>';
119        return $this->circuit;
120   
121    }
122   
123    function getAccess() { //I am a convenience method to return this fuseaction's access attribute value.
124   
125        if ( isset($GLOBALS['attributes']['fusebox.debug']) && $GLOBALS['attributes']['fusebox.debug'] == 'true' ) echo '<ul><li>Starting $'.__CLASS__.'->'.__FUNCTION__.'()';
126        if ( isset($GLOBALS['attributes']['fusebox.debug']) && $GLOBALS['attributes']['fusebox.debug'] == 'true' ) echo '</li><li>Ending $'.__CLASS__.'->'.__FUNCTION__.'()</li></ul>';
127        return $this->access;
128   
129    }
130   
131    function getPermissions /*I return the aggregated permissions for this fuseaction.*/ (
132            $inheritFromCircuit = true, //I indicate whether or not the circuit's permissions should be returned if this fuseaction has no permissions specified.";
133            $useCircuitTrace = false //I indicate whether or not to inherit the parent circuit's permissions if this fuseaction's circuit has no permissions specified.
134        ) {
135   
136        if ( isset($GLOBALS['attributes']['fusebox.debug']) && $GLOBALS['attributes']['fusebox.debug'] == 'true' ) echo '<ul><li>Starting $'.__CLASS__.'->'.__FUNCTION__.'()';
137        if ( isset($GLOBALS['attributes']['fusebox.debug']) && $GLOBALS['attributes']['fusebox.debug'] == 'true' ) echo '</li><li>Ending $'.__CLASS__.'->'.__FUNCTION__.'()</li></ul>';
138        if ( $this->permissions == "" && $inheritFromCircuit ) {
139            $_c = $this->getCircuit();
140            return $_c->getPermissions($useCircuitTrace);
141        } else {
142            return $this->permissions;
143        }
144   
145    }
146   
147    function getCustomAttributes /*I return the custom (namespace-qualified) attributes for this fuseaction tag.*/ (
148            $ns //I am the namespace prefix whose attributes should be returned.
149        ) {
150       
151        if ( isset($GLOBALS['attributes']['fusebox.debug']) && $GLOBALS['attributes']['fusebox.debug'] == 'true' ) echo '<ul><li>Starting $'.__CLASS__.'->'.__FUNCTION__.'()';
152        if ( isset($GLOBALS['attributes']['fusebox.debug']) && $GLOBALS['attributes']['fusebox.debug'] == 'true' ) echo '</li><li>Ending $'.__CLASS__.'->'.__FUNCTION__.'()</li></ul>';
153        if ( array_key_exists($ns,$this->customAttributes) ) {
154            // we structCopy() this so folks can't poke values back into the metadata!
155            //return structCopy($this->customAttributes[$ns]);
156            return $this->customAttributes[$ns];
157        } else {
158            return $array();
159        }
160       
161    }
162   
163}
164?>
Note: See TracBrowser for help on using the browser.