private function checkPage($page) { if (!preg_match('/^[a-z0-9-]+$/i', $page)) { throw new NotFoundException('Unsafe page "' . $page . '" requested'); } if (!$this->hasScript($page) && !$this->hasTemplate($page)) { throw new NotFoundException('Page "' . $page . '" not found'); } return $page; } private function hasScript($page) { return file_exists($this->getScript($page)); } private function hasTemplate($page) { return file_exists($this->getTemplate($page)); } private function getScript($page) { return self::PAGE_DIR . $page . '-script.php'; } private function getTemplate($page) { return self::PAGE_DIR . $page . '-view.php'; } } $index = new Index(); $index->init(); $index->run();
header('HTTP/1.1 403 Forbidden'); } elseif ($type == 'error_404') { header('HTTP/1.1 404 Not Found'); } else { header('HTTP/1.1 200 Ok'); } header('Vary: User-Agent', false); header('Content-Type: ' . $content . '; charset=' . Config::get('characterSet')); // Send the cache headers if ($expire !== null && (Config::get('cacheMode') == 'both' || Config::get('cacheMode') == 'browser')) { header('Cache-Control: public, max-age=' . ($expire - time())); header('Expires: ' . gmdate('D, d M Y H:i:s', $expire) . ' GMT'); header('Last-Modified: ' . gmdate('D, d M Y H:i:s', time()) . ' GMT'); header('Pragma: public'); } else { header('Cache-Control: no-cache'); header('Cache-Control: pre-check=0, post-check=0', false); header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); header('Expires: Fri, 06 Jun 1975 15:10:00 GMT'); header('Pragma: no-cache'); } echo $strBuffer; exit; } } /** * Instantiate the controller */ $objIndex = new Index(); $objIndex->run();
ob_start(); // Este es un cambio //require_once 'app/controller/UsersController.php'; require_once 'app/view/IndexView.php'; /** * Description of index * * @author Daniel Fernandez */ class Index { /* * Este es el metodo que ejecuta la aplicación */ public function run($page) { switch ($page) { case 'index': $users = new UsersController(); $users->runIndex(); break; default: $home_view = new HomeView(); $home_view->runIndex(); break; } } } $index = new Index(); $index->run($_GET['view']); ob_end_flush();
//默认配置 /** @constant 要被处理的源代码路径 */ define("CODE_PATH", "./src/obj/"); /** @constant tangram 代码路径 */ define("TANGRAM_PATH", "./src/"); /** @constant Tangram-base 所在目录 */ define("TANGRAM_BASE_DIR", "tangram/"); /** @constant Tangram命名空间 */ define("TANGRAM_NAMESPACE", "baidu"); /** @constant 处理的文件类型 */ define("FILETYPES", ".html,.htm,.js,.tpl"); //处理传进来的参数 $param = isset($argv) ? $argv : $_REQUEST; $paramsHandler = new HandleParams($param); $config = $paramsHandler->run(); //如果用户是通过浏览器访问,则显示web界面。否则为命令行模式 if ($config['type'] == "web") { $uiHandler = new Ui($config); $uiHandler->run(); } if (!empty($config["params"]) || $config['type'] == "commandline") { //解析用户的源代码,提取其中调用Tangram的代码 $parseHandler = new Parse($config); $parseRes = $parseHandler->run(); //分析用户调用的tangram源代码,得到用户需要的tangram模块 $indexHandler = new Index($parseRes, $config); $indexRes = $indexHandler->run(); //将用户用到的tangram模块打包返回给用户 $packHandler = new Pack($indexRes, $config); $packHandler->run(); }
<?php require_once '../config.php'; $page = new Index(); $page->run();