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
33f17eec
Commit
33f17eec
authored
Oct 19, 2013
by
Dave Marshall
Committed by
Fabien Potencier
Oct 26, 2013
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Event helpers add listeners directly after boot
Fixes #748
parent
e0aa6a89
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
0 deletions
+24
-0
src/Silex/Application.php
src/Silex/Application.php
+5
-0
tests/Silex/Tests/LazyDispatcherTest.php
tests/Silex/Tests/LazyDispatcherTest.php
+19
-0
No files found.
src/Silex/Application.php
View file @
33f17eec
...
...
@@ -267,6 +267,11 @@ class Application extends \Pimple implements HttpKernelInterface, TerminableInte
*/
public
function
on
(
$eventName
,
$callback
,
$priority
=
0
)
{
if
(
$this
->
booted
)
{
$this
[
'dispatcher'
]
->
addListener
(
$eventName
,
$callback
,
$priority
);
return
;
}
$this
[
'dispatcher'
]
=
$this
->
share
(
$this
->
extend
(
'dispatcher'
,
function
(
$dispatcher
,
$app
)
use
(
$callback
,
$priority
,
$eventName
)
{
$dispatcher
->
addListener
(
$eventName
,
$callback
,
$priority
);
...
...
tests/Silex/Tests/LazyDispatcherTest.php
View file @
33f17eec
...
...
@@ -38,4 +38,23 @@ class LazyDispatcherTest extends \PHPUnit_Framework_TestCase
$this
->
assertTrue
(
$dispatcherCreated
);
}
/** @test */
public
function
eventHelpersShouldDirectlyAddListenersAfterBoot
()
{
$app
=
new
Application
();
$fired
=
false
;
$app
->
get
(
"/"
,
function
()
use
(
$app
,
&
$fired
)
{
$app
->
finish
(
function
()
use
(
&
$fired
)
{
$fired
=
true
;
});
});
$request
=
Request
::
create
(
'/'
);
$response
=
$app
->
handle
(
$request
);
$app
->
terminate
(
$request
,
$response
);
$this
->
assertTrue
(
$fired
,
'Event was not fired'
);
}
}
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