sfPathInfoRouting.class.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. /*
  3. * This file is part of the symfony package.
  4. * (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com>
  5. *
  6. * For the full copyright and license information, please view the LICENSE
  7. * file that was distributed with this source code.
  8. */
  9. /**
  10. * sfPathInfoRouting class is a very simple routing class that uses PATH_INFO.
  11. *
  12. * @package symfony
  13. * @subpackage routing
  14. * @author Fabien Potencier <fabien.potencier@symfony-project.com>
  15. * @version SVN: $Id: sfPathInfoRouting.class.php 7779 2008-03-08 18:08:36Z fabien $
  16. */
  17. class sfPathInfoRouting extends sfRouting
  18. {
  19. protected
  20. $currentRouteParameters = array();
  21. /**
  22. * @see sfRouting
  23. */
  24. public function getCurrentInternalUri($with_route_name = false)
  25. {
  26. $parameters = $this->currentRouteParameters;
  27. // other parameters
  28. unset($parameters['module'], $parameters['action']);
  29. ksort($parameters);
  30. $parameters = count($parameters) ? '?'.http_build_query($parameters, null, '&') : '';
  31. return sprintf('%s/%s%s', $this->currentRouteParameters['module'], $this->currentRouteParameters['action'], $parameters);
  32. }
  33. /**
  34. * @see sfRouting
  35. */
  36. public function generate($name, $params = array(), $querydiv = '/', $divider = '/', $equals = '/')
  37. {
  38. $url = '';
  39. foreach ($this->mergeArrays($this->defaultParameters, $params) as $key => $value)
  40. {
  41. $url .= '/'.$key.'/'.$value;
  42. }
  43. return $url ? $url : '/';
  44. }
  45. /**
  46. * @see sfRouting
  47. */
  48. public function parse($url)
  49. {
  50. $this->currentRouteParameters = $this->defaultParameters;
  51. $array = explode('/', trim($url, '/'));
  52. $count = count($array);
  53. for ($i = 0; $i < $count; $i++)
  54. {
  55. // see if there's a value associated with this parameter, if not we're done with path data
  56. if ($count > ($i + 1))
  57. {
  58. $this->currentRouteParameters[$array[$i]] = $array[++$i];
  59. }
  60. }
  61. $this->currentRouteParameters = $this->fixDefaults($this->currentRouteParameters);
  62. return $this->currentRouteParameters;
  63. }
  64. /**
  65. * @see sfRouting
  66. */
  67. public function getRoutes()
  68. {
  69. return array();
  70. }
  71. /**
  72. * @see sfRouting
  73. */
  74. public function setRoutes($routes)
  75. {
  76. return array();
  77. }
  78. /**
  79. * @see sfRouting
  80. */
  81. public function hasRoutes()
  82. {
  83. return false;
  84. }
  85. /**
  86. * @see sfRouting
  87. */
  88. public function clearRoutes()
  89. {
  90. }
  91. }