root / phpframework / trunk / fuseboxFactory.php

Revision 340, 8.3 kB (checked in by scorfield, 2 years ago)

Initial import of Fusebox 5.0.0 for PHP.

  • 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 FuseboxFactory { //I am a factory object that creates verb objects.
53
54    var $lexCompPool;
55    var $verbLexPool;
56    var $fuseboxLexicon;
57   
58    function FuseboxFactory() { //I am the constructor.
59        if ( isset($GLOBALS['attributes']['fusebox.debug']) && $GLOBALS['attributes']['fusebox.debug'] == 'true' ) echo '<ul><li>Starting $'.__CLASS__.'->'.__FUNCTION__.'()';
60       
61        $this->lexCompPool = 0;
62        $this->verbLexPool = 0;
63       
64        $this->fuseboxLexicon = array();
65        $this->fuseboxLexicon['namespace'] = "\$fusebox";
66        $this->fuseboxLexicon['path'] = "verbs/";
67       
68        if ( isset($GLOBALS['attributes']['fusebox.debug']) && $GLOBALS['attributes']['fusebox.debug'] == 'true' ) echo '</li><li>Ending $'.__CLASS__.'->'.__FUNCTION__.'()</li></ul>';
69        return $this;
70       
71    }
72   
73    function &create /*I create a verb object.*/ (
74            $verb, //I am the name of the verb to create.
75            &$action, //I am the enclosing fuseaction object.
76            $attributes, //I am the attributes of this verb.
77            $children, //I am the XML representation of this verb's children.
78            $global=false //I indicate whether this is part of a regular fuseaction (false) or a global fuseaction (true).
79        ) {
80        if ( isset($GLOBALS['attributes']['fusebox.debug']) && $GLOBALS['attributes']['fusebox.debug'] == 'true' ) echo '<ul><li>Starting $'.__CLASS__.'->'.__FUNCTION__.'()';
81        $verbObject = "";
82        $_fbc =& $action->getCircuit();
83        $_fba =& $_fbc->getApplication();
84       
85        /* global pre/post process is a special case: */
86        if ( $global ) {
87            if ( in_array($verb,array("do","fuseaction")) ) {
88                /* this is OK, do is deprecated */
89                if ( $verb == "do" and $_fba->strictMode ) {
90                    __cfthrow(array( 'type'=>"fusebox.badGrammar.deprecated",
91                        'message'=>"Deprecated feature",
92                        'detail'=>"Using the 'do' verb in a global pre/post process was deprecated in Fusebox 4.1."
93                    ));
94                }
95            } else {
96                /* no other verbs are allowed */
97                __cfthrow(array( 'type'=>"fusebox.badGrammar.illegalVerb",
98                    'message'=>"Illegal verb encountered",
99                    'detail'=>"The '{$verb}' verb is illegal in a global pre/post process."
100                ));
101            }
102        } else {
103            if ( in_array($verb,array("fuseaction")) ) {
104                /* verbs that are only legal in global pre/post process */
105                __cfthrow(array( 'type'=>"fusebox.badGrammar.illegalVerb",
106                    'message'=>"Illegal verb encountered",
107                    'detail'=>"The '{$verb}' verb is only legal in a global pre/post process."
108                ));
109            }
110        }
111        if ( count(explode(":",str_replace(".",":",$verb))) == 2 ) {
112            /* must be namespace.verb or namespace:verb */
113            require_once("fuseboxVerb.php");
114            if ( !isPHP5() ) { eval('$verbObject =& new FuseboxVerb($action, $verb, $attributes, $children);'); } else { $verbObject = new FuseboxVerb($action, $verb, $attributes, $children); }
115        } elseif ( in_array($verb,array("do","fuseaction")) ) {
116            /* built-in verbs that cannot be implemented as a lexicon */
117            require_once("fuseboxDoFuseaction.php");
118            if ( !isPHP5() ) { eval('$verbObject =& new FuseboxDoFuseaction($action,$attributes,$children,$verb);'); } else { $verbObject = new FuseboxDoFuseaction($action,$attributes,$children,$verb); }
119        } else {
120            /* builtin verb implemented as a lexicon */
121            require_once("fuseboxVerb.php");
122            if ( !isPHP5() ) {
123                eval('$verbObject =& new FuseboxVerb($action, $this->fuseboxLexicon["namespace"] . ":" . $verb,$attributes, $children);');
124            } else {
125                $verbObject = new FuseboxVerb($action, $this->fuseboxLexicon['namespace'] . ":" . $verb,
126                            $attributes, $children);
127            }
128        }
129        if ( isset($GLOBALS['attributes']['fusebox.debug']) && $GLOBALS['attributes']['fusebox.debug'] == 'true' ) echo '</li><li>Ending $'.__CLASS__.'->'.__FUNCTION__.'()</li></ul>';
130        return $verbObject;
131    }
132   
133    function &createLexiconCompiler() { //I return a lexicon compiler context (either from the pool or a newly created instance).
134   
135        if ( isset($GLOBALS['attributes']['fusebox.debug']) && $GLOBALS['attributes']['fusebox.debug'] == 'true' ) echo '<ul><li>Starting $'.__CLASS__.'->'.__FUNCTION__.'()';
136        if ( !is_object($this->lexCompPool) ) {
137            require_once("fuseboxLexiconCompiler.php");
138            if ( !isPHP5() ) { eval('$obj =& new FuseboxLexiconCompiler();'); } else { $obj = new FuseboxLexiconCompiler(); }
139        } else {
140            $obj =& $this->lexCompPool;
141            $this->lexCompPool =& $obj->_next;
142        }
143       
144        if ( isset($GLOBALS['attributes']['fusebox.debug']) && $GLOBALS['attributes']['fusebox.debug'] == 'true' ) echo '</li><li>Ending $'.__CLASS__.'->'.__FUNCTION__.'()</li></ul>';
145        return $obj;
146   
147    }
148   
149    function freeLexiconCompiler /*I return the lexicon compiler context to the pool.*/ (
150            $lexComp //I am the lexicon compiler context to be returned. I am required but it's faster to specify that I am not required.
151        ) {
152   
153        if ( isset($GLOBALS['attributes']['fusebox.debug']) && $GLOBALS['attributes']['fusebox.debug'] == 'true' ) echo '<ul><li>Starting $'.__CLASS__.'->'.__FUNCTION__.'()';
154        $lexComp->_next =& $this->lexCompPool;
155        $this->lexCompPool =& $lexComp;
156       
157        if ( isset($GLOBALS['attributes']['fusebox.debug']) && $GLOBALS['attributes']['fusebox.debug'] == 'true' ) echo '</li><li>Ending $'.__CLASS__.'->'.__FUNCTION__.'()</li></ul>';
158    }
159   
160    function getBuiltinLexicon() { //I return the (magic) builtin lexicon.
161       
162        if ( isset($GLOBALS['attributes']['fusebox.debug']) && $GLOBALS['attributes']['fusebox.debug'] == 'true' ) echo '<ul><li>Starting $'.__CLASS__.'->'.__FUNCTION__.'()';
163        if ( isset($GLOBALS['attributes']['fusebox.debug']) && $GLOBALS['attributes']['fusebox.debug'] == 'true' ) echo '</li><li>Ending $'.__CLASS__.'->'.__FUNCTION__.'()</li></ul>';
164        return $this->fuseboxLexicon;
165       
166    }
167   
168}
169?>
Note: See TracBrowser for help on using the browser.