/** * Processes the request. */ public static function Magic() { App::$Debug = defined('DEBUG_MODE') ? DEBUG_MODE : false; \Nemiro\Console::Time('Request duration'); if (App::$Debug) { if (isset($_GET) && count($_GET) > 0) { \Nemiro\Console::Info('GET '); foreach ($_GET as $k => $v) { \Nemiro\Console::Info('-- %s = %s', $k, $v); } } if (isset($_POST) && count($_POST) > 0) { \Nemiro\Console::Info('POST '); foreach ($_POST as $k => $v) { \Nemiro\Console::Info('-- %s = %s', $k, $v); } } } App::RaiseEvent('Application_BeginRequest'); try { App::SessionStart(); $pageClass = App::GetScriptName(); if (class_exists($pageClass)) { $page = new $pageClass(); } else { $page = new UI\Page(); //throw new \ErrorException(sprintf('Class %s not found.</span>', $pageClass)); } App::RaiseEvent('Application_PageCreated', $page); $page->Build(); } catch (\Exception $ex) { App::RaiseEvent('Application_Error', $ex); } App::RaiseEvent('Application_EndRequest'); \Nemiro\Console::TimeEnd('Request duration'); # debug info if (App::$Debug) { echo \Nemiro\Console::ToScript(); } }
/** * Optimizes html-code of the page. * * @param \string $value The HTML code to optimization. * * @return \string */ private function Optimization($value) { \Nemiro\Console::Info('HTML Optimization. Input: %s Kb.', round(strlen($value) / 1024, 2)); $value = preg_replace('/\\015\\012|\\015|\\012/', PHP_EOL, $value); $value = $this->CompressScriptAndStyle($value); $value = $this->ClearHTMLComments($value); // \r\n in a textarea $value = preg_replace_callback('#<textarea([^>]*?)>(.*?)</textarea>#si', create_function('$matches', ' $z = str_replace(PHP_EOL, "\\z1310", $matches[2]); return "<textarea".$matches[1].">".$z."</textarea>"; '), $value); // -- $value = preg_replace('/\\s+/', ' ', $value); // spaces $value = preg_replace('/((?<!\\?>)' . PHP_EOL . ')[\\s]+/m', '\\1', $value); $value = preg_replace('/\\t+/', '', $value); // \r\n to textarea $value = str_replace('\\z1310', '\\r\\n', $value); \Nemiro\Console::Info('HTML Optimization is completed. Output: %s Kb.', round(strlen($value) / 1024, 2)); return $value; }
/** * Stops the timer with the specified label and logged the elapsed time. * * @param \string $label The timer label. * * @return \double|\int */ public static function TimeEnd($label) { if (!\Nemiro\App::$Debug) { return 0; } $mtime = microtime(); $mtime = explode(' ', $mtime); $timeEnd = $mtime[1] + $mtime[0]; $ts = \Nemiro\Console::$TimeItems[$label]; $result = $timeEnd - $ts; \Nemiro\Console::Info($label, $result); return $result; }