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
c78353e2
Commit
c78353e2
authored
Feb 24, 2012
by
Igor Wiedler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Give useful error message when accessing request outside of request scope
parent
219ba070
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
1 deletion
+15
-1
src/Silex/Application.php
src/Silex/Application.php
+4
-0
tests/Silex/Tests/ApplicationTest.php
tests/Silex/Tests/ApplicationTest.php
+11
-1
No files found.
src/Silex/Application.php
View file @
c78353e2
...
@@ -111,6 +111,10 @@ class Application extends \Pimple implements HttpKernelInterface, EventSubscribe
...
@@ -111,6 +111,10 @@ class Application extends \Pimple implements HttpKernelInterface, EventSubscribe
return
new
RedirectableUrlMatcher
(
$app
[
'routes'
],
$app
[
'request_context'
]);
return
new
RedirectableUrlMatcher
(
$app
[
'routes'
],
$app
[
'request_context'
]);
});
});
$this
[
'request'
]
=
function
()
{
throw
new
\RuntimeException
(
'Accessed request service outside of request scope. Try moving that call to a before handler or controller.'
);
};
$this
[
'request.http_port'
]
=
80
;
$this
[
'request.http_port'
]
=
80
;
$this
[
'request.https_port'
]
=
443
;
$this
[
'request.https_port'
]
=
443
;
$this
[
'debug'
]
=
false
;
$this
[
'debug'
]
=
false
;
...
...
tests/Silex/Tests/ApplicationTest.php
View file @
c78353e2
...
@@ -58,7 +58,7 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
...
@@ -58,7 +58,7 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
$this
->
assertEquals
(
$request
,
$app
[
'request'
]);
$this
->
assertEquals
(
$request
,
$app
[
'request'
]);
}
}
public
function
test
g
etRoutesWithNoRoutes
()
public
function
test
G
etRoutesWithNoRoutes
()
{
{
$app
=
new
Application
();
$app
=
new
Application
();
...
@@ -165,6 +165,16 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
...
@@ -165,6 +165,16 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
$this
->
assertEquals
(
'text/html; charset=ISO-8859-1'
,
$response
->
headers
->
get
(
'Content-Type'
));
$this
->
assertEquals
(
'text/html; charset=ISO-8859-1'
,
$response
->
headers
->
get
(
'Content-Type'
));
}
}
/**
* @expectedException RuntimeException
*/
public
function
testAccessingRequestOutsideOfScopeShouldThrowRuntimeException
()
{
$app
=
new
Application
();
$request
=
$app
[
'request'
];
}
}
}
class
FooController
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