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
f674b3be
Commit
f674b3be
authored
Mar 26, 2011
by
Fabien Potencier
Browse files
Options
Browse Files
Download
Plain Diff
merged igows/redirect
parents
12bb71b2
8cc98bdc
Changes
2
Show 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 @
f674b3be
...
...
@@ -21,6 +21,7 @@ use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException;
use
Symfony\Component\HttpKernel\Exception\NotFoundHttpException
;
use
Symfony\Component\HttpKernel\Events
as
HttpKernelEvents
;
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
;
...
...
@@ -242,6 +243,19 @@ class Application extends \Pimple implements HttpKernelInterface, EventSubscribe
$this
[
'controllers'
]
->
flush
();
}
/**
* Redirects the user to another URL.
*
* @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
);
}
/**
* Handles the request and deliver the response.
*
...
...
tests/Silex/Tests/RouterTest.php
View file @
f674b3be
...
...
@@ -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