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
c4975cc4
Commit
c4975cc4
authored
Jul 18, 2012
by
Jérôme Tamarelle
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Create Application::on() method to add an event listener
parent
81bafcc6
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
0 deletions
+27
-0
src/Silex/Application.php
src/Silex/Application.php
+13
-0
tests/Silex/Tests/ApplicationTest.php
tests/Silex/Tests/ApplicationTest.php
+14
-0
No files found.
src/Silex/Application.php
View file @
c4975cc4
...
...
@@ -270,6 +270,19 @@ class Application extends \Pimple implements HttpKernelInterface, EventSubscribe
return
$this
[
'controllers'
]
->
delete
(
$pattern
,
$to
);
}
/**
* Adds an event listener that listens on the specified events.
*
* @param string $eventName The event to listen on
* @param callable $listener The listener
* @param integer $priority The higher this value, the earlier an event
* listener will be triggered in the chain (defaults to 0)
*/
public
function
on
(
$eventName
,
$callback
,
$priority
=
0
)
{
return
$this
[
'dispatcher'
]
->
addListener
(
$eventName
,
$callback
,
$priority
);
}
/**
* Registers a before filter.
*
...
...
tests/Silex/Tests/ApplicationTest.php
View file @
c4975cc4
...
...
@@ -106,6 +106,20 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
$this
->
assertEquals
(
'foobar'
,
$response
->
getContent
());
}
public
function
testOn
()
{
$app
=
new
Application
();
$app
[
'pass'
]
=
false
;
$app
->
on
(
'test'
,
function
(
Event
$e
)
use
(
$app
)
{
$app
[
'pass'
]
=
true
;
});
$app
[
'dispatcher'
]
->
dispatch
(
'test'
);
$this
->
assertTrue
(
$app
[
'pass'
]);
}
public
function
testAbort
()
{
$app
=
new
Application
();
...
...
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