/** * Spiral will automatically populate requested method injections for boot method. * * @param HttpDispatcher $http */ public function boot(HttpDispatcher $http) { //Register route in a default http router (you can change router using setRouter() method) $http->addRoute($this->sampleRole()); //Default route used as "fallback" when no other route work $http->defaultRoute($this->defaultRoute()); }
/** * @param ContainerInterface $container * @param HttpDispatcher $dispatcher */ public function __construct(ContainerInterface $container, HttpDispatcher $dispatcher) { //Yes, by default we are using configuration of parent HttpDispatcher (i probably need a //method for that). $this->config = $dispatcher->config()['cookies']; $this->container = $container; }
/** * @param HttpDispatcher $dispatcher */ public function boot(HttpDispatcher $dispatcher) { $dispatcher->riseMiddleware(function (Request $request, Response $response, $next) { $start = microtime(true); /** * @var Response $response */ $response = $next($request, $response); return $response->withHeader('X-Elapsed', number_format(microtime(true) - $start, 4)); }); }
/** * @param HttpDispatcher $dispatcher * @param FactoryInterface $factory */ public function boot(HttpDispatcher $dispatcher, FactoryInterface $factory) { $dispatcher->riseMiddleware($factory->make(ProfilerWrapper::class, ['started' => microtime(true)])); }
/** * @param HttpDispatcher $http * @param Vault $vault */ public function boot(HttpDispatcher $http, Vault $vault) { $http->addRoute($vault->route()); }