url_matcher2.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <?php
  2. use Symfony\Component\Routing\Exception\MethodNotAllowedException;
  3. use Symfony\Component\Routing\Exception\ResourceNotFoundException;
  4. use Symfony\Component\Routing\RequestContext;
  5. /**
  6. * ProjectUrlMatcher
  7. *
  8. * This class has been auto-generated
  9. * by the Symfony Routing Component.
  10. */
  11. class ProjectUrlMatcher extends Symfony\Tests\Component\Routing\Fixtures\RedirectableUrlMatcher
  12. {
  13. /**
  14. * Constructor.
  15. */
  16. public function __construct(RequestContext $context)
  17. {
  18. $this->context = $context;
  19. }
  20. public function match($pathinfo)
  21. {
  22. $allow = array();
  23. // foo
  24. if (0 === strpos($pathinfo, '/foo') && preg_match('#^/foo/(?P<bar>baz|symfony)$#x', $pathinfo, $matches)) {
  25. return array_merge($this->mergeDefaults($matches, array ( 'def' => 'test',)), array('_route' => 'foo'));
  26. }
  27. // bar
  28. if (0 === strpos($pathinfo, '/bar') && preg_match('#^/bar/(?P<foo>[^/]+?)$#x', $pathinfo, $matches)) {
  29. if (!in_array($this->context->getMethod(), array('get', 'head'))) {
  30. $allow = array_merge($allow, array('get', 'head'));
  31. goto not_bar;
  32. }
  33. $matches['_route'] = 'bar';
  34. return $matches;
  35. }
  36. not_bar:
  37. // baz
  38. if ($pathinfo === '/test/baz') {
  39. return array('_route' => 'baz');
  40. }
  41. // baz2
  42. if ($pathinfo === '/test/baz.html') {
  43. return array('_route' => 'baz2');
  44. }
  45. // baz3
  46. if (rtrim($pathinfo, '/') === '/test/baz3') {
  47. if (substr($pathinfo, -1) !== '/') {
  48. return $this->redirect($pathinfo.'/', 'baz3');
  49. }
  50. return array('_route' => 'baz3');
  51. }
  52. // baz4
  53. if (0 === strpos($pathinfo, '/test') && preg_match('#^/test/(?P<foo>[^/]+?)/?$#x', $pathinfo, $matches)) {
  54. if (substr($pathinfo, -1) !== '/') {
  55. return $this->redirect($pathinfo.'/', 'baz4');
  56. }
  57. $matches['_route'] = 'baz4';
  58. return $matches;
  59. }
  60. // baz5
  61. if (0 === strpos($pathinfo, '/test') && preg_match('#^/test/(?P<foo>[^/]+?)/?$#x', $pathinfo, $matches)) {
  62. if ($this->context->getMethod() != 'post') {
  63. $allow[] = 'post';
  64. goto not_baz5;
  65. }
  66. if (substr($pathinfo, -1) !== '/') {
  67. return $this->redirect($pathinfo.'/', 'baz5');
  68. }
  69. $matches['_route'] = 'baz5';
  70. return $matches;
  71. }
  72. not_baz5:
  73. // baz.baz6
  74. if (0 === strpos($pathinfo, '/test') && preg_match('#^/test/(?P<foo>[^/]+?)/?$#x', $pathinfo, $matches)) {
  75. if ($this->context->getMethod() != 'put') {
  76. $allow[] = 'put';
  77. goto not_bazbaz6;
  78. }
  79. if (substr($pathinfo, -1) !== '/') {
  80. return $this->redirect($pathinfo.'/', 'baz.baz6');
  81. }
  82. $matches['_route'] = 'baz.baz6';
  83. return $matches;
  84. }
  85. not_bazbaz6:
  86. // foofoo
  87. if ($pathinfo === '/foofoo') {
  88. return array ( 'def' => 'test', '_route' => 'foofoo',);
  89. }
  90. if (0 === strpos($pathinfo, '/a')) {
  91. if (0 === strpos($pathinfo, '/a/b')) {
  92. // foo
  93. if (0 === strpos($pathinfo, '/a/b') && preg_match('#^/a/b/(?P<foo>[^/]+?)$#x', $pathinfo, $matches)) {
  94. $matches['_route'] = 'foo';
  95. return $matches;
  96. }
  97. // bar
  98. if (0 === strpos($pathinfo, '/a/b') && preg_match('#^/a/b/(?P<bar>[^/]+?)$#x', $pathinfo, $matches)) {
  99. $matches['_route'] = 'bar';
  100. return $matches;
  101. }
  102. }
  103. }
  104. // secure
  105. if ($pathinfo === '/secure') {
  106. if ($this->context->getScheme() !== 'https') {
  107. return $this->redirect($pathinfo, 'secure', 'https');
  108. }
  109. return array('_route' => 'secure');
  110. }
  111. // nonsecure
  112. if ($pathinfo === '/nonsecure') {
  113. if ($this->context->getScheme() !== 'http') {
  114. return $this->redirect($pathinfo, 'nonsecure', 'http');
  115. }
  116. return array('_route' => 'nonsecure');
  117. }
  118. throw 0 < count($allow) ? new MethodNotAllowedException(array_unique($allow)) : new ResourceNotFoundException();
  119. }
  120. }