root / phpframework / trunk / fuseboxLexiconCompiler.php
| Revision 635, 8.4 kB (checked in by starkraving2002, 1 year 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 FuseboxLexiconCompiler { //I compile a lexicon verb. I am created for each verb that needs to be compiled and I provide the thread-safe context in which that verb is compiled. That includes the various fb_* methods used to write to the parsed file. |
| 53 | |
| 54 | var $fb_writer; |
| 55 | var $fb_; |
| 56 | var $lexiconInfo; |
| 57 | |
| 58 | function &init /*I am the constructor.*/ ( |
| 59 | &$writer, //I am the parsed file writer object. I am required but it's faster to specify that I am not required. |
| 60 | &$verbInfo, //I am the verb compilation context. I am required but it's faster to specify that I am not required. |
| 61 | &$lexiconInfo //I am the lexicon definition that supports this verb. I am required but it's faster to specify that I am not required. |
| 62 | ) { |
| 63 | |
| 64 | if ( isset($GLOBALS['attributes']['fusebox.debug']) && $GLOBALS['attributes']['fusebox.debug'] == 'true' ) echo '<ul><li>Starting $'.__CLASS__.'->'.__FUNCTION__.'()'; |
| 65 | $this->fb_writer =& $writer; |
| 66 | //$this->fb_ = array(); |
| 67 | $this->fb_['verbInfo'] =& $verbInfo; |
| 68 | $this->lexiconInfo =& $lexiconInfo; |
| 69 | $this->compiled = false; |
| 70 | if ( isset($GLOBALS['attributes']['fusebox.debug']) && $GLOBALS['attributes']['fusebox.debug'] == 'true' ) echo '</li><li>Ending $'.__CLASS__.'->'.__FUNCTION__.'()</li></ul>'; |
| 71 | return $this; |
| 72 | |
| 73 | } |
| 74 | |
| 75 | function compile() { //I compile a lexicon verb by including its implementation file. |
| 76 | |
| 77 | if ( isset($GLOBALS['attributes']['fusebox.debug']) && $GLOBALS['attributes']['fusebox.debug'] == 'true' ) echo '<ul><li>Starting $'.__CLASS__.'->'.__FUNCTION__.'()'; |
| 78 | // if ( array_key_exists('home',$GLOBALS['application']['fusebox']->circuits) ) echo "<br />".get_class($this).'.compile start: '.$GLOBALS['_fba']->circuits['home']->alias; |
| 79 | $info =& $this->lexiconInfo; |
| 80 | $lexiconFile = $info->lexicon['path']; |
| 81 | if ( !array_key_exists('targetCircuit',$this->fb_) ) $this->fb_['targetCircuit'] = $info->action->circuit; |
| 82 | $lexiconFile .= $info->verb; |
| 83 | $lexiconFile .= ".php"; |
| 84 | do { |
| 85 | $okay = false; |
| 86 | $fb_ =& $this->fb_; |
| 87 | //echo '<br>including '.$lexiconFile; |
| 88 | include($lexiconFile); |
| 89 | //if ( false == ( @include($lexiconFile) ) ) break; |
| 90 | $this->fb_ =& $fb_; |
| 91 | $okay = true; |
| 92 | } while ( false ); |
| 93 | if ( !$okay ) { |
| 94 | __cfthrow(array('type'=>"fusebox.badGrammar.missingImplementationException", |
| 95 | 'message'=>"Bad Grammar verb in circuit file", |
| 96 | 'detail'=>"The implementation file for the '{$info['verb']}' verb from the '{$info['lexicon']['namespace']}'" . |
| 97 | " custom lexicon could not be found. It is used in the '".$this->fb_['verbInfo']['circuit'].".".$this->fb_['verbInfo']['fuseaction']."' fuseaction." |
| 98 | )); |
| 99 | } |
| 100 | if ( $this->fb_['verbInfo']['executionMode'] == "end" ) { |
| 101 | if ( !$this->compiled && ( |
| 102 | array_key_exists('fuseactionException',$this->fb_writer->fuseboxApplication->pluginPhases) || |
| 103 | array_key_exists('processError',$this->fb_writer->fuseboxApplication->pluginPhases) |
| 104 | ) && |
| 105 | $this->fb_writer->fuseboxApplication->scriptVersion{0} != '5' ) { |
| 106 | $this->fb_writer->rawPrintln("if ( \$php_errormsg ) break;"); |
| 107 | } |
| 108 | $this->compiled = true; |
| 109 | } |
| 110 | if ( isset($GLOBALS['attributes']['fusebox.debug']) && $GLOBALS['attributes']['fusebox.debug'] == 'true' ) echo '</li><li>Ending $'.__CLASS__.'->'.__FUNCTION__.'()</li></ul>'; |
| 111 | } |
| 112 | |
| 113 | function fb_appendLine /*I append a line to the parsed file.*/ ( |
| 114 | $lineContent //I am the line of text to append. |
| 115 | ) { |
| 116 | if ( isset($GLOBALS['attributes']['fusebox.debug']) && $GLOBALS['attributes']['fusebox.debug'] == 'true' ) echo '<ul><li>Starting $'.__CLASS__.'->'.__FUNCTION__.'()'; |
| 117 | $this->fb_writer->println($lineContent); |
| 118 | if ( isset($GLOBALS['attributes']['fusebox.debug']) && $GLOBALS['attributes']['fusebox.debug'] == 'true' ) echo '</li><li>Ending $'.__CLASS__.'->'.__FUNCTION__.'()</li></ul>'; |
| 119 | } |
| 120 | |
| 121 | function fb_appendIndent() { //I am a no-op provided for backward compatibility. |
| 122 | } |
| 123 | |
| 124 | function fb_appendSegment /*I append a segment of text to the parsed file.*/ ( |
| 125 | $segmentContent //I am the segment of text to append. |
| 126 | ) { |
| 127 | if ( isset($GLOBALS['attributes']['fusebox.debug']) && $GLOBALS['attributes']['fusebox.debug'] == 'true' ) echo '<ul><li>Starting $'.__CLASS__.'->'.__FUNCTION__.'()'; |
| 128 | $this->fb_writer->_print($segmentContent); |
| 129 | if ( isset($GLOBALS['attributes']['fusebox.debug']) && $GLOBALS['attributes']['fusebox.debug'] == 'true' ) echo '</li><li>Ending $'.__CLASS__.'->'.__FUNCTION__.'()</li></ul>'; |
| 130 | } |
| 131 | |
| 132 | function fb_appendNewline() { //I append a newline to the parsed file. |
| 133 | if ( isset($GLOBALS['attributes']['fusebox.debug']) && $GLOBALS['attributes']['fusebox.debug'] == 'true' ) echo '<ul><li>Starting $'.__CLASS__.'->'.__FUNCTION__.'()'; |
| 134 | $this->fb_writer->println(""); |
| 135 | if ( isset($GLOBALS['attributes']['fusebox.debug']) && $GLOBALS['attributes']['fusebox.debug'] == 'true' ) echo '</li><li>Ending $'.__CLASS__.'->'.__FUNCTION__.'()</li></ul>'; |
| 136 | } |
| 137 | |
| 138 | function fb_increaseIndent() { //I am a no-op provided for backward compatibility. |
| 139 | } |
| 140 | |
| 141 | function fb_decreaseIndent() { //I am a no-op provided for backward compatibility. |
| 142 | } |
| 143 | |
| 144 | function fb_throw /*I throw the specified exception.*/ ( |
| 145 | $type, //I am the type of exception to throw. |
| 146 | $message, //I am the message to include in the thrown exception. |
| 147 | $detail //I am the detail to include in the thrown exception. |
| 148 | ) { |
| 149 | if ( isset($GLOBALS['attributes']['fusebox.debug']) && $GLOBALS['attributes']['fusebox.debug'] == 'true' ) echo '<ul><li>Starting $'.__CLASS__.'->'.__FUNCTION__.'()'; |
| 150 | |
| 151 | __cfthrow(array( 'type'=>$type, 'message'=>$message, 'detail'=>$detail)); |
| 152 | |
| 153 | if ( isset($GLOBALS['attributes']['fusebox.debug']) && $GLOBALS['attributes']['fusebox.debug'] == 'true' ) echo '</li><li>Ending $'.__CLASS__.'->'.__FUNCTION__.'()</li></ul>'; |
| 154 | } |
| 155 | |
| 156 | } |
| 157 | ?> |
Note: See TracBrowser
for help on using the browser.
