url_matcher2.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. // barhead
  38. if (0 === strpos($pathinfo, '/barhead') && preg_match('#^/barhead/(?P<foo>[^/]+?)$#x', $pathinfo, $matches)) {
  39. if (!in_array($this->context->getMethod(), array('get', 'head'))) {
  40. $allow = array_merge($allow, array('get', 'head'));
  41. goto not_barhead;
  42. }
  43. $matches['_route'] = 'barhead';
  44. return $matches;
  45. }
  46. not_barhead:
  47. // baz
  48. if ($pathinfo === '/test/baz') {
  49. return array('_route' => 'baz');
  50. }
  51. // baz2
  52. if ($pathinfo === '/test/baz.html') {
  53. return array('_route' => 'baz2');
  54. }
  55. // baz3
  56. if (rtrim($pathinfo, '/') === '/test/baz3') {
  57. if (substr($pathinfo, -1) !== '/') {
  58. return $this->redirect($pathinfo.'/', 'baz3');
  59. }
  60. return array('_route' => 'baz3');
  61. }
  62. // baz4
  63. if (0 === strpos($pathinfo, '/test') && preg_match('#^/test/(?P<foo>[^/]+?)/?$#x', $pathinfo, $matches)) {
  64. if (substr($pathinfo, -1) !== '/') {
  65. return $this->redirect($pathinfo.'/', 'baz4');
  66. }
  67. $matches['_route'] = 'baz4';
  68. return $matches;
  69. }
  70. // baz5
  71. if (0 === strpos($pathinfo, '/test') && preg_match('#^/test/(?P<foo>[^/]+?)/?$#x', $pathinfo, $matches)) {
  72. if ($this->context->getMethod() != 'post') {
  73. $allow[] = 'post';
  74. goto not_baz5;
  75. }
  76. if (substr($pathinfo, -1) !== '/') {
  77. return $this->redirect($pathinfo.'/', 'baz5');
  78. }
  79. $matches['_route'] = 'baz5';
  80. return $matches;
  81. }
  82. not_baz5:
  83. // baz.baz6
  84. if (0 === strpos($pathinfo, '/test') && preg_match('#^/test/(?P<foo>[^/]+?)/?$#x', $pathinfo, $matches)) {
  85. if ($this->context->getMethod() != 'put') {
  86. $allow[] = 'put';
  87. goto not_bazbaz6;
  88. }
  89. if (substr($pathinfo, -1) !== '/') {
  90. return $this->redirect($pathinfo.'/', 'baz.baz6');
  91. }
  92. $matches['_route'] = 'baz.baz6';
  93. return $matches;
  94. }
  95. not_bazbaz6:
  96. // foofoo
  97. if ($pathinfo === '/foofoo') {
  98. return array ( 'def' => 'test', '_route' => 'foofoo',);
  99. }
  100. if (0 === strpos($pathinfo, '/a')) {
  101. if (0 === strpos($pathinfo, '/a/b')) {
  102. // foo
  103. if (0 === strpos($pathinfo, '/a/b') && preg_match('#^/a/b/(?P<foo>[^/]+?)$#x', $pathinfo, $matches)) {
  104. $matches['_route'] = 'foo';
  105. return $matches;
  106. }
  107. // bar
  108. if (0 === strpos($pathinfo, '/a/b') && preg_match('#^/a/b/(?P<bar>[^/]+?)$#x', $pathinfo, $matches)) {
  109. $matches['_route'] = 'bar';
  110. return $matches;
  111. }
  112. }
  113. }
  114. // secure
  115. if ($pathinfo === '/secure') {
  116. if ($this->context->getScheme() !== 'https') {
  117. return $this->redirect($pathinfo, 'secure', 'https');
  118. }
  119. return array('_route' => 'secure');
  120. }
  121. // nonsecure
  122. if ($pathinfo === '/nonsecure') {
  123. if ($this->context->getScheme() !== 'http') {
  124. return $this->redirect($pathinfo, 'nonsecure', 'http');
  125. }
  126. return array('_route' => 'nonsecure');
  127. }
  128. throw 0 < count($allow) ? new MethodNotAllowedException(array_unique($allow)) : new ResourceNotFoundException();
  129. }
  130. }