File tree Expand file tree Collapse file tree 3 files changed +23
-10
lines changed Expand file tree Collapse file tree 3 files changed +23
-10
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Cake \Routing \Exception ;
4
+
5
+ use RuntimeException ;
6
+
7
+ class RedirectException extends RuntimeException
8
+ {
9
+ }
Original file line number Diff line number Diff line change 16
16
17
17
use Cake \Event \Event ;
18
18
use Cake \Routing \DispatcherFilter ;
19
+ use Cake \Routing \Exception \RedirectException ;
19
20
use Cake \Routing \Router ;
20
21
21
22
/**
@@ -42,16 +43,23 @@ class RoutingFilter extends DispatcherFilter
42
43
* If Routes have not been loaded they will be loaded, and config/routes.php will be run.
43
44
*
44
45
* @param \Cake\Event\Event $event containing the request, response and additional params
45
- * @return void
46
+ * @return void|Cake\Network\Response A response will be returned when a redirect route is encountered.
46
47
*/
47
48
public function beforeDispatch (Event $ event )
48
49
{
49
50
$ request = $ event ->data ['request ' ];
50
51
Router::setRequestInfo ($ request );
51
52
52
- if (empty ($ request ->params ['controller ' ])) {
53
- $ params = Router::parse ($ request ->url );
54
- $ request ->addParams ($ params );
53
+ try {
54
+ if (empty ($ request ->params ['controller ' ])) {
55
+ $ params = Router::parse ($ request ->url );
56
+ $ request ->addParams ($ params );
57
+ }
58
+ } catch (RedirectException $ e ) {
59
+ $ response = $ event ->data ['response ' ];
60
+ $ response ->statusCode ($ e ->getCode ());
61
+ $ response ->header ('Location ' , $ e ->getMessage ());
62
+ return $ response ;
55
63
}
56
64
}
57
65
}
Original file line number Diff line number Diff line change 15
15
namespace Cake \Routing \Route ;
16
16
17
17
use Cake \Network \Response ;
18
+ use Cake \Routing \Exception \RedirectException ;
18
19
use Cake \Routing \Router ;
19
20
20
21
/**
@@ -91,12 +92,7 @@ public function parse($url)
91
92
if (isset ($ this ->options ['status ' ]) && ($ this ->options ['status ' ] >= 300 && $ this ->options ['status ' ] < 400 )) {
92
93
$ status = $ this ->options ['status ' ];
93
94
}
94
- $ this ->response ->header ([
95
- 'Location ' => Router::url ($ redirect , true )
96
- ]);
97
- $ this ->response ->statusCode ($ status );
98
- $ this ->response ->send ();
99
- $ this ->response ->stop ();
95
+ throw new RedirectException (Router::url ($ redirect , true ), $ status );
100
96
}
101
97
102
98
/**
You can’t perform that action at this time.
0 commit comments