RoutingFilter.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. /**
  3. * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  4. * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  5. *
  6. * Licensed under The MIT License
  7. * For full copyright and license information, please see the LICENSE.txt
  8. * Redistributions of files must retain the above copyright notice.
  9. *
  10. * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  11. * @link http://cakephp.org CakePHP(tm) Project
  12. * @since 3.0.0
  13. * @license http://www.opensource.org/licenses/mit-license.php MIT License
  14. */
  15. namespace Cake\Routing\Filter;
  16. use Cake\Event\Event;
  17. use Cake\Routing\DispatcherFilter;
  18. use Cake\Routing\Router;
  19. /**
  20. * A dispatcher filter that applies routing rules to the request.
  21. *
  22. * This filter will call Router::parse() when the request has no controller
  23. * parameter defined.
  24. */
  25. class RoutingFilter extends DispatcherFilter {
  26. /**
  27. * Priority setting.
  28. *
  29. * This filter is normally fired last just before the request
  30. * is dispatched.
  31. *
  32. * @var int
  33. */
  34. protected $_priority = 10;
  35. /**
  36. * Applies Routing and additionalParameters to the request to be dispatched.
  37. * If Routes have not been loaded they will be loaded, and app/Config/routes.php will be run.
  38. *
  39. * @param \Cake\Event\Event $event containing the request, response and additional params
  40. * @return void
  41. */
  42. public function beforeDispatch(Event $event) {
  43. $request = $event->data['request'];
  44. Router::setRequestInfo($request);
  45. if (empty($request->params['controller'])) {
  46. $params = Router::parse($request->url);
  47. $request->addParams($params);
  48. }
  49. }
  50. }