1234567891011121314151617181920212223242526272829303132333435363738394041 |
- <?php
- /**
- * @file
- * Demo typical entity listing routes with their modifiers.
- */
- use demo\Controllers\BlogController;
- use Silex\Application;
- use Silex\ControllerCollection;
- $blogCollection = function (Application $app): ControllerCollection {
- $MAGIC = 'xyzzy';
- // This is a factory service, producing a new instance every time.
- $blog = $app['controllers_factory'];
- $blog->get('/', BlogController::class . '::index')
- ->bind('blog_list');
- $blog->get('/{id}', BlogController::class . '::index2')
- ->assert('id', $MAGIC)
- // Serve '(mount)/xyzzy' when asked for '(mount)'.
- ->value('id', $MAGIC)
- ->bind('blog_mount');
- $blog->get('/json', BlogController::class . '::json');
- $blog->get('/json-view', BlogController::class . '::jsonView');
- $blog->get('/{id}', BlogController::class . '::fifiAction')
- ->assert('id', '\d+')
- // See Symfony expression language.
- ->when("request.headers.get('User-Agent') matches '/firefox/i'");
- $blog->get('/{id}', BlogController::class . '::show')
- ->assert('id', '\d+')
- // Serve '(mount)/1' when asked for '(mount)/'.
- ->value('id', 1)
- ->bind('blog_post');
- return $blog;
- };
- return $blogCollection($app);
|