protected function getView() { static $view; if (!isset($view)) { plugin::call('view_start'); //实例化view $view = new View(); //初始化模版 $view->getTheme(); } return $view; }
protected function checkCompile() { $tplfile = ltrim(str_replace(array(PT_ROOT, '/application/', '/template/'), '/', $this->tplFile), '/'); $compiledFile = CACHE_PATH . '/template/' . substr(str_replace('/', ',', $tplfile), 0, -5) . '.php'; $compile = true; if (APP_MODE == 'sae') { $timekey = md5($compiledFile . '_time'); $compiledFile = 'saekv://' . md5($compiledFile); if (!APP_DEBUG && Cache::get($timekey) > filemtime($this->tplFile)) { $compile = false; } } else { if (!APP_DEBUG && is_file($compiledFile) && filemtime($compiledFile) > filemtime($this->tplFile)) { $compile = false; } } if ($compile) { $content = file_get_contents($this->tplFile); plugin::call('template_compile_start', $content); $content = $this->compile($content); if (!APP_DEBUG) { $content = preg_replace_callback('/<style[^>]*>([^<]*)<\\/style>/isU', array('self', 'compressCss'), $content); $content = preg_replace_callback('/<script[^>]*>([^<]+?)<\\/script>/isU', array('self', 'compressJs'), $content); $content = preg_replace(array("/>\\s+</"), array('> <'), $content); $content = preg_replace('/\\?>\\s*<\\?php/', '', $content); $content = str_replace(array("\r\n", "\r", "\n", "\t", ' ', ' '), ' ', $content); $content = strip_whitespace($content); } //判断是否开启layout if (C('LAYOUT', null, false)) { $includeFile = $this->getTplFile(C('LAYOUT_NAME', null, 'layout')); $truereturn = realpath($includeFile); if ($truereturn) { $layout = $this->compile(file_get_contents($truereturn)); $content = str_replace('__CONTENT__', $content, $layout); } else { halt("无法找到对应的layout模版:{$truereturn}"); } } $content = '<?php defined(\'PT_ROOT\') || exit(\'Permission denied\');?>' . $this->replace($content); if (APP_MODE == 'sae') { Cache::set($timekey, NOW_TIME); } plugin::call('template_compile_end', $content); F($compiledFile, $content); } return $compiledFile; }
protected static function app() { plugin::call('controller_start'); $controllerFile = APP_PATH . '/' . MODULE_NAME . '/controller/' . CONTROLLER_NAME . '.php'; if (is_file($controllerFile)) { include $controllerFile; $classname = CONTROLLER_NAME . 'Controller'; $actionname = ACTION_NAME . 'Action'; if (class_exists($classname, false)) { $app = new $classname(); //加载init方法 if (method_exists($app, 'init')) { $app->init(); } // 加载action if (method_exists($app, $actionname)) { $app->{$actionname}(); plugin::call('controller_end'); } else { halt('控制器' . CONTROLLER_NAME . '对应的文件中未找到方法' . $actionname, __FILE__, __LINE__ - 3); } } else { halt('控制器' . CONTROLLER_NAME . '对应的文件中未找到类' . $classname, __FILE__, __LINE__ - 13); } } else { halt('找不到' . MODULE_NAME . '模块下的控制器' . CONTROLLER_NAME . ' 文件不存在:' . $controllerFile, __FILE__, __LINE__ - 20); } }