12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- <?php
- namespace demo\Controllers;
- use Silex\Api\ControllerProviderInterface;
- use Silex\Application;
- use Silex\ControllerCollection;
- class BlogControllerProvider implements ControllerProviderInterface {
- const MAGIC = 'xyzzy';
- /**
- * Returns routes to connect to the given application.
- *
- * @param Application $app An Application instance
- *
- * @return ControllerCollection A ControllerCollection instance
- */
- public function connect(Application $app): ControllerCollection {
- // This is a factory service, producing a new instance every time.
- $collection = $app['controllers_factory'];
- $blog = BlogController::class;
- $collection->get('/', "$blog::index")
- ->bind('blog_list');
- $collection->get('/{id}', "$blog::index2")
- ->assert('id', static::MAGIC)
- // Serve '(mount)/xyzzy' when asked for '(mount)'.
- ->value('id', static::MAGIC)
- ->bind('blog_mount');
- $collection->get('/json', "$blog::json");
- $collection->get('/json-view', "$blog::jsonView");
- $collection->get('/{id}', "$blog::fifiAction")
- ->assert('id', '\d+')
- // See Symfony expression language.
- ->when("request.headers.get('User-Agent') matches '/firefox/i'");
- $collection->get('/{id}', "$blog::show")
- ->assert('id', '\d+')
- // Serve '(mount)/1' when asked for '(mount)/'.
- ->value('id', 1)
- ->bind('blog_post');
- return $collection;
- }
- }
|