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
38b34164
Commit
38b34164
authored
Feb 21, 2011
by
Igor Wiedler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use event dispatcher for before/after handlers
parent
dec6a2b7
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
11 deletions
+8
-11
src/Silex/Framework.php
src/Silex/Framework.php
+8
-11
No files found.
src/Silex/Framework.php
View file @
38b34164
...
...
@@ -29,7 +29,7 @@ use Symfony\Component\Routing\Matcher\UrlMatcher;
class
Framework
extends
HttpKernel
{
protected
$routes
;
protected
$
handlers
=
array
(
'error'
=>
array
(),
'before'
=>
array
(),
'after'
=>
array
()
);
protected
$
errorHandlers
=
array
(
);
protected
$request
;
/**
...
...
@@ -182,7 +182,7 @@ class Framework extends HttpKernel
*/
public
function
before
(
$callback
)
{
$this
->
handlers
[
'before'
][]
=
$callback
;
$this
->
dispatcher
->
connect
(
'silex.before'
,
$callback
)
;
return
$this
;
}
...
...
@@ -200,7 +200,7 @@ class Framework extends HttpKernel
*/
public
function
after
(
$callback
)
{
$this
->
handlers
[
'after'
][]
=
$callback
;
$this
->
dispatcher
->
connect
(
'silex.after'
,
$callback
)
;
return
$this
;
}
...
...
@@ -224,7 +224,7 @@ class Framework extends HttpKernel
*/
public
function
error
(
$callback
)
{
$this
->
handlers
[
'error'
]
[]
=
$callback
;
$this
->
errorHandlers
[]
=
$callback
;
return
$this
;
}
...
...
@@ -296,9 +296,7 @@ class Framework extends HttpKernel
*/
public
function
runBeforeFilters
(
Event
$event
)
{
foreach
(
$this
->
handlers
[
'before'
]
as
$beforeFilter
)
{
$beforeFilter
();
}
$this
->
dispatcher
->
notify
(
new
Event
(
null
,
'silex.before'
));
}
/**
...
...
@@ -326,9 +324,7 @@ class Framework extends HttpKernel
*/
public
function
runAfterFilters
(
Event
$event
,
$response
)
{
foreach
(
$this
->
handlers
[
'after'
]
as
$afterFilter
)
{
$afterFilter
();
}
$this
->
dispatcher
->
notify
(
new
Event
(
null
,
'silex.after'
));
return
$response
;
}
...
...
@@ -344,8 +340,9 @@ class Framework extends HttpKernel
public
function
handleException
(
Event
$event
)
{
$exception
=
$event
->
get
(
'exception'
);
$response
=
$prevResult
=
null
;
foreach
(
$this
->
handlers
[
'error'
]
as
$callback
)
{
foreach
(
$this
->
errorHandlers
as
$callback
)
{
$result
=
$callback
(
$exception
);
if
(
null
!==
$result
&&
!
$prevResult
)
{
$response
=
$this
->
parseStringResponse
(
$event
,
$result
);
...
...
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