示例#1
0
 function testStopTimer()
 {
     sleep(1);
     $time = Raxan::stopTimer($this->_varTimer);
     $this->compare(round($time), 1.0, 'Stop Timer after 1 second');
 }
示例#2
0
 /**
  * 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;
 }