root / phpframework / trunk / fuseboxVerb.php
| Revision 427, 7.9 kB (checked in by starkraving2002, 2 years ago) | |
|---|---|
|
|
| Line | |
|---|---|
| 1 | <?php |
| 2 | /* |
| 3 | Fusebox Software License |
| 4 | Version 1.0 |
| 5 | |
| 6 | Copyright (c) 2003, 2004, 2005, 2006 The Fusebox Corporation. All rights reserved. |
| 7 | |
| 8 | Redistribution and use in source and binary forms, with or without modification, are permitted |
| 9 | provided that the following conditions are met: |
| 10 | |
| 11 | 1. Redistributions of source code must retain the above copyright notice, this list of conditions |
| 12 | and the following disclaimer. |
| 13 | |
| 14 | 2. 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 | |
| 18 | 3. 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 | |
| 26 | 4. 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 | |
| 30 | 5. 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 | |
| 34 | If one or more of the above conditions are violated, then this license is immediately revoked and |
| 35 | can be re-instated only upon prior written authorization of the Fusebox Corporation. |
| 36 | |
| 37 | THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 38 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 39 | DISCLAIMED. IN NO EVENT SHALL THE FUSEBOX CORPORATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY |
| 40 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 41 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 42 | BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
| 43 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 44 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 45 | |
| 46 | ------------------------------------------------------------------------------- |
| 47 | |
| 48 | This software consists of voluntary contributions made by many individuals on behalf of the |
| 49 | Fusebox Corporation. For more information on Fusebox, please see <http://www.fusebox.org/>. |
| 50 | |
| 51 | */ |
| 52 | class FuseboxVerb { //I represent a verb that is implemented as part of a lexicon. |
| 53 | |
| 54 | var $action; |
| 55 | var $attributes; |
| 56 | var $verb; |
| 57 | var $children; |
| 58 | var $factory; |
| 59 | var $nChildren; |
| 60 | var $fb41style; |
| 61 | var $lexicon; |
| 62 | |
| 63 | function FuseboxVerb /*I am the constructor.*/ ( |
| 64 | &$action, //I am the enclosing fuseaction object. |
| 65 | $customVerb, //I am the name of this (custom) verb. |
| 66 | $attributes, //I am the attributes for this verb. |
| 67 | &$children //I am the XML representation of any children this verb has. |
| 68 | ) { |
| 69 | if ( isset($GLOBALS['attributes']['fusebox.debug']) && $GLOBALS['attributes']['fusebox.debug'] == 'true' ) echo '<ul><li>Starting $'.__CLASS__.'->'.__FUNCTION__.'()'; |
| 70 | list($ns,$this->verb) = explode(':',str_replace('.',':',$customVerb)); |
| 71 | $i = 0; |
| 72 | $verb = ""; |
| 73 | $thisCircuit =& $action->getCircuit(); |
| 74 | $thisApp =& $thisCircuit->getApplication(); |
| 75 | $this->factory =& $thisApp->getFuseactionFactory(); |
| 76 | |
| 77 | $this->action =& $action; |
| 78 | $this->attributes = $attributes; |
| 79 | /* we will create our children below */ |
| 80 | $this->children = array(); |
| 81 | |
| 82 | $this->nChildren = count($children); |
| 83 | |
| 84 | for ( $i = 0 ; $i < $this->nChildren ; $i++ ) { |
| 85 | $verb = $children[$i]['xmlName']; |
| 86 | $this->children[$i] =& $this->factory->create($verb, |
| 87 | $this->action, |
| 88 | $children[$i]['xmlAttributes'], |
| 89 | $children[$i]['xmlChildren']); |
| 90 | } |
| 91 | $this->fb41style = (count(explode(".",$customVerb)) == 2); |
| 92 | if ( $this->fb41style ) { |
| 93 | $this->lexicon = $thisApp->getLexiconDefinition($ns); |
| 94 | } else { |
| 95 | $this->lexicon = $thisCircuit->getLexiconDefinition($ns); |
| 96 | } |
| 97 | |
| 98 | if ( isset($GLOBALS['attributes']['fusebox.debug']) && $GLOBALS['attributes']['fusebox.debug'] == 'true' ) echo '</li><li>Ending $'.__CLASS__.'->'.__FUNCTION__.'()</li></ul>'; |
| 99 | return $this; |
| 100 | |
| 101 | } |
| 102 | |
| 103 | function compile /*I compile a custom lexicon verb. I create the thread-safe context and perform the start and end execution, as well as compiling any children.*/ ( |
| 104 | &$writer, //I am the parsed file writer object. I am required but it's faster to specify that I am not required. |
| 105 | &$context //I am the context in which this verb is compiled. I can be omitted if the verb has no enclosing parent. |
| 106 | ) { |
| 107 | if ( isset($GLOBALS['attributes']['fusebox.debug']) && $GLOBALS['attributes']['fusebox.debug'] == 'true' ) echo '<ul><li>Starting $'.__CLASS__.'->'.__FUNCTION__.'()'; |
| 108 | // if ( array_key_exists('home',$GLOBALS['application']['fusebox']->circuits) ) echo "<br />".get_class($this).'.compile start: '.$GLOBALS['_fba']->circuits['home']->alias; |
| 109 | /* |
| 110 | the following is purely a device to allow nested custom verbs: |
| 111 | we pass the struct reference into the lexicon compiler but then we |
| 112 | fill in the fields here *afterwards* - relies on pass by reference! |
| 113 | because we are recursive, we need to create a new lexicon compiler |
| 114 | on each 'call' of the (static) compiler (i.e., this method) |
| 115 | trust me! -- sean corfield |
| 116 | */ |
| 117 | $verbInfo = array(); |
| 118 | $verbInfo['lexicon'] = $this->lexicon['namespace']; |
| 119 | $verbInfo['lexiconVerb'] = $this->verb; |
| 120 | $verbInfo['attributes'] = $this->attributes; |
| 121 | /* |
| 122 | change to FB41 lexicons (but needed for FB5): |
| 123 | circuit - alias of current circuit |
| 124 | fuseaction - name of current fuseaction |
| 125 | action - fuseaction object for more complex usage |
| 126 | */ |
| 127 | $circuit =& $this->action->getCircuit(); |
| 128 | $verbInfo['circuit'] = $circuit->getAlias(); |
| 129 | $verbInfo['fuseaction'] = $this->action->getName(); |
| 130 | $verbInfo['action'] =& $this->action; |
| 131 | |
| 132 | $oCompiler =& $this->factory->createLexiconCompiler(); |
| 133 | $compiler = $oCompiler->init($writer,$verbInfo,$this); |
| 134 | $i = 0; |
| 135 | |
| 136 | if ( $this->fb41style ) { |
| 137 | |
| 138 | /* FB41: just compile the lexicon once with no executionMode */ |
| 139 | $compiler->fb_['verbInfo'] =& $verbInfo; |
| 140 | $compiler->compile(); |
| 141 | |
| 142 | } else { |
| 143 | |
| 144 | /* |
| 145 | FB5 has new fields in verbInfo: |
| 146 | skipBody - false, can be set to true by start tag to skip compilation of child tags |
| 147 | hasChildren - true if there are nested tags, else false |
| 148 | parent - present if we are nested (the verbInfo of the parent tag) |
| 149 | executionMode - start|inactive|end, just like custom tags |
| 150 | */ |
| 151 | $verbInfo['skipBody'] = false; |
| 152 | $verbInfo['hasChildren'] = ( $this->nChildren != 0 ); |
| 153 | |
| 154 | if ( ( is_string($context) && strlen($context) > 0 ) || ( is_array($context) && count($context) > 0 ) ) { |
| 155 | $verbInfo['parent'] =& $context; |
| 156 | } |
| 157 | |
| 158 | $verbInfo['executionMode'] = "start"; |
| 159 | $compiler->fb_['verbInfo'] =& $verbInfo; |
| 160 | $compiler->compile(); |
| 161 | |
| 162 | if ( array_key_exists("skipBody",$verbInfo) && is_bool($verbInfo['skipBody']) && $verbInfo['skipBody'] ) { |
| 163 | /* the verb decided not to compile its children */ |
| 164 | } else { |
| 165 | if ( $this->nChildren > 0 ) { |
| 166 | $verbInfo['executionMode'] = "inactive"; |
| 167 | $compiler->fb_['verbInfo'] =& $verbInfo; |
| 168 | for ( $i = 0 ; $i < $this->nChildren ; $i++ ) { |
| 169 | $this->children[$i]->compile($writer,$verbInfo); |
| 170 | } |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | $verbInfo['executionMode'] = "end"; |
| 175 | $compiler->fb_['verbInfo'] =& $verbInfo; |
| 176 | $compiler->compile(); |
| 177 | |
| 178 | } |
| 179 | |
| 180 | $this->factory->freeLexiconCompiler($compiler); |
| 181 | if ( isset($GLOBALS['attributes']['fusebox.debug']) && $GLOBALS['attributes']['fusebox.debug'] == 'true' ) echo '</li><li>Ending $'.__CLASS__.'->'.__FUNCTION__.'()</li></ul>'; |
| 182 | } |
| 183 | |
| 184 | } |
| 185 | ?> |
Note: See TracBrowser
for help on using the browser.
