<?php // Twig require_once './vendor/twig/twig/lib/Twig/Autoloader.php'; Twig_Autoloader::register(); // Autoloader spl_autoload_register(function ($class) { $root = '.'; // root is current file $class_file = str_replace('\\', '/', $class); $file = "{$root}/{$class_file}.php"; if (is_readable($file)) { require $file; } }); // Error and Exception Handling error_reporting(E_ALL); set_error_handler('Core\\Error::errorHandler'); set_exception_handler('Core\\Error::exceptionHandler'); /** * Routing */ $router = new Core\Router(); $router->add('', ['controller' => 'Home', 'action' => 'index']); $router->add('authenticate', ['controller' => 'Authenticate', 'action' => 'index']); $router->add('diary', ['controller' => 'Diary', 'action' => 'index']); $router->add('{controller}/{action}'); $router->add('admin/{controller}/{action}', ['namespace' => 'Admin']); $router->dispatch($_SERVER['QUERY_STRING']);
/** * KK-Framework * Author: kookxiang <*****@*****.**> */ // Initialize constants define('ROOT_PATH', dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR); define('LIBRARY_PATH', ROOT_PATH . 'Library/'); define('DATA_PATH', ROOT_PATH . 'Data/'); define('TIMESTAMP', time()); @ini_set('display_errors', 'on'); @ini_set('expose_php', false); @date_default_timezone_set('Asia/Shanghai'); @ini_set('date.timezone', 'Asia/Shanghai'); // Register composer require ROOT_PATH . 'Package/autoload.php'; // Register error handler Core\Error::registerHandler(); // Initialize config @(include DATA_PATH . 'Config.php'); if (ini_get('opcache.enable')) { if (!ini_get('opcache.save_comments')) { throw new \Core\Error('ZendOpcache is configured not saving PHP DocComments which is required.'); } } // Handler for user power Core\Filter::register(new Helper\LoginFilter()); // Handler for json request Core\Filter::register(new Helper\JSON()); $defaultRouter = new Core\Router(); $defaultRouter->handleRequest();
/** * Adding a route that has already been defined. * * @access public * @expectedException InvalidArgumentException */ public function testAddingExistingRoute() { // Create router $router = new Core\Router(); // Create two routes called the same $router->addRoute('Foo'); $router->addRoute('Foo'); }
<?php $router = Core\Router::getInstance(); $router->get('/', 'App\\Controllers\\GameController@index'); $router->get('newGame', 'App\\Controllers\\GameController@newGame'); $router->get('gameData', 'App\\Controllers\\GameController@gameData'); $router->post('shot', 'App\\Controllers\\GameController@shot');
<?php /** * Index page * * Loads the libraries and calls the router to handle the request * * @package Core */ /* Autoload libraries */ require_once 'vendor/autoload.php'; /* Dispatch the request */ Core\Router::dispatch();
<?php /** * Composer autoloader * */ require_once '../vendor/autoload.php'; /** * Error and Exception handling * */ error_reporting(E_ALL); set_error_handler('Core\\Error::errorHandler'); set_exception_handler('Core\\Error::exceptionHandler'); if (session_status() == PHP_SESSION_NONE) { session_start(); } $router = new \Core\Router(); /** * Add the Route * */ $router->add('', ['controller' => 'HomeController', 'action' => 'index']); $router->add('home', ['controller' => 'HomeController', 'action' => 'index']); $router->add('home/fileupload', ['controller' => 'HomeController', 'action' => 'fileUpload']); $router->add('contact', ['controller' => 'ContactController', 'action' => 'index']); $router->add('admin/users/{id:\\d+}/index', ['controller' => 'UsersController', 'action' => 'index', 'namespace' => 'Admin']); //$router->add('{controller}/{id:\d+}/{action}'); $url = $_SERVER['QUERY_STRING']; $router->dispatch($url);
<?php //if(str_replace('www.',null,$_SERVER['HTTP_HOST']) == 'jonathan-sharp.co.uk') // die("Coming soon!"); /** * Das index, ja? */ require 'core_path.php'; require CORE_PATH . '/core.php'; import('core.routing'); $router = new \Core\Router(); $router->route($_GET['route']);
<?php $url = (string) @$_GET['URL']; if (!$url || $url[0] != '/') { $url = "/{$url}"; } try { require_once dirname(__FILE__) . '/php/init.php'; $router = new Core\Router(config()->routes); print $router->route($url); } catch (Exception $e) { print file_get_contents(dirname(__FILE__) . '/php/App/Shared/View/500.html'); if (DEBUG) { print '<p>' . $e->getMessage() . '</p>' . error_log((string) $e, E_USER_ERROR); } }
<?php if (extension_loaded('xhprof')) { include_once '/usr/share/php/xhprof_lib/utils/xhprof_lib.php'; include_once '/usr/share/php/xhprof_lib/utils/xhprof_runs.php'; xhprof_enable(XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY); } require_once 'core_path.php'; require_once CORE_PATH . '/core.php'; define('DATETIME_FORMAT', "Ymd.Hi"); define('DATE_FORMAT', "l j<\\s\\u\\p>S</\\s\\u\\p> F 'y"); import('core.routing'); $router = new \Core\Router(); $router->route(URI); if (extension_loaded('xhprof')) { $profiler_namespace = 'core'; // namespace for your application $xhprof_data = xhprof_disable(); $xhprof_runs = new XHProfRuns_Default(); $run_id = $xhprof_runs->save_run($xhprof_data, $profiler_namespace); // url to the XHProf UI libraries (change the host name and path) $profiler_url = sprintf('http://trouble.0xf.nl/xhprof/xhprof_html/index.php?run=%s&source=%s', $run_id, $profiler_namespace); echo '<a href="' . $profiler_url . '" target="_blank">Profiler output</a>'; }
<?php session_start(); define("ROOT_DIR", __DIR__); include "autoload.php"; include "vendor/autoload.php"; include "src/Core/Exceptions.php"; $router = new \Core\Router(); $router->route(); $app = new \Core\Application(); $app->run($router->getController(), $router->getAction());
<?php namespace Application; error_reporting(E_ALL); ini_set('display_errors', 'On'); define('ROOT_URL', substr($_SERVER['PHP_SELF'], 0, -(strlen($_SERVER['SCRIPT_FILENAME']) - strlen(dirname(__FILE__))))); require_once "Autoloader.php"; require_once 'config.php'; $router = new Core\Router(); $router->run();
*/ define('ROOT_PATH', realpath(dirname(__FILE__)) . DIRECTORY_SEPARATOR); //项目根目录 require_once 'config/init.conf.php'; require_once CORE_PATH . 'Loader.php'; //捕获错误信息 function getLastErr() { $errInfo = error_get_last(); if (null != $errInfo) { $fileName = ROOT_PATH . 'logs' . DIRECTORY_SEPARATOR . 'error.log'; $errStr = date('Y-m-d H:i:s'); foreach ($errInfo as $key => $value) { $errStr .= $key . '=' . $value . ','; } file_put_contents($fileName, $errStr, FILE_APPEND); } } register_shutdown_function('getLastErr'); registerAutoLoad(); try { $routerObj = new Core\Router(); $routerObj->dispatch(); } catch (Exception $exc) { $logObj = new Core\Log(EXCEPTION_LOG_FILE, false, EXCEPTION_LOG_PATH); $logObj->exceptionLog(array('code' => $exc->getCode(), 'msg' => $exc->getMessage(), 'file' => $exc->getFile(), 'trace' => $exc->getTraceAsString())); $logObj->closeFile(); if ('dev' == ENV) { Core\CommonFunction::show_exception($exc); } }
/** * Route, and pass to the Dispatcher to run our controller/action. * * @access private */ private function route() { $this->_router->route(); }
<?php require __DIR__ . '/check_setup.php'; require __DIR__ . '/common.php'; require __DIR__ . '/core/router.php'; $router = new Core\Router($registry); $router->execute();
<?php /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ require 'config.php'; if (isset($_SERVER['REQUEST_URI']) && strpos($_SERVER['REQUEST_URI'], Config::$base) !== 0) { http_response_code(404) && exit; } if (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] !== 'on') { http_response_code(500) && exit; } header('Strict-Transport-Security: max-age=86400'); spl_autoload_register(); Core\Session::start(); Core\CSRF::handle(); Core\Router::getURI(); date_default_timezone_set('UTC'); Core\DB::connect(); define('BASEPATH', __DIR__ . '/'); Core\Router::controller('open'); if (!\Core\Session::authenticated()) { header('Location: ' . Config::$base . 'auth/login') || exit; } Core\Router::controller(); http_response_code(404) && exit;