@@ -42,46 +42,18 @@ class PageRouter extends Router
4242 */
4343 public function handle (?string $ uri = null )
4444 {
45- // If we cannot find a URI to match against, then set it to root (`/`).
46- if ($ uri === null || $ uri === '' ) {
47- $ uri = '/ ' ;
48- }
49-
50- // Decode URL-encoded string
51- $ uri = urldecode ($ uri );
52-
53- $ this ->checkDisallowedChars ($ uri );
54-
55- // Restart filterInfo
56- $ this ->filtersInfo = [];
57-
58- // Checks defined routes
59- if ($ this ->checkRoutes ($ uri )) {
60- if ($ this ->collection ->isFiltered ($ this ->matchedRoute [0 ])) {
61- $ this ->filtersInfo = $ this ->collection ->getFiltersForRoute ($ this ->matchedRoute [0 ]);
45+ try {
46+ $ handle = parent ::handle ($ uri );
47+ } catch (PageNotFoundException $ e ) {
48+ // HACK: Check for page based routes
49+ if ($ this ->pageBasedRoute ($ uri )) {
50+ return $ this ->controllerName ();
6251 }
6352
64- return $ this ->controller ;
65- }
66-
67- // HACK: Check for page based routes
68- if ($ this ->pageBasedRoute ($ uri )) {
69- return $ this ->controllerName ();
70- }
71-
72- // Still here? Then we can try to match the URI against
73- // Controllers/directories, but the application may not
74- // want this, like in the case of API's.
75- if (! $ this ->collection ->shouldAutoRoute ()) {
76- throw new PageNotFoundException (
77- "Can't find a route for ' {$ this ->collection ->getHTTPVerb ()}: {$ uri }'. "
78- );
53+ throw $ e ;
7954 }
8055
81- // Checks auto routes
82- $ this ->autoRoute ($ uri );
83-
84- return $ this ->controllerName ();
56+ return $ handle ;
8557 }
8658
8759 /**
@@ -134,20 +106,4 @@ public function pageBasedRoute(string $uri)
134106
135107 return $ pageFound ;
136108 }
137-
138- /**
139- * Checks disallowed characters
140- */
141- private function checkDisallowedChars (string $ uri ): void
142- {
143- foreach (explode ('/ ' , $ uri ) as $ segment ) {
144- if ($ segment !== '' && $ this ->permittedURIChars !== ''
145- && preg_match ('/\A[ ' . $ this ->permittedURIChars . ']+\z/iu ' , $ segment ) !== 1
146- ) {
147- throw new BadRequestException (
148- 'The URI you submitted has disallowed characters: " ' . $ segment . '" '
149- );
150- }
151- }
152- }
153109}
0 commit comments