pipeRoutingMiddleware() public method

Register the routing middleware in the middleware pipeline.
コード例 #1
0
 public static function setUpBeforeClass()
 {
     // Load configuration
     $config = (require __DIR__ . '/../config/config.php');
     // Override config settings
     $config['debug'] = true;
     $config['config_cache_enabled'] = false;
     $dependencies = $config['dependencies'];
     $dependencies['services']['config'] = $config;
     // Build container
     self::$container = new ServiceManager($dependencies);
     // Get application from container
     self::$app = self::$container->get(Application::class);
     self::$app->raiseThrowables();
     // Setup middleware
     self::$app->pipe(ServerUrlMiddleware::class);
     self::$app->pipe(ErrorHandler::class);
     self::$app->pipe(SessionMiddleware::class);
     self::$app->pipeRoutingMiddleware();
     self::$app->pipe(UrlHelperMiddleware::class);
     self::$app->pipeDispatchMiddleware();
     self::$app->pipe(NotFoundHandler::class);
     // Setup routes
     self::$app->route('/', Action\HomePageAction::class, ['GET'], 'home');
     self::$app->route('/blog', Action\BlogIndexAction::class, ['GET'], 'blog');
     self::$app->route('/blog/feed.xml', Action\BlogXmlFeedAction::class, ['GET'], 'feed');
     self::$app->route('/blog/{id:[0-9a-zA-Z\\-]+}', Action\BlogPostAction::class, ['GET'], 'blog.post');
     self::$app->route('/code', Action\CodeAction::class, ['GET'], 'code');
     self::$app->route('/contact', Action\ContactAction::class, ['GET', 'POST'], 'contact');
 }
コード例 #2
0
 /**
  * Inject routes from configuration, if any.
  *
  * @param Application $app
  * @param ContainerInterface $container
  */
 private function injectRoutes(Application $app, ContainerInterface $container)
 {
     $config = $container->has('config') ? $container->get('config') : [];
     if (!isset($config['routes'])) {
         $app->pipeRoutingMiddleware();
         return;
     }
     foreach ($config['routes'] as $spec) {
         if (!isset($spec['path']) || !isset($spec['middleware'])) {
             continue;
         }
         $methods = isset($spec['allowed_methods']) && is_array($spec['allowed_methods']) ? $spec['allowed_methods'] : null;
         $name = isset($spec['name']) ? $spec['name'] : null;
         $route = $app->route($spec['path'], $spec['middleware'], $methods, $name);
         if (isset($spec['options']) && is_array($spec['options'])) {
             $route->setOptions($spec['options']);
         }
     }
 }
コード例 #3
0
 /**
  * Inject routes from configuration, if any.
  *
  * @param Application $app
  * @param ContainerInterface $container
  */
 private function injectRoutes(Application $app, ContainerInterface $container)
 {
     $config = $container->has('config') ? $container->get('config') : [];
     if (!isset($config['routes'])) {
         $app->pipeRoutingMiddleware();
         return;
     }
     foreach ($config['routes'] as $spec) {
         if (!isset($spec['path']) || !isset($spec['middleware'])) {
             continue;
         }
         if (isset($spec['allowed_methods'])) {
             $methods = $spec['allowed_methods'];
             if (!is_array($methods)) {
                 throw new ContainerInvalidArgumentException(sprintf('Allowed HTTP methods for a route must be in form of an array; received "%s"', gettype($methods)));
             }
         } else {
             $methods = Route::HTTP_METHOD_ANY;
         }
         $name = isset($spec['name']) ? $spec['name'] : null;
         $route = new Route($spec['path'], $spec['middleware'], $methods, $name);
         if (isset($spec['options'])) {
             $options = $spec['options'];
             if (!is_array($options)) {
                 throw new ContainerInvalidArgumentException(sprintf('Route options must be an array; received "%s"', gettype($options)));
             }
             $route->setOptions($options);
         }
         $app->route($route);
     }
 }
コード例 #4
0
 public function __invoke(Application $app)
 {
     $app->pipeRoutingMiddleware();
     $app->pipeDispatchMiddleware();
 }