Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Sign in
Toggle navigation
S
Silex
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
common
Silex
Commits
8cc98bdc
Commit
8cc98bdc
authored
Mar 25, 2011
by
Igor Wiedler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Application::redirect convenience method
parent
5aa6a974
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
0 deletions
+22
-0
src/Silex/Application.php
src/Silex/Application.php
+14
-0
tests/Silex/Tests/RouterTest.php
tests/Silex/Tests/RouterTest.php
+8
-0
No files found.
src/Silex/Application.php
View file @
8cc98bdc
...
...
@@ -19,6 +19,7 @@ use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
use
Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException
;
use
Symfony\Component\HttpKernel\Exception\NotFoundHttpException
;
use
Symfony\Component\HttpFoundation\Request
;
use
Symfony\Component\HttpFoundation\RedirectResponse
;
use
Symfony\Component\EventDispatcher\Event
;
use
Symfony\Component\EventDispatcher\EventDispatcher
;
use
Symfony\Component\EventDispatcher\EventSubscriberInterface
;
...
...
@@ -233,6 +234,19 @@ class Application extends HttpKernel implements EventSubscriberInterface
$this
->
controllers
->
flush
();
}
/**
* Redirect
*
* @param string $url The URL to redirect to
* @param integer $status The status code (302 by default)
*
* @see Symfony\Component\HttpFoundation\RedirectResponse
*/
public
function
redirect
(
$url
,
$status
=
302
)
{
return
new
RedirectResponse
(
$url
,
$status
);
}
/**
* Handle the request and deliver the response.
*
...
...
tests/Silex/Tests/RouterTest.php
View file @
8cc98bdc
...
...
@@ -83,9 +83,17 @@ class RouterTest extends \PHPUnit_Framework_TestCase
return
new
RedirectResponse
(
'/target'
);
});
$application
->
match
(
'/redirect2'
,
function
()
use
(
$application
)
{
return
$application
->
redirect
(
'/target2'
);
});
$request
=
Request
::
create
(
'/redirect'
);
$response
=
$application
->
handle
(
$request
);
$this
->
assertTrue
(
$response
->
isRedirected
(
'/target'
));
$request
=
Request
::
create
(
'/redirect2'
);
$response
=
$application
->
handle
(
$request
);
$this
->
assertTrue
(
$response
->
isRedirected
(
'/target2'
));
}
/**
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment