controllers-blog.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. /**
  3. * @file
  4. * Demo typical entity listing routes with their modifiers.
  5. */
  6. use demo\Controllers\BlogController;
  7. use Silex\Application;
  8. use Silex\ControllerCollection;
  9. $blogCollection = function (Application $app): ControllerCollection {
  10. $MAGIC = 'xyzzy';
  11. // This is a factory service, producing a new instance every time.
  12. $blog = $app['controllers_factory'];
  13. $blog->get('/', BlogController::class . '::index')
  14. ->bind('blog_list');
  15. $blog->get('/{id}', BlogController::class . '::index2')
  16. ->assert('id', $MAGIC)
  17. // Serve '(mount)/xyzzy' when asked for '(mount)'.
  18. ->value('id', $MAGIC)
  19. ->bind('blog_mount');
  20. $blog->get('/json', BlogController::class . '::json');
  21. $blog->get('/json-view', BlogController::class . '::jsonView');
  22. $blog->get('/{id}', BlogController::class . '::fifiAction')
  23. ->assert('id', '\d+')
  24. // See Symfony expression language.
  25. ->when("request.headers.get('User-Agent') matches '/firefox/i'");
  26. $blog->get('/{id}', BlogController::class . '::show')
  27. ->assert('id', '\d+')
  28. // Serve '(mount)/1' when asked for '(mount)/'.
  29. ->value('id', 1)
  30. ->bind('blog_post');
  31. return $blog;
  32. };
  33. return $blogCollection($app);