/** * 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; }
public static function ToScript() { if (!\Nemiro\App::$Debug) { return ''; } $log = '<script type="text/javascript">'; for ($i = 0; $i < count(\Nemiro\Console::$LogItems); $i++) { $item = \Nemiro\Console::$LogItems[$i]; $log .= 'console.' . $item[0] . '('; if (isset($item[1])) { $log .= '"' . \Nemiro\Console::GetNormalizedMessage($item[1]) . '"'; } if (isset($item[2])) { $item[3] = array_merge(array($item[2]), $item[3]); $jc = count($item[3]); for ($j = 0; $j < $jc; $j++) { if ($j != $jc) { $log .= ', '; } if (gettype($item[3][$j]) == 'array' || gettype($item[3][$j]) == 'object') { $log .= '"' . \Nemiro\Console::GetNormalizedMessage(var_dump($item[3][$j])) . '"'; } else { $log .= '"' . \Nemiro\Console::GetNormalizedMessage($item[3][$j]) . '"'; } } } $log .= ');' . "\n"; } $log .= '</script>'; return $log; }