action.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. /**
  3. * Lithium: the most rad php framework
  4. *
  5. * @copyright Copyright 2010, Union of RAD (http://union-of-rad.org)
  6. * @license http://opensource.org/licenses/bsd-license.php The BSD License
  7. */
  8. /**
  9. * This file contains a series of method filters that allow you to intercept different parts of
  10. * Lithium's dispatch cycle. The filters below are used for on-demand loading of routing
  11. * configuration, and automatically configuring the correct environment in which the application
  12. * runs.
  13. *
  14. * For more information on in the filters system, see `lithium\util\collection\Filters`.
  15. *
  16. * @see lithium\util\collection\Filters
  17. */
  18. use lithium\core\Libraries;
  19. use lithium\net\http\Router;
  20. use lithium\core\Environment;
  21. use lithium\action\Dispatcher;
  22. /**
  23. * This filter intercepts the `run()` method of the `Dispatcher`, and first passes the `'request'`
  24. * parameter (an instance of the `Request` object) to the `Environment` class to detect which
  25. * environment the application is running in. Then, loads all application routes in all plugins,
  26. * loading the default application routes last.
  27. *
  28. * Change this code if plugin routes must be loaded in a specific order (i.e. not the same order as
  29. * the plugins are added in your bootstrap configuration), or if application routes must be loaded
  30. * first (in which case the default catch-all routes should be removed).
  31. *
  32. * If `Dispatcher::run()` is called multiple times in the course of a single request, change the
  33. * `include`s to `include_once`.
  34. *
  35. * @see lithium\action\Request
  36. * @see lithium\core\Environment
  37. * @see lithium\net\http\Router
  38. */
  39. Dispatcher::applyFilter('run', function($self, $params, $chain) {
  40. Environment::set($params['request']);
  41. foreach (array_reverse(Libraries::get()) as $name => $config) {
  42. if ($name === 'lithium') {
  43. continue;
  44. }
  45. $file = "{$config['path']}/config/routes.php";
  46. file_exists($file) ? include $file : null;
  47. }
  48. return $chain->next($self, $params, $chain);
  49. });
  50. ?>