function testBindSysEvent() { $this->title('System Bind and Trigger'); $callback = array($this, 'callback'); Raxan::bindSysEvent('test_event', $callback); Raxan::triggerSysEvent('test_event'); $this->compare($this->msgFromCallback, 'done', 'Callback Object'); Raxan::bindSysEvent('test_event2', 'regular_callback_function'); Raxan::triggerSysEvent('test_event2'); $this->compare($GLOBALS['msgFromCallback'], 'done', 'Callback Function'); }
/** * Creates an instance of a page class * @param string $page The name of a RaxanWebPage sub-class * @param string $content */ function raxan_auto_create($page, $content = null) { // initialize page class if ($page) { try { if (!$content) { $content = ''; } $type = substr($content, 0, 5) == '<?xml' ? 'xml' : null; $o = new $page($content, null, $type); $o->reply(); } catch (Exception $e) { // raise system error event $rt = Raxan::triggerSysEvent('system_error', $e); if (!$rt) { $err = $e->getMessage() . ' Line ' . $e->getLine() . ' in ' . $e->getFile() . "\n" . $e->getTraceAsString() . "\n"; if (ini_get('display_errors') == 1) { echo "Uncaught Error: " . nl2br($err); } Raxan::log($err, 'ERROR', 'Uncaught Error'); } } } }
/** * Sends data to client * @param string $responseType Accepted values: html, xhtml, xhtml/html, xml, wml * @return RaxanWebPage */ public function reply($responseType = null) { $this->isReplying = true; $rt = $responseType; if ($rt === null) { $rt = $this->responseType; } else { $this->responseType = $rt; } if ($rt == 'xhtml/html') { $rt = isset($_SERVER['HTTP_ACCEPT']) && strpos($_SERVER['HTTP_ACCEPT'], "application/xhtml+xml") ? 'xhtml' : 'html'; } switch ($rt) { case 'wml': case 'xml': case 'xhtml': $content = $this->render('xml'); $ctype = 'text/xml'; if ($rt == 'wml') { $ctype = 'text/vnd.wap.wml'; } else { if ($rt == 'xhtml') { $ctype = 'application/xhtml+xml'; $content = preg_replace('/ |
/', '', $content); } } if (!$this->_contentType) { $this->contentType($ctype); } break; default: //html $content = $this->render('html'); if (!$this->_contentType) { $this->contentType($this->isEmbedded ? 'text/javascript' : 'text/html'); } if ($rt == 'html') { // change existing doctype to HTML5 Doctype $content = preg_replace('/<!DOCTYPE[^>]*>/si', "<!DOCTYPE html >", $content, 1); } break; } // send headers header($this->_contentType); if ($this->preventBrowserCache) { header("Expires: Mon, 1 Jan 1990 11:59:00 GMT"); header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); header("Cache-Control: no-cache, must-revalidate"); header("Cache-Control: post-check=0, pre-check=0", false); header("Pragma: no-cache"); } if ($this->_headers) { foreach ($this->_headers as $s) { @header($s); } } // send content to client (eg. html, xml, json, etc) echo $content; if (Raxan::$isDebug) { Raxan::debug('Page _reply()'); } if (!$this->_endResponse) { $this->_reply(); // call _reply event Raxan::triggerSysEvent('page_reply', $this); } // show render time and memory usage if ($this->showRenderTime && !$this->isAjaxRequest) { $time = Raxan::stopTimer($this->_startTime); $mem = function_exists('memory_get_usage') ? memory_get_usage() / 1048576 : null; echo '<div style="position:fixed; left:0; bottom:0;width:100%; margin-top:5px; padding:5px 10px;' . 'border-top:1px solid #eee; background:#fff; color:#000; opacity:0.85;z-index:1000;" align="left">' . 'Render time: ' . number_format($time, 5) . ' secs.' . ($mem ? ' Memory usage: ' . number_format($mem, 2) . ' MB.' : '') . '</div>'; } return $this; }