PageRenderTime 48ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/src/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher2.php

https://github.com/Exercise/symfony
PHP | 244 lines | 167 code | 39 blank | 38 comment | 55 complexity | d4a483bb8b85bf868ee6d9bb74280176 MD5 | raw file
  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\Component\Routing\Tests\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. $pathinfo = rawurldecode($pathinfo);
  24. // foo
  25. if (0 === strpos($pathinfo, '/foo') && preg_match('#^/foo/(?<bar>baz|symfony)$#s', $pathinfo, $matches)) {
  26. return array_merge($this->mergeDefaults($matches, array ( 'def' => 'test',)), array('_route' => 'foo'));
  27. }
  28. // bar
  29. if (0 === strpos($pathinfo, '/bar') && preg_match('#^/bar/(?<foo>[^/]+?)$#s', $pathinfo, $matches)) {
  30. if (!in_array($this->context->getMethod(), array('GET', 'HEAD'))) {
  31. $allow = array_merge($allow, array('GET', 'HEAD'));
  32. goto not_bar;
  33. }
  34. $matches['_route'] = 'bar';
  35. return $matches;
  36. }
  37. not_bar:
  38. // barhead
  39. if (0 === strpos($pathinfo, '/barhead') && preg_match('#^/barhead/(?<foo>[^/]+?)$#s', $pathinfo, $matches)) {
  40. if (!in_array($this->context->getMethod(), array('GET', 'HEAD'))) {
  41. $allow = array_merge($allow, array('GET', 'HEAD'));
  42. goto not_barhead;
  43. }
  44. $matches['_route'] = 'barhead';
  45. return $matches;
  46. }
  47. not_barhead:
  48. // baz
  49. if ($pathinfo === '/test/baz') {
  50. return array('_route' => 'baz');
  51. }
  52. // baz2
  53. if ($pathinfo === '/test/baz.html') {
  54. return array('_route' => 'baz2');
  55. }
  56. // baz3
  57. if (rtrim($pathinfo, '/') === '/test/baz3') {
  58. if (substr($pathinfo, -1) !== '/') {
  59. return $this->redirect($pathinfo.'/', 'baz3');
  60. }
  61. return array('_route' => 'baz3');
  62. }
  63. // baz4
  64. if (0 === strpos($pathinfo, '/test') && preg_match('#^/test/(?<foo>[^/]+?)/?$#s', $pathinfo, $matches)) {
  65. if (substr($pathinfo, -1) !== '/') {
  66. return $this->redirect($pathinfo.'/', 'baz4');
  67. }
  68. $matches['_route'] = 'baz4';
  69. return $matches;
  70. }
  71. // baz5
  72. if (0 === strpos($pathinfo, '/test') && preg_match('#^/test/(?<foo>[^/]+?)/$#s', $pathinfo, $matches)) {
  73. if ($this->context->getMethod() != 'POST') {
  74. $allow[] = 'POST';
  75. goto not_baz5;
  76. }
  77. $matches['_route'] = 'baz5';
  78. return $matches;
  79. }
  80. not_baz5:
  81. // baz.baz6
  82. if (0 === strpos($pathinfo, '/test') && preg_match('#^/test/(?<foo>[^/]+?)/$#s', $pathinfo, $matches)) {
  83. if ($this->context->getMethod() != 'PUT') {
  84. $allow[] = 'PUT';
  85. goto not_bazbaz6;
  86. }
  87. $matches['_route'] = 'baz.baz6';
  88. return $matches;
  89. }
  90. not_bazbaz6:
  91. // foofoo
  92. if ($pathinfo === '/foofoo') {
  93. return array ( 'def' => 'test', '_route' => 'foofoo',);
  94. }
  95. // quoter
  96. if (preg_match('#^/(?<quoter>[\']+)$#s', $pathinfo, $matches)) {
  97. $matches['_route'] = 'quoter';
  98. return $matches;
  99. }
  100. // space
  101. if ($pathinfo === '/spa ce') {
  102. return array('_route' => 'space');
  103. }
  104. if (0 === strpos($pathinfo, '/a')) {
  105. if (0 === strpos($pathinfo, '/a/b\'b')) {
  106. // foo1
  107. if (preg_match('#^/a/b\'b/(?<foo>[^/]+?)$#s', $pathinfo, $matches)) {
  108. $matches['_route'] = 'foo1';
  109. return $matches;
  110. }
  111. // bar1
  112. if (preg_match('#^/a/b\'b/(?<bar>[^/]+?)$#s', $pathinfo, $matches)) {
  113. $matches['_route'] = 'bar1';
  114. return $matches;
  115. }
  116. }
  117. // overriden
  118. if (preg_match('#^/a/(?<var>.*)$#s', $pathinfo, $matches)) {
  119. $matches['_route'] = 'overriden';
  120. return $matches;
  121. }
  122. if (0 === strpos($pathinfo, '/a/b\'b')) {
  123. // foo2
  124. if (preg_match('#^/a/b\'b/(?<foo1>[^/]+?)$#s', $pathinfo, $matches)) {
  125. $matches['_route'] = 'foo2';
  126. return $matches;
  127. }
  128. // bar2
  129. if (preg_match('#^/a/b\'b/(?<bar1>[^/]+?)$#s', $pathinfo, $matches)) {
  130. $matches['_route'] = 'bar2';
  131. return $matches;
  132. }
  133. }
  134. }
  135. if (0 === strpos($pathinfo, '/multi')) {
  136. // helloWorld
  137. if (0 === strpos($pathinfo, '/multi/hello') && preg_match('#^/multi/hello(?:/(?<who>[^/]+?))?$#s', $pathinfo, $matches)) {
  138. return array_merge($this->mergeDefaults($matches, array ( 'who' => 'World!',)), array('_route' => 'helloWorld'));
  139. }
  140. // overriden2
  141. if ($pathinfo === '/multi/new') {
  142. return array('_route' => 'overriden2');
  143. }
  144. // hey
  145. if (rtrim($pathinfo, '/') === '/multi/hey') {
  146. if (substr($pathinfo, -1) !== '/') {
  147. return $this->redirect($pathinfo.'/', 'hey');
  148. }
  149. return array('_route' => 'hey');
  150. }
  151. }
  152. // foo3
  153. if (preg_match('#^/(?<_locale>[^/]+?)/b/(?<foo>[^/]+?)$#s', $pathinfo, $matches)) {
  154. $matches['_route'] = 'foo3';
  155. return $matches;
  156. }
  157. // bar3
  158. if (preg_match('#^/(?<_locale>[^/]+?)/b/(?<bar>[^/]+?)$#s', $pathinfo, $matches)) {
  159. $matches['_route'] = 'bar3';
  160. return $matches;
  161. }
  162. // ababa
  163. if ($pathinfo === '/ababa') {
  164. return array('_route' => 'ababa');
  165. }
  166. // foo4
  167. if (0 === strpos($pathinfo, '/aba') && preg_match('#^/aba/(?<foo>[^/]+?)$#s', $pathinfo, $matches)) {
  168. $matches['_route'] = 'foo4';
  169. return $matches;
  170. }
  171. if (0 === strpos($pathinfo, '/a')) {
  172. // a
  173. if ($pathinfo === '/a/a...') {
  174. return array('_route' => 'a');
  175. }
  176. if (0 === strpos($pathinfo, '/a/b')) {
  177. // b
  178. if (preg_match('#^/a/b/(?<var>[^/]+?)$#s', $pathinfo, $matches)) {
  179. $matches['_route'] = 'b';
  180. return $matches;
  181. }
  182. // c
  183. if (0 === strpos($pathinfo, '/a/b/c') && preg_match('#^/a/b/c/(?<var>[^/]+?)$#s', $pathinfo, $matches)) {
  184. $matches['_route'] = 'c';
  185. return $matches;
  186. }
  187. }
  188. }
  189. // secure
  190. if ($pathinfo === '/secure') {
  191. if ($this->context->getScheme() !== 'https') {
  192. return $this->redirect($pathinfo, 'secure', 'https');
  193. }
  194. return array('_route' => 'secure');
  195. }
  196. // nonsecure
  197. if ($pathinfo === '/nonsecure') {
  198. if ($this->context->getScheme() !== 'http') {
  199. return $this->redirect($pathinfo, 'nonsecure', 'http');
  200. }
  201. return array('_route' => 'nonsecure');
  202. }
  203. throw 0 < count($allow) ? new MethodNotAllowedException(array_unique($allow)) : new ResourceNotFoundException();
  204. }
  205. }