before('mwBeforeAll:next', $priority = 0); // Callable service example. // "After": triggered on KernelEvents::RESPONSE. $app->after('mwAfterAll'); // Plain callable example. // "Finish": triggered on KernelEvents::TERMINATE. $app->finish([Finish::class, 'handle']); // ---- Routing ---------------------------------------------------------------- // Demo Twig. $app->get('/', HomeController::class . '::home') ->bind('homepage'); // Demo redirects and forwards. $app->get('/home', DelegatingController::class . '::redirectPath'); $app->get('/blogz', DelegatingController::class . '::forwardPath'); $app->get('/all_blogs', DelegatingController::class . '::forwardName'); // Demo typical entity listing routes with their modifiers. $app->get('/blogs', BlogController::class . '::index') ->bind('blog_list'); $app->get('/blogs-json', BlogController::class . '::json'); $app->get('/blogs-json-view', BlogController::class . '::jsonView'); $app->get('/blog/{id}', BlogController::class . '::fifiAction') ->assert('id', '\d+') ->when("request.headers.get('User-Agent') matches '/firefox/i'"); $app->get('/blog/{id}', BlogController::class . '::show') ->assert('id', '\d+') ->value('id', 1) ->bind('blog_post'); // Demo POST request handling. $app->post('/feedback', FeedbackController::class . '::feedbackAction'); // Demo escaping HTML and JSON $app->get('/hello/{name}', EscapeController::class . '::html'); $app->get('/hello-json/{name}', EscapeController::class . '::json'); // Demo streaming. $app->get('/noise', StreamController::class . '::customStream'); $app->get('/pass', StreamController::class . '::fileStream'); // Demo error handling. $app->get('err/http', ErrorController::class . '::errorHttp'); $app->get('err/base', ErrorController::class . '::errorBase'); // Demo param converters. $app->get('/user/{user}', UserController::class . '::itemAction') ->convert('user', 'converter.user:convert'); /* ---- View handlers ---------------------------------------------------------- View handlers can also receive Request $request as 2nd arg e.g. for basic content negotiation. But the callback_resolver service: - can not receive $app - unlike the controller_resolver, can only use standard callables/services - unlike the exception listener, can not use _invoke-able class names. So one way to get the app is to use it as a global (!). They are triggered on KernelEvents::VIEW. */ $app->view([JsonView::class, 'handle']); /* ---- Exception handlers ----------------------------------------------------- Handlers are examined in order, and called in a chain with the result of the previous one. The last one must return a string or Response. They are triggered on KernelEvents::EXCEPTION. */ $app->error([HttpErrorHandler::class, 'handle']); // Handlers do not receive $app, so they have to be closures or instantiated // here if they need it (or use the global $app like view handlers. $app->error(new GenericErrorHandler($app));