1. sfRequestRoute.class.php
  2. /** * sfRequestRoute represents a route that is request aware. * * It implements the sf_method requirement. * * @package symfony * @subpackage routing * @author Fabien Potencier * @version SVN: $Id: sfRequestRoute.class.php 20784 2009-08-04 20:53:57Z Kris.Wallsmith $ */
  3. class sfRequestRoute extends sfRoute
  4. {
  5. /**
  6. * Constructor.
  7. *
  8. * Applies a default sf_method requirements of GET or HEAD.
  9. *
  10. * @see sfRoute
  11. */
  12. public function __construct($pattern, $defaults = array(), $requirements = array(), $options = array())
  13. {
  14. if (!isset($requirements['sf_method']))
  15. {
  16. $requirements['sf_method'] = array('get', 'head');
  17. }
  18. else
  19. {
  20. $requirements['sf_method'] = array_map('strtolower', (array) $requirements['sf_method']);
  21. }
  22. parent::__construct($pattern, $defaults, $requirements, $options);
  23. }
  24. /**
  25. * Returns true if the URL matches this route, false otherwise.
  26. *
  27. * @param string $url The URL
  28. * @param array $context The context
  29. *
  30. * @return array An array of parameters
  31. */
  32. public function matchesUrl($url, $context = array())
  33. {
  34. if (false === $parameters = parent::matchesUrl($url, $context))
  35. {
  36. return false;
  37. }
  38. // enforce the sf_method requirement
  39. if (in_array(strtolower($context['method']), $this->requirements['sf_method']))
  40. {
  41. return $parameters;
  42. }
  43. return false;
  44. }
  45. /**
  46. * Returns true if the parameters match this route, false otherwise.
  47. *
  48. * @param mixed $params The parameters
  49. * @param array $context The context
  50. *
  51. * @return Boolean true if the parameters match this route, false otherwise.
  52. */
  53. public function matchesParameters($params, $context = array())
  54. {
  55. if (isset($params['sf_method']))
  56. {
  57. // enforce the sf_method requirement
  58. if (!in_array(strtolower($params['sf_method']), $this->requirements['sf_method']))
  59. {
  60. return false;
  61. }
  62. unset($params['sf_method']);
  63. }
  64. return parent::matchesParameters($params, $context);
  65. }
  66. /**
  67. * Generates a URL from the given parameters.
  68. *
  69. * @param mixed $params The parameter values
  70. * @param array $context The context
  71. * @param Boolean $absolute Whether to generate an absolute URL
  72. *
  73. * @return string The generated URL
  74. */
  75. public function generate($params, $context = array(), $absolute = false)
  76. {
  77. unset($params['sf_method']);
  78. return parent::generate($params, $context, $absolute);
  79. }
  80. }

Debug toolbar