| 1 | <?php |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | |
|---|
| 22 | |
|---|
| 23 | |
|---|
| 24 | |
|---|
| 25 | |
|---|
| 26 | |
|---|
| 27 | |
|---|
| 28 | |
|---|
| 29 | |
|---|
| 30 | |
|---|
| 31 | |
|---|
| 32 | |
|---|
| 33 | |
|---|
| 34 | |
|---|
| 35 | |
|---|
| 36 | |
|---|
| 37 | |
|---|
| 38 | |
|---|
| 39 | |
|---|
| 40 | |
|---|
| 41 | |
|---|
| 42 | |
|---|
| 43 | |
|---|
| 44 | |
|---|
| 45 | |
|---|
| 46 | |
|---|
| 47 | |
|---|
| 48 | |
|---|
| 49 | |
|---|
| 50 | |
|---|
| 51 | |
|---|
| 52 | class MyFusebox { |
|---|
| 53 | var $version; |
|---|
| 54 | var $thisCircuit; |
|---|
| 55 | var $thisFuseaction; |
|---|
| 56 | var $thisPlugin; |
|---|
| 57 | var $thisPhase; |
|---|
| 58 | var $plugins; |
|---|
| 59 | var $parameters; |
|---|
| 60 | var $stack; |
|---|
| 61 | |
|---|
| 62 | var $created; |
|---|
| 63 | var $log; |
|---|
| 64 | var $occurence; |
|---|
| 65 | var $frame; |
|---|
| 66 | |
|---|
| 67 | |
|---|
| 68 | function MyFusebox ( $appKey, $attributes ) { |
|---|
| 69 | if ( isset($GLOBALS['attributes']['fusebox.debug']) && $GLOBALS['attributes']['fusebox.debug'] == 'true' ) echo '<ul><li>Starting $'.__CLASS__.'->'.__FUNCTION__.'()'; |
|---|
| 70 | |
|---|
| 71 | $this->thisCircuit = ""; |
|---|
| 72 | $this->thisFuseaction = ""; |
|---|
| 73 | $this->thisPlugin = ""; |
|---|
| 74 | $this->thisPhase = ""; |
|---|
| 75 | |
|---|
| 76 | $this->version = array(); |
|---|
| 77 | $this->version['runtime'] = "unknown"; |
|---|
| 78 | $this->version['loader'] = "unknown"; |
|---|
| 79 | $this->version['transformer'] = "unknown"; |
|---|
| 80 | $this->version['parser'] = "unknown"; |
|---|
| 81 | |
|---|
| 82 | $this->version['runtime'] = "5.0.0.GR.0"; |
|---|
| 83 | |
|---|
| 84 | |
|---|
| 85 | $this->parameters = array(); |
|---|
| 86 | $this->parameters['load'] = true; |
|---|
| 87 | $this->parameters['parse'] = true; |
|---|
| 88 | $this->parameters['execute'] = true; |
|---|
| 89 | |
|---|
| 90 | $this->parameters['clean'] = false; |
|---|
| 91 | $this->parameters['parseall'] = false; |
|---|
| 92 | |
|---|
| 93 | $this->parameters['userProvidedLoadParameter'] = false; |
|---|
| 94 | $this->parameters['userProvidedCleanParameter'] = false; |
|---|
| 95 | $this->parameters['userProvidedParseParameter'] = false; |
|---|
| 96 | $this->parameters['userProvidedParseAllParameter'] = false; |
|---|
| 97 | $this->parameters['userProvidedExecuteParameter'] = false; |
|---|
| 98 | |
|---|
| 99 | $this->plugins = array(); |
|---|
| 100 | |
|---|
| 101 | |
|---|
| 102 | $this->stack = array(); |
|---|
| 103 | |
|---|
| 104 | |
|---|
| 105 | $this->appKey = $appKey; |
|---|
| 106 | $theFusebox = array(); |
|---|
| 107 | |
|---|
| 108 | list($usec, $sec) = explode(" ", microtime()); |
|---|
| 109 | $this->created = ((float)$usec + (float)$sec); |
|---|
| 110 | |
|---|
| 111 | $this->log = array(); |
|---|
| 112 | $this->occurrence = array(); |
|---|
| 113 | |
|---|
| 114 | |
|---|
| 115 | if ( isset($GLOBALS['application']) && is_array($GLOBALS['application']) && array_key_exists($this->appKey,$GLOBALS['application']) ) { |
|---|
| 116 | $theFusebox =& $GLOBALS['application'][$this->appKey]; |
|---|
| 117 | } |
|---|
| 118 | |
|---|
| 119 | if ( is_object($theFusebox) && array_key_exists("mode",get_object_vars($theFusebox)) ) { |
|---|
| 120 | switch ( $theFusebox->mode ) { |
|---|
| 121 | |
|---|
| 122 | case "development" : |
|---|
| 123 | if ( array_key_exists('strictMode',get_object_vars($theFusebox)) && $theFusebox->strictMode ) { |
|---|
| 124 | |
|---|
| 125 | $theFusebox->mode = "development-full-load"; |
|---|
| 126 | __cfthrow(array( 'type'=>"fusebox.badGrammar.deprecated", |
|---|
| 127 | 'message'=>"Deprecated feature", |
|---|
| 128 | 'detail'=>"'development' is a deprecated execution mode - use 'development-full-load' instead.")); |
|---|
| 129 | } |
|---|
| 130 | $this->parameters['load'] = true; |
|---|
| 131 | $this->parameters['parse'] = true; |
|---|
| 132 | $this->parameters['execute'] = true; |
|---|
| 133 | break; |
|---|
| 134 | |
|---|
| 135 | case "development-full-load" : |
|---|
| 136 | $this->parameters['load'] = true; |
|---|
| 137 | $this->parameters['parse'] = true; |
|---|
| 138 | $this->parameters['execute'] = true; |
|---|
| 139 | break; |
|---|
| 140 | |
|---|
| 141 | case "development-circuit-load" : |
|---|
| 142 | $this->parameters['load'] = false; |
|---|
| 143 | $this->parameters['parse'] = true; |
|---|
| 144 | $this->parameters['execute'] = true; |
|---|
| 145 | break; |
|---|
| 146 | case "production" : |
|---|
| 147 | $this->parameters['load'] = false; |
|---|
| 148 | $this->parameters['parse'] = false; |
|---|
| 149 | $this->parameters['execute'] = true; |
|---|
| 150 | break; |
|---|
| 151 | default: |
|---|
| 152 | |
|---|
| 153 | $theFusebox->mode = "development-full-load"; |
|---|
| 154 | __cfthrow(array( 'type'=>"fusebox.badGrammar.invalidParameterValue", |
|---|
| 155 | 'message'=>"Parameter has invalid value", |
|---|
| 156 | 'detail'=>"The parameter 'mode' must be one of 'development-full-load', 'development-circuit-load' or 'production' in the fusebox.xml file.")); |
|---|
| 157 | break; |
|---|
| 158 | } |
|---|
| 159 | } |
|---|
| 160 | |
|---|
| 161 | |
|---|
| 162 | |
|---|
| 163 | if ( !isset($attributes["fusebox.password"]) ) { $attributes["fusebox.password"] = ""; } |
|---|
| 164 | if ( is_object($theFusebox) && array_key_exists('password',get_object_vars($theFusebox)) && $theFusebox->password == $attributes['fusebox.password'] ) { |
|---|
| 165 | |
|---|
| 166 | if ( array_key_exists('fusebox.loadclean',$attributes) && in_array($attributes['fusebox.loadclean'],array('true','false')) ) { |
|---|
| 167 | $this->parameters['load'] = ( $attributes['fusebox.loadclean'] == 'true' ); |
|---|
| 168 | $this->parameters['clean'] = ( $attributes['fusebox.loadclean'] == 'true' ); |
|---|
| 169 | $this->parameters['userProvidedLoadParameter'] = true; |
|---|
| 170 | $this->parameters['userProvidedCleanParameter'] = true; |
|---|
| 171 | } |
|---|
| 172 | if ( array_key_exists('fusebox.load',$attributes) && in_array($attributes['fusebox.load'],array('true','false')) ) { |
|---|
| 173 | $this->parameters['load'] = ( $attributes['fusebox.load'] == 'true' ); |
|---|
| 174 | $this->parameters['userProvidedLoadParameter'] = true; |
|---|
| 175 | } |
|---|
| 176 | if ( array_key_exists('fusebox.parseall',$attributes) && in_array($attributes['fusebox.parseall'],array('true','false')) ) { |
|---|
| 177 | $this->parameters['parse'] = ( $attributes['fusebox.parseall'] == 'true' ); |
|---|
| 178 | $this->parameters['parseall'] = ( $attributes['fusebox.parseall'] == 'true' ); |
|---|
| 179 | if ( $this->parameters['parseall'] ) { |
|---|
| 180 | $this->parameters['load'] = true; |
|---|
| 181 | } |
|---|
| 182 | $this->parameters['userProvidedLoadParameter'] = true; |
|---|
| 183 | $this->parameters['userProvidedParseParameter'] = true; |
|---|
| 184 | $this->parameters['userProvidedParseAllParameter'] = true; |
|---|
| 185 | } |
|---|
| 186 | if ( array_key_exists('fusebox.parse',$attributes) && in_array($attributes['fusebox.parse'],array('true','false')) ) { |
|---|
| 187 | $this->parameters['parse'] = ( $attributes['fusebox.parse'] == 'true' ); |
|---|
| 188 | $this->parameters['userProvidedParseParameter'] = true; |
|---|
| 189 | } |
|---|
| 190 | if ( array_key_exists('fusebox.execute',$attributes) && in_array($attributes['fusebox.execute'],array('true','false')) ) { |
|---|
| 191 | $this->parameters['execute'] = ( $attributes['fusebox.execute'] == 'true' ); |
|---|
| 192 | $this->parameters['userProvidedExecuteParameter'] = true; |
|---|
| 193 | } |
|---|
| 194 | } |
|---|
| 195 | |
|---|
| 196 | |
|---|
| 197 | |
|---|
| 198 | |
|---|
| 199 | |
|---|
| 200 | |
|---|
| 201 | if ( is_object($theFusebox) && ( in_array('getversion',get_class_methods($theFusebox)) || in_array('getVersion',get_class_methods($theFusebox)) ) ) { |
|---|
| 202 | if ( $this->version['runtime'] != $theFusebox->getVersion() ) { |
|---|
| 203 | $this->parameters['userProvidedLoadParameter'] = true; |
|---|
| 204 | $this->parameters['load'] = true; |
|---|
| 205 | } |
|---|
| 206 | } else { |
|---|
| 207 | |
|---|
| 208 | $this->parameters['userProvidedLoadParameter'] = true; |
|---|
| 209 | $this->parameters['load'] = true; |
|---|
| 210 | } |
|---|
| 211 | |
|---|
| 212 | |
|---|
| 213 | if ( is_object($theFusebox) && array_key_exists("isFullyLoaded",get_object_vars($theFusebox)) && $theFusebox->isFullyLoaded ) { |
|---|
| 214 | |
|---|
| 215 | } else { |
|---|
| 216 | $this->parameters['load'] = true; |
|---|
| 217 | } |
|---|
| 218 | |
|---|
| 219 | $this->theFusebox =& $theFusebox; |
|---|
| 220 | if ( isset($GLOBALS['attributes']['fusebox.debug']) && $GLOBALS['attributes']['fusebox.debug'] == 'true' ) echo '</li><li>Ending $'.__CLASS__.'->'.__FUNCTION__.'()</li></ul>'; |
|---|
| 221 | return $this; |
|---|
| 222 | } |
|---|
| 223 | |
|---|
| 224 | function &getApplication () { |
|---|
| 225 | if ( isset($GLOBALS['attributes']['fusebox.debug']) && $GLOBALS['attributes']['fusebox.debug'] == 'true' ) echo '<ul><li>Starting $'.__CLASS__.'->'.__FUNCTION__.'()'; |
|---|
| 226 | |
|---|
| 227 | |
|---|
| 228 | |
|---|
| 229 | |
|---|
| 230 | |
|---|
| 231 | |
|---|
| 232 | if ( isset($GLOBALS['attributes']['fusebox.debug']) && $GLOBALS['attributes']['fusebox.debug'] == 'true' ) echo '</li><li>Ending $'.__CLASS__.'->'.__FUNCTION__.'()</li></ul>'; |
|---|
| 233 | return $GLOBALS['application'][$this->appKey]; |
|---|
| 234 | |
|---|
| 235 | } |
|---|
| 236 | |
|---|
| 237 | function &getCurrentCircuit() { |
|---|
| 238 | if ( isset($GLOBALS['attributes']['fusebox.debug']) && $GLOBALS['attributes']['fusebox.debug'] == 'true' ) echo '<ul><li>Starting $'.__CLASS__.'->'.__FUNCTION__.'()'; |
|---|
| 239 | |
|---|
| 240 | if ( isset($GLOBALS['attributes']['fusebox.debug']) && $GLOBALS['attributes']['fusebox.debug'] == 'true' ) echo '</li><li>Ending $'.__CLASS__.'->'.__FUNCTION__.'()</li></ul>'; |
|---|
| 241 | return $GLOBALS['application'][$this->appKey]->circuits[$this->thisCircuit]; |
|---|
| 242 | |
|---|
| 243 | } |
|---|
| 244 | |
|---|
| 245 | function &getCurrentFuseaction() { |
|---|
| 246 | if ( isset($GLOBALS['attributes']['fusebox.debug']) && $GLOBALS['attributes']['fusebox.debug'] == 'true' ) echo '<ul><li>Starting $'.__CLASS__.'->'.__FUNCTION__.'()'; |
|---|
| 247 | |
|---|
| 248 | if ( isset($GLOBALS['attributes']['fusebox.debug']) && $GLOBALS['attributes']['fusebox.debug'] == 'true' ) echo '</li><li>Ending $'.__CLASS__.'->'.__FUNCTION__.'()</li></ul>'; |
|---|
| 249 | return $GLOBALS['application'][$this->appKey]->circuits[$this->thisCircuit]->fuseactions[$this->thisFuseaction]; |
|---|
| 250 | |
|---|
| 251 | } |
|---|
| 252 | |
|---|
| 253 | function enterStackFrame() { |
|---|
| 254 | if ( isset($GLOBALS['attributes']['fusebox.debug']) && $GLOBALS['attributes']['fusebox.debug'] == 'true' ) echo '<ul><li>Starting $'.__CLASS__.'->'.__FUNCTION__.'()'; |
|---|
| 255 | |
|---|
| 256 | $frame = array(); |
|---|
| 257 | |
|---|
| 258 | $frame['__fuseboxStack'] = $this->stack; |
|---|
| 259 | $this->stack = $frame; |
|---|
| 260 | |
|---|
| 261 | if ( isset($GLOBALS['attributes']['fusebox.debug']) && $GLOBALS['attributes']['fusebox.debug'] == 'true' ) echo '</li><li>Ending $'.__CLASS__.'->'.__FUNCTION__.'()</li></ul>'; |
|---|
| 262 | } |
|---|
| 263 | |
|---|
| 264 | function leaveStackFrame() { |
|---|
| 265 | if ( isset($GLOBALS['attributes']['fusebox.debug']) && $GLOBALS['attributes']['fusebox.debug'] == 'true' ) echo '<ul><li>Starting $'.__CLASS__.'->'.__FUNCTION__.'()'; |
|---|
| 266 | |
|---|
| 267 | $this->stack = $this->stack['__fuseboxStack']; |
|---|
| 268 | |
|---|
| 269 | if ( isset($GLOBALS['attributes']['fusebox.debug']) && $GLOBALS['attributes']['fusebox.debug'] == 'true' ) echo '</li><li>Ending $'.__CLASS__.'->'.__FUNCTION__.'()</li></ul>'; |
|---|
| 270 | } |
|---|
| 271 | |
|---|
| 272 | function trace ( $type, $message, $theTime = 0 ) { |
|---|
| 273 | if ( isset($GLOBALS['attributes']['fusebox.debug']) && $GLOBALS['attributes']['fusebox.debug'] == 'true' ) echo '<ul><li>Starting $'.__CLASS__.'->'.__FUNCTION__.'()'; |
|---|
| 274 | |
|---|
| 275 | list($usec, $sec) = explode(" ", microtime()); |
|---|
| 276 | $theTime = ( $theTime > 0 ) ? $theTime : ((float)$usec + (float)$sec); |
|---|
| 277 | $this->addTrace(($theTime - $this->created) * 1000,$type,$message); |
|---|
| 278 | |
|---|
| 279 | if ( isset($GLOBALS['attributes']['fusebox.debug']) && $GLOBALS['attributes']['fusebox.debug'] == 'true' ) echo '</li><li>Ending $'.__CLASS__.'->'.__FUNCTION__.'()</li></ul>'; |
|---|
| 280 | } |
|---|
| 281 | |
|---|
| 282 | function addTrace( |
|---|
| 283 | $time, |
|---|
| 284 | $type, |
|---|
| 285 | $message, |
|---|
| 286 | $occurrence = 0 |
|---|
| 287 | ) { |
|---|
| 288 | if ( isset($GLOBALS['attributes']['fusebox.debug']) && $GLOBALS['attributes']['fusebox.debug'] == 'true' ) echo '<ul><li>Starting $'.__CLASS__.'->'.__FUNCTION__.'()'; |
|---|
| 289 | global $log; |
|---|
| 290 | if ( array_key_exists($message,$this->occurrence) ) { |
|---|
| 291 | $this->occurrence[$message]++; |
|---|
| 292 | } else { |
|---|
| 293 | $this->occurrence[$message] = 1; |
|---|
| 294 | } |
|---|
| 295 | $occurrence = $this->occurrence[$message]; |
|---|
| 296 | $log[] = array('time'=>$time,'type'=>$type,'message'=>$message,'occurrence'=>$occurrence); |
|---|
| 297 | if ( isset($GLOBALS['attributes']['fusebox.debug']) && $GLOBALS['attributes']['fusebox.debug'] == 'true' ) echo '</li><li>Ending $'.__CLASS__.'->'.__FUNCTION__.'()</li></ul>'; |
|---|
| 298 | } |
|---|
| 299 | |
|---|
| 300 | function renderTrace() { |
|---|
| 301 | if ( isset($GLOBALS['attributes']['fusebox.debug']) && $GLOBALS['attributes']['fusebox.debug'] == 'true' ) echo '<ul><li>Starting $'.__CLASS__.'->'.__FUNCTION__.'()'; |
|---|
| 302 | |
|---|
| 303 | global $log; |
|---|
| 304 | $result = ""; |
|---|
| 305 | $i = 0; |
|---|
| 306 | |
|---|
| 307 | $result = ' |
|---|
| 308 | <br /> |
|---|
| 309 | <div style="clear:both;padding-top:10px;border-bottom:1px Solid #CCC;font-family:verdana;font-size:16px;font-weight:bold">Fusebox debugging:</div> |
|---|
| 310 | <br /> |
|---|
| 311 | <table cellpadding="2" cellspacing="0" width="100%" style="border:1px Solid #CCC;font-family:verdana;font-size:11pt;"> |
|---|
| 312 | <tr style="background:#EAEAEA"> |
|---|
| 313 | <td style="border-bottom:1px Solid #CCC;font-family:verdana;font-size:11pt;"><strong>Time</strong></td> |
|---|
| 314 | <td style="border-bottom:1px Solid #CCC;font-family:verdana;font-size:11pt;"><strong>Category</strong></td> |
|---|
| 315 | <td style="border-bottom:1px Solid #CCC;font-family:verdana;font-size:11pt;"><strong>Message</strong></td> |
|---|
| 316 | <td style="border-bottom:1px Solid #CCC;font-family:verdana;font-size:11pt;"><strong>Count</strong></td> |
|---|
| 317 | </tr> |
|---|
| 318 | '; for ( $i = 0 ; $i < count($log) ; $i++ ) { |
|---|
| 319 | $result .= ( $i % 2 > 0 ) ? '<tr style="background:#F9F9F9">' : '<tr style="background:#FFFFFF">'; $result .= ' |
|---|
| 320 | <td valign="top" style="font-size:10pt;border-bottom:1px Solid #CCC;font-family:verdana;">'.round($log[$i]['time']).'ms</td> |
|---|
| 321 | <td valign="top" style="font-size:10pt;border-bottom:1px Solid #CCC;font-family:verdana;">'.$log[$i]['type'].'</td> |
|---|
| 322 | <td valign="top" style="font-size:10pt;border-bottom:1px Solid #CCC;font-family:verdana;">'.$log[$i]['message'].'</td> |
|---|
| 323 | <td valign="top" align="center" style="font-size:10pt;border-bottom:1px Solid #CCC;font-family:verdana;">'.$log[$i]['occurrence'].'</td> |
|---|
| 324 | </tr>'; |
|---|
| 325 | } $result .= ' |
|---|
| 326 | </table>'; |
|---|
| 327 | |
|---|
| 328 | if ( isset($GLOBALS['attributes']['fusebox.debug']) && $GLOBALS['attributes']['fusebox.debug'] == 'true' ) echo '</li><li>Ending $'.__CLASS__.'->'.__FUNCTION__.'()</li></ul>'; |
|---|
| 329 | return $result; |
|---|
| 330 | |
|---|
| 331 | } |
|---|
| 332 | |
|---|
| 333 | } |
|---|
| 334 | ?> |
|---|