sfPathInfoRouting.class.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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 11313 2008-09-03 17:28:33Z 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(), $absolute = false)
  37. {
  38. $parameters = $this->mergeArrays($this->defaultParameters, $params);
  39. if ($this->getDefaultParameter('module') == $parameters['module'])
  40. {
  41. unset($parameters['module']);
  42. }
  43. if ($this->getDefaultParameter('action') == $parameters['action'])
  44. {
  45. unset($parameters['action']);
  46. }
  47. $url = '';
  48. foreach ($parameters as $key => $value)
  49. {
  50. $url .= '/'.$key.'/'.$value;
  51. }
  52. return $this->fixGeneratedUrl($url ? $url : '/', $absolute);
  53. }
  54. /**
  55. * @see sfRouting
  56. */
  57. public function parse($url)
  58. {
  59. $this->currentRouteParameters = $this->defaultParameters;
  60. $array = explode('/', trim($url, '/'));
  61. $count = count($array);
  62. for ($i = 0; $i < $count; $i++)
  63. {
  64. // see if there's a value associated with this parameter, if not we're done with path data
  65. if ($count > ($i + 1))
  66. {
  67. $this->currentRouteParameters[$array[$i]] = $array[++$i];
  68. }
  69. }
  70. return $this->currentRouteParameters;
  71. }
  72. /**
  73. * @see sfRouting
  74. */
  75. public function getRoutes()
  76. {
  77. return array();
  78. }
  79. /**
  80. * @see sfRouting
  81. */
  82. public function setRoutes($routes)
  83. {
  84. return array();
  85. }
  86. /**
  87. * @see sfRouting
  88. */
  89. public function hasRoutes()
  90. {
  91. return false;
  92. }
  93. /**
  94. * @see sfRouting
  95. */
  96. public function clearRoutes()
  97. {
  98. }
  99. }