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
add25faa
Commit
add25faa
authored
May 20, 2012
by
Fabien Potencier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed Request object accessibility from the application after handling
parent
5d1011c6
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
12 deletions
+32
-12
doc/changelog.rst
doc/changelog.rst
+3
-0
src/Silex/Application.php
src/Silex/Application.php
+9
-3
tests/Silex/Tests/ApplicationTest.php
tests/Silex/Tests/ApplicationTest.php
+20
-9
No files found.
doc/changelog.rst
View file @
add25faa
...
...
@@ -3,6 +3,9 @@ Changelog
This changelog references all backward incompatibilities as we introduce them:
* **2012-05-20**: The Request instance is not available anymore from the
Application after it has been handled.
* **2012-04-01**: Added ``finish`` filters.
* **2012-03-20**: Added ``json`` helper::
...
...
src/Silex/Application.php
View file @
add25faa
...
...
@@ -123,9 +123,11 @@ class Application extends \Pimple implements HttpKernelInterface, EventSubscribe
$this
[
'request.default_locale'
]
=
'en'
;
$this
[
'request
'
]
=
function
()
{
$this
[
'request
_error'
]
=
$this
->
protect
(
function
()
{
throw
new
\RuntimeException
(
'Accessed request service outside of request scope. Try moving that call to a before handler or controller.'
);
};
});
$this
[
'request'
]
=
$this
[
'request_error'
];
$this
[
'request.http_port'
]
=
80
;
$this
[
'request.https_port'
]
=
443
;
...
...
@@ -426,7 +428,11 @@ class Application extends \Pimple implements HttpKernelInterface, EventSubscribe
$this
->
flush
();
return
$this
[
'kernel'
]
->
handle
(
$request
,
$type
,
$catch
);
$response
=
$this
[
'kernel'
]
->
handle
(
$request
,
$type
,
$catch
);
$this
[
'request'
]
=
$this
[
'request_error'
];
return
$response
;
}
/**
...
...
tests/Silex/Tests/ApplicationTest.php
View file @
add25faa
...
...
@@ -49,17 +49,14 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
public
function
testGetRequest
()
{
$app
=
new
Application
();
$app
->
get
(
'/'
,
function
()
{
return
'root'
;
});
$request
=
Request
::
create
(
'/'
);
$app
->
handle
(
$request
);
$app
=
new
Application
();
$app
->
get
(
'/'
,
function
(
Request
$req
)
use
(
$request
)
{
return
$request
===
$req
?
'ok'
:
'ko'
;
});
$this
->
assertEquals
(
$request
,
$app
[
'request'
]
);
$this
->
assertEquals
(
'ok'
,
$app
->
handle
(
$request
)
->
getContent
()
);
}
public
function
testGetRoutesWithNoRoutes
()
...
...
@@ -71,7 +68,7 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
$this
->
assertEquals
(
0
,
count
(
$routes
->
all
()));
}
public
function
test
g
etRoutesWithRoutes
()
public
function
test
G
etRoutesWithRoutes
()
{
$app
=
new
Application
();
...
...
@@ -321,6 +318,20 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
$request
=
$app
[
'request'
];
}
/**
* @expectedException RuntimeException
*/
public
function
testAccessingRequestOutsideOfScopeShouldThrowRuntimeExceptionAfterHandling
()
{
$app
=
new
Application
();
$app
->
get
(
'/'
,
function
()
{
return
'hello'
;
});
$app
->
handle
(
Request
::
create
(
'/'
),
HttpKernelInterface
::
MASTER_REQUEST
,
false
);
$request
=
$app
[
'request'
];
}
}
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