public function run() { ob_start(); $request = $this->container['request']; $response = $this->container['response']; // Call before handlers if ($this->runHandlers('before', $this->container)) { $response->prepare()->send(); $this->end(); return; } // Route & execute try { $match = Router::run(Request::method(), Request::host(), Request::path()); $routeResult = $match->execute($this->container); $routeResult->render($this->container); } catch (PageNotFoundException $e) { // 404 $response->setResponseCode($e->getCode()); $this->runHandlers('missing', $this->container); } catch (HttpException $e) { // 500 $response->setResponseCode($e->getCode()); $this->runHandlers('error', $this->container); } // Call after handlers $this->runHandlers('after', $this->container); // Send our response down! $response->prepare()->send(); $this->end(); ob_end_flush(); }
public function execute(InputInterface $input, OutputInterface $output) { foreach (Router::routes() as $route) { if ($route != null) { $output->writeln(strtolower(str_pad(str_replace('|HEAD', '', $route->method()), 9)) . "\t" . str_pad($route->path(), 40) . "\t" . (is_callable($route->action()) ? '{closure}' : $route->action())); } } }
public static function getRouteUrl($routeName, $params = array()) { $route = Router::findRoute($routeName); if (!is_null($route)) { $path = $route->path(); foreach ($params as $key => $value) { $path = str_replace('{' . $key . '}', $value, $path); } $path = preg_replace('/{[^}]+\\?}/', '', $path); $path = str_replace('//', '/', $path); return $path; } else { throw new ArgumentException("Route alias not found. Can't redirect to " . $routeName); } }
public function testBeforeAndAfterFilterOrder() { $stack = array(); $this->app->before(function () use(&$stack) { $stack[] = 'before'; }); $this->app->after(function () use(&$stack) { $stack[] = 'after'; }); Router::get('/', function () use(&$stack) { $stack[] = 'route'; return 'Hello'; }); $this->app->run(); $this->assertEquals(array('before', 'route', 'after'), $stack); }
public function register() { $route = Router::get($this->mountPath . '/{asset}', function ($asset) { return $this->render($asset); }); $route->where('asset', '.+\\..+'); return $this; }