Example #1
0
 /**
  * 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());
 }
Example #2
0
 /**
  * @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;
 }
Example #3
0
 /**
  * @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));
     });
 }
Example #4
0
 /**
  * @param HttpDispatcher   $dispatcher
  * @param FactoryInterface $factory
  */
 public function boot(HttpDispatcher $dispatcher, FactoryInterface $factory)
 {
     $dispatcher->riseMiddleware($factory->make(ProfilerWrapper::class, ['started' => microtime(true)]));
 }
Example #5
0
 /**
  * @param HttpDispatcher $http
  * @param Vault          $vault
  */
 public function boot(HttpDispatcher $http, Vault $vault)
 {
     $http->addRoute($vault->route());
 }