public function testCacheToFile() { $router = new \Routing\Router($this->host); $fileG = __DIR__ . '/cache/generator.cached.inc.php'; $fileM = __DIR__ . '/cache/routes.cached.inc.php'; if (is_file($fileG)) { unlink($fileG); } if (is_file($fileM)) { unlink($fileM); } $router->useCache($fileM, $fileG); $router->add('blog', '/blog/(page:num:?)', 'app:blog:index'); $router->add('user', '/id(id:num)', 'app:user:index'); $route = $router->match('GET', '/id888'); $this->assertSame('app:user:index', $route != null ? $route->getController() : 'false'); $this->assertSame('/id777', $router->generate('user', array('id' => 777))); $this->assertTrue(is_file($fileG)); $this->assertTrue(is_file($fileM)); $router = new \Routing\Router($this->host); $router->useCache($fileM, $fileG); $route = $router->match('GET', '/id888'); $this->assertSame('app:user:index', $route != null ? $route->getController() : 'false'); $this->assertSame('/id777', $router->generate('user', array('id' => 777))); $this->assertTrue(is_file($fileG)); $this->assertTrue(is_file($fileM)); }
*/ Routing\Router::register('*', '(:all)', function () { return Event::first('404'); }); /* |-------------------------------------------------------------------------- | Route The Incoming Request |-------------------------------------------------------------------------- | | Phew! We can finally route the request to the appropriate route and | execute the route to get the response. This will give an instance | of the Response object that we can send back to the browser | */ $uri = URI::current(); Request::$route = Routing\Router::route(Request::method(), $uri); $response = Request::$route->call(); /* |-------------------------------------------------------------------------- | Persist The Session To Storage |-------------------------------------------------------------------------- | | If a session driver has been configured, we will save the session to | storage so it is avaiable for the next request. This will also set | the session cookie in the cookie jar to be sent to the user. | */ if (Config::get('session.driver') !== '') { Session::save(); } /*
Routing\Filter::register(require $filters); } // -------------------------------------------------------------- // Call the "before" filter for the application and module. // -------------------------------------------------------------- foreach (array('before', ACTIVE_MODULE . '::before') as $filter) { $response = Routing\Filter::call($filter, array(Request::method(), Request::uri()), true); if (!is_null($response)) { break; } } // -------------------------------------------------------------- // Route the request and get the response from the route. // -------------------------------------------------------------- if (is_null($response)) { $route = Routing\Router::make(Request::method(), Request::uri(), new Routing\Loader(ACTIVE_MODULE_PATH))->route(); $response = is_null($route) ? Response::error('404') : $route->call(); } $response = Response::prepare($response); // -------------------------------------------------------------- // Call the "after" filter for the application and module. // -------------------------------------------------------------- foreach (array(ACTIVE_MODULE . '::after', 'after') as $filter) { Routing\Filter::call($filter, array($response, Request::method(), Request::uri())); } // -------------------------------------------------------------- // Stringify the response. // -------------------------------------------------------------- $response->content = (string) $response->content; // -------------------------------------------------------------- // Close the session.
require __DIR__ . "/../vendor/autoload.php"; /* Load services into dependency injection container */ $app = new ServicesContainer(); if (isset($_SERVER['HTTP_DEBUG']) and $_SERVER['HTTP_DEBUG'] === $app->config->debug->debug_key) { ini_set('display_errors', 1); ini_set('html_errors', 1); error_reporting(E_ALL | E_STRICT); header('Debug: Enabled'); } else { $error_handler = new Raven_ErrorHandler($app->sentry); set_error_handler(array($error_handler, 'handleError')); set_exception_handler(array($error_handler, 'handleException')); } /* Define routing and dispatch controllers to build response */ $router = new Routing\Router($app); // Set URL slug patterns $router->setPattern('eventslug', '\\d{4}\\-\\w+'); $router->setPattern('id', '\\d+'); // Cope with Andrew's extreme muppetry $router->route('/2014-sf/register', '/2015-london/register'); // Authentication routes $router->route('/auth/callback', 'AuthCallback'); $router->route('/auth/logout', 'AuthLogout'); $router->route('/auth/email/start-verify', 'PublicSite\\AuthEmailSendCode'); $router->route('/auth/email/verify', 'PublicSite\\AuthEmailVerify'); // Public content routes $router->route('/:eventslug', 'PublicSite\\Info'); $router->route('/:eventslug/(?<page>schedule|faq|hub)', 'PublicSite\\Info'); $router->route('/:eventslug/register', 'PublicSite\\Register'); $router->route('/:eventslug/video', 'PublicSite\\VideoAPI');