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
36abd018
Commit
36abd018
authored
May 20, 2012
by
Fabien Potencier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added support for sub-requests
parent
add25faa
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
1 deletion
+37
-1
src/Silex/Application.php
src/Silex/Application.php
+3
-1
tests/Silex/Tests/ApplicationTest.php
tests/Silex/Tests/ApplicationTest.php
+34
-0
No files found.
src/Silex/Application.php
View file @
36abd018
...
...
@@ -423,6 +423,8 @@ class Application extends \Pimple implements HttpKernelInterface, EventSubscribe
{
$this
->
beforeDispatched
=
false
;
$current
=
HttpKernelInterface
::
SUB_REQUEST
===
$type
?
$this
[
'request'
]
:
$this
[
'request_error'
];
$this
[
'request'
]
=
$request
;
$this
[
'request'
]
->
setDefaultLocale
(
$this
[
'request.default_locale'
]);
...
...
@@ -430,7 +432,7 @@ class Application extends \Pimple implements HttpKernelInterface, EventSubscribe
$response
=
$this
[
'kernel'
]
->
handle
(
$request
,
$type
,
$catch
);
$this
[
'request'
]
=
$
this
[
'request_error'
]
;
$this
[
'request'
]
=
$
current
;
return
$response
;
}
...
...
tests/Silex/Tests/ApplicationTest.php
View file @
36abd018
...
...
@@ -332,6 +332,40 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
$request
=
$app
[
'request'
];
}
public
function
testSubRequest
()
{
$app
=
new
Application
();
$app
->
get
(
'/sub'
,
function
(
Request
$request
)
{
return
new
Response
(
'foo'
);
});
$app
->
get
(
'/'
,
function
(
Request
$request
)
use
(
$app
)
{
return
$app
->
handle
(
Request
::
create
(
'/sub'
),
HttpKernelInterface
::
SUB_REQUEST
);
});
$this
->
assertEquals
(
'foo'
,
$app
->
handle
(
Request
::
create
(
'/'
))
->
getContent
());
}
public
function
testSubRequestDoesNotReplaceMainRequestAfterHandling
()
{
$mainRequest
=
Request
::
create
(
'/'
);
$subRequest
=
Request
::
create
(
'/sub'
);
$app
=
new
Application
();
$app
->
get
(
'/sub'
,
function
(
Request
$request
)
{
return
new
Response
(
'foo'
);
});
$app
->
get
(
'/'
,
function
(
Request
$request
)
use
(
$subRequest
,
$app
)
{
$response
=
$app
->
handle
(
$subRequest
,
HttpKernelInterface
::
SUB_REQUEST
);
// request in app must be the main request here
$response
->
setContent
(
$response
->
getContent
()
.
' '
.
$app
[
'request'
]
->
getPathInfo
());
return
$response
;
});
$this
->
assertEquals
(
'foo /'
,
$app
->
handle
(
$mainRequest
)
->
getContent
());
}
}
class
FooController
...
...
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