url_matcher2.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  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. $trimmedPathinfo = rtrim($pathinfo, '/');
  25. $context = $this->context;
  26. $request = $this->request;
  27. $requestMethod = $canonicalMethod = $context->getMethod();
  28. $scheme = $context->getScheme();
  29. if ('HEAD' === $requestMethod) {
  30. $canonicalMethod = 'GET';
  31. }
  32. if (0 === strpos($pathinfo, '/foo')) {
  33. // foo
  34. if (preg_match('#^/foo/(?P<bar>baz|symfony)$#s', $pathinfo, $matches)) {
  35. return $this->mergeDefaults(array_replace($matches, array('_route' => 'foo')), array ( 'def' => 'test',));
  36. }
  37. // foofoo
  38. if ('/foofoo' === $pathinfo) {
  39. return array ( 'def' => 'test', '_route' => 'foofoo',);
  40. }
  41. }
  42. elseif (0 === strpos($pathinfo, '/bar')) {
  43. // bar
  44. if (preg_match('#^/bar/(?P<foo>[^/]++)$#s', $pathinfo, $matches)) {
  45. if ('GET' !== $canonicalMethod) {
  46. $allow[] = 'GET';
  47. goto not_bar;
  48. }
  49. return $this->mergeDefaults(array_replace($matches, array('_route' => 'bar')), array ());
  50. }
  51. not_bar:
  52. // barhead
  53. if (0 === strpos($pathinfo, '/barhead') && preg_match('#^/barhead/(?P<foo>[^/]++)$#s', $pathinfo, $matches)) {
  54. if ('GET' !== $canonicalMethod) {
  55. $allow[] = 'GET';
  56. goto not_barhead;
  57. }
  58. return $this->mergeDefaults(array_replace($matches, array('_route' => 'barhead')), array ());
  59. }
  60. not_barhead:
  61. }
  62. elseif (0 === strpos($pathinfo, '/test')) {
  63. if (0 === strpos($pathinfo, '/test/baz')) {
  64. // baz
  65. if ('/test/baz' === $pathinfo) {
  66. return array('_route' => 'baz');
  67. }
  68. // baz2
  69. if ('/test/baz.html' === $pathinfo) {
  70. return array('_route' => 'baz2');
  71. }
  72. // baz3
  73. if ('/test/baz3' === $trimmedPathinfo) {
  74. if (substr($pathinfo, -1) !== '/') {
  75. return $this->redirect($pathinfo.'/', 'baz3');
  76. }
  77. return array('_route' => 'baz3');
  78. }
  79. }
  80. // baz4
  81. if (preg_match('#^/test/(?P<foo>[^/]++)/?$#s', $pathinfo, $matches)) {
  82. if (substr($pathinfo, -1) !== '/') {
  83. return $this->redirect($pathinfo.'/', 'baz4');
  84. }
  85. return $this->mergeDefaults(array_replace($matches, array('_route' => 'baz4')), array ());
  86. }
  87. // baz5
  88. if (preg_match('#^/test/(?P<foo>[^/]++)/$#s', $pathinfo, $matches)) {
  89. if ('POST' !== $canonicalMethod) {
  90. $allow[] = 'POST';
  91. goto not_baz5;
  92. }
  93. return $this->mergeDefaults(array_replace($matches, array('_route' => 'baz5')), array ());
  94. }
  95. not_baz5:
  96. // baz.baz6
  97. if (preg_match('#^/test/(?P<foo>[^/]++)/$#s', $pathinfo, $matches)) {
  98. if ('PUT' !== $canonicalMethod) {
  99. $allow[] = 'PUT';
  100. goto not_bazbaz6;
  101. }
  102. return $this->mergeDefaults(array_replace($matches, array('_route' => 'baz.baz6')), array ());
  103. }
  104. not_bazbaz6:
  105. }
  106. // quoter
  107. if (preg_match('#^/(?P<quoter>[\']+)$#s', $pathinfo, $matches)) {
  108. return $this->mergeDefaults(array_replace($matches, array('_route' => 'quoter')), array ());
  109. }
  110. // space
  111. if ('/spa ce' === $pathinfo) {
  112. return array('_route' => 'space');
  113. }
  114. if (0 === strpos($pathinfo, '/a')) {
  115. if (0 === strpos($pathinfo, '/a/b\'b')) {
  116. // foo1
  117. if (preg_match('#^/a/b\'b/(?P<foo>[^/]++)$#s', $pathinfo, $matches)) {
  118. return $this->mergeDefaults(array_replace($matches, array('_route' => 'foo1')), array ());
  119. }
  120. // bar1
  121. if (preg_match('#^/a/b\'b/(?P<bar>[^/]++)$#s', $pathinfo, $matches)) {
  122. return $this->mergeDefaults(array_replace($matches, array('_route' => 'bar1')), array ());
  123. }
  124. }
  125. // overridden
  126. if (preg_match('#^/a/(?P<var>.*)$#s', $pathinfo, $matches)) {
  127. return $this->mergeDefaults(array_replace($matches, array('_route' => 'overridden')), array ());
  128. }
  129. if (0 === strpos($pathinfo, '/a/b\'b')) {
  130. // foo2
  131. if (preg_match('#^/a/b\'b/(?P<foo1>[^/]++)$#s', $pathinfo, $matches)) {
  132. return $this->mergeDefaults(array_replace($matches, array('_route' => 'foo2')), array ());
  133. }
  134. // bar2
  135. if (preg_match('#^/a/b\'b/(?P<bar1>[^/]++)$#s', $pathinfo, $matches)) {
  136. return $this->mergeDefaults(array_replace($matches, array('_route' => 'bar2')), array ());
  137. }
  138. }
  139. }
  140. elseif (0 === strpos($pathinfo, '/multi')) {
  141. // helloWorld
  142. if (0 === strpos($pathinfo, '/multi/hello') && preg_match('#^/multi/hello(?:/(?P<who>[^/]++))?$#s', $pathinfo, $matches)) {
  143. return $this->mergeDefaults(array_replace($matches, array('_route' => 'helloWorld')), array ( 'who' => 'World!',));
  144. }
  145. // hey
  146. if ('/multi/hey' === $trimmedPathinfo) {
  147. if (substr($pathinfo, -1) !== '/') {
  148. return $this->redirect($pathinfo.'/', 'hey');
  149. }
  150. return array('_route' => 'hey');
  151. }
  152. // overridden2
  153. if ('/multi/new' === $pathinfo) {
  154. return array('_route' => 'overridden2');
  155. }
  156. }
  157. // foo3
  158. if (preg_match('#^/(?P<_locale>[^/]++)/b/(?P<foo>[^/]++)$#s', $pathinfo, $matches)) {
  159. return $this->mergeDefaults(array_replace($matches, array('_route' => 'foo3')), array ());
  160. }
  161. // bar3
  162. if (preg_match('#^/(?P<_locale>[^/]++)/b/(?P<bar>[^/]++)$#s', $pathinfo, $matches)) {
  163. return $this->mergeDefaults(array_replace($matches, array('_route' => 'bar3')), array ());
  164. }
  165. if (0 === strpos($pathinfo, '/aba')) {
  166. // ababa
  167. if ('/ababa' === $pathinfo) {
  168. return array('_route' => 'ababa');
  169. }
  170. // foo4
  171. if (preg_match('#^/aba/(?P<foo>[^/]++)$#s', $pathinfo, $matches)) {
  172. return $this->mergeDefaults(array_replace($matches, array('_route' => 'foo4')), array ());
  173. }
  174. }
  175. $host = $context->getHost();
  176. if (preg_match('#^a\\.example\\.com$#si', $host, $hostMatches)) {
  177. // route1
  178. if ('/route1' === $pathinfo) {
  179. return array('_route' => 'route1');
  180. }
  181. // route2
  182. if ('/c2/route2' === $pathinfo) {
  183. return array('_route' => 'route2');
  184. }
  185. }
  186. if (preg_match('#^b\\.example\\.com$#si', $host, $hostMatches)) {
  187. // route3
  188. if ('/c2/route3' === $pathinfo) {
  189. return array('_route' => 'route3');
  190. }
  191. }
  192. if (preg_match('#^a\\.example\\.com$#si', $host, $hostMatches)) {
  193. // route4
  194. if ('/route4' === $pathinfo) {
  195. return array('_route' => 'route4');
  196. }
  197. }
  198. if (preg_match('#^c\\.example\\.com$#si', $host, $hostMatches)) {
  199. // route5
  200. if ('/route5' === $pathinfo) {
  201. return array('_route' => 'route5');
  202. }
  203. }
  204. // route6
  205. if ('/route6' === $pathinfo) {
  206. return array('_route' => 'route6');
  207. }
  208. if (preg_match('#^(?P<var1>[^\\.]++)\\.example\\.com$#si', $host, $hostMatches)) {
  209. if (0 === strpos($pathinfo, '/route1')) {
  210. // route11
  211. if ('/route11' === $pathinfo) {
  212. return $this->mergeDefaults(array_replace($hostMatches, array('_route' => 'route11')), array ());
  213. }
  214. // route12
  215. if ('/route12' === $pathinfo) {
  216. return $this->mergeDefaults(array_replace($hostMatches, array('_route' => 'route12')), array ( 'var1' => 'val',));
  217. }
  218. // route13
  219. if (0 === strpos($pathinfo, '/route13') && preg_match('#^/route13/(?P<name>[^/]++)$#s', $pathinfo, $matches)) {
  220. return $this->mergeDefaults(array_replace($hostMatches, $matches, array('_route' => 'route13')), array ());
  221. }
  222. // route14
  223. if (0 === strpos($pathinfo, '/route14') && preg_match('#^/route14/(?P<name>[^/]++)$#s', $pathinfo, $matches)) {
  224. return $this->mergeDefaults(array_replace($hostMatches, $matches, array('_route' => 'route14')), array ( 'var1' => 'val',));
  225. }
  226. }
  227. }
  228. if (preg_match('#^c\\.example\\.com$#si', $host, $hostMatches)) {
  229. // route15
  230. if (0 === strpos($pathinfo, '/route15') && preg_match('#^/route15/(?P<name>[^/]++)$#s', $pathinfo, $matches)) {
  231. return $this->mergeDefaults(array_replace($matches, array('_route' => 'route15')), array ());
  232. }
  233. }
  234. // route16
  235. if (0 === strpos($pathinfo, '/route16') && preg_match('#^/route16/(?P<name>[^/]++)$#s', $pathinfo, $matches)) {
  236. return $this->mergeDefaults(array_replace($matches, array('_route' => 'route16')), array ( 'var1' => 'val',));
  237. }
  238. // route17
  239. if ('/route17' === $pathinfo) {
  240. return array('_route' => 'route17');
  241. }
  242. // a
  243. if ('/a/a...' === $pathinfo) {
  244. return array('_route' => 'a');
  245. }
  246. if (0 === strpos($pathinfo, '/a/b')) {
  247. // b
  248. if (preg_match('#^/a/b/(?P<var>[^/]++)$#s', $pathinfo, $matches)) {
  249. return $this->mergeDefaults(array_replace($matches, array('_route' => 'b')), array ());
  250. }
  251. // c
  252. if (0 === strpos($pathinfo, '/a/b/c') && preg_match('#^/a/b/c/(?P<var>[^/]++)$#s', $pathinfo, $matches)) {
  253. return $this->mergeDefaults(array_replace($matches, array('_route' => 'c')), array ());
  254. }
  255. }
  256. // secure
  257. if ('/secure' === $pathinfo) {
  258. $requiredSchemes = array ( 'https' => 0,);
  259. if (!isset($requiredSchemes[$scheme])) {
  260. return $this->redirect($pathinfo, 'secure', key($requiredSchemes));
  261. }
  262. return array('_route' => 'secure');
  263. }
  264. // nonsecure
  265. if ('/nonsecure' === $pathinfo) {
  266. $requiredSchemes = array ( 'http' => 0,);
  267. if (!isset($requiredSchemes[$scheme])) {
  268. return $this->redirect($pathinfo, 'nonsecure', key($requiredSchemes));
  269. }
  270. return array('_route' => 'nonsecure');
  271. }
  272. throw 0 < count($allow) ? new MethodNotAllowedException(array_unique($allow)) : new ResourceNotFoundException();
  273. }
  274. }