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
7bee6bfd
Commit
7bee6bfd
authored
Nov 03, 2013
by
Fabien Potencier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
adding a new interface for providers willing to register event listeners
parent
613c4bfa
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
81 additions
and
18 deletions
+81
-18
doc/changelog.rst
doc/changelog.rst
+1
-0
src/Silex/Application.php
src/Silex/Application.php
+6
-2
src/Silex/EventListenerProviderInterface.php
src/Silex/EventListenerProviderInterface.php
+24
-0
src/Silex/Provider/HttpCacheServiceProvider.php
src/Silex/Provider/HttpCacheServiceProvider.php
+9
-3
src/Silex/Provider/HttpFragmentServiceProvider.php
src/Silex/Provider/HttpFragmentServiceProvider.php
+8
-2
src/Silex/Provider/LocaleServiceProvider.php
src/Silex/Provider/LocaleServiceProvider.php
+8
-2
src/Silex/Provider/RememberMeServiceProvider.php
src/Silex/Provider/RememberMeServiceProvider.php
+8
-3
src/Silex/Provider/SecurityServiceProvider.php
src/Silex/Provider/SecurityServiceProvider.php
+8
-3
src/Silex/Provider/SessionServiceProvider.php
src/Silex/Provider/SessionServiceProvider.php
+9
-3
No files found.
doc/changelog.rst
View file @
7bee6bfd
...
@@ -9,6 +9,7 @@ Changelog
...
@@ -9,6 +9,7 @@ Changelog
if you want Silex to manage your locale (must also be registered for the translation service provider)
if you want Silex to manage your locale (must also be registered for the translation service provider)
1.2.0 (2014-03-29)
1.2.0 (2014-03-29)
------------------
* Allowed disabling the boot logic of MonologServiceProvider
* Allowed disabling the boot logic of MonologServiceProvider
* Reverted "convert attributes on the request that actually exist"
* Reverted "convert attributes on the request that actually exist"
...
...
src/Silex/Application.php
View file @
7bee6bfd
...
@@ -179,11 +179,15 @@ class Application extends \Pimple implements HttpKernelInterface, TerminableInte
...
@@ -179,11 +179,15 @@ class Application extends \Pimple implements HttpKernelInterface, TerminableInte
public
function
boot
()
public
function
boot
()
{
{
if
(
!
$this
->
booted
)
{
if
(
!
$this
->
booted
)
{
$this
->
booted
=
true
;
foreach
(
$this
->
providers
as
$provider
)
{
foreach
(
$this
->
providers
as
$provider
)
{
if
(
$provider
instanceof
EventListenerProviderInterface
)
{
$provider
->
subscribe
(
$this
,
$this
[
'dispatcher'
]);
}
$provider
->
boot
(
$this
);
$provider
->
boot
(
$this
);
}
}
$this
->
booted
=
true
;
}
}
}
}
...
...
src/Silex/EventListenerProviderInterface.php
0 → 100644
View file @
7bee6bfd
<?php
/*
* This file is part of the Silex framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace
Silex
;
use
Symfony\Component\EventDispatcher\EventDispatcherInterface
;
/**
* Interface for event listener providers.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
interface
EventListenerProviderInterface
{
public
function
subscribe
(
Application
$app
,
EventDispatcherInterface
$dispatcher
);
}
src/Silex/Provider/HttpCacheServiceProvider.php
View file @
7bee6bfd
...
@@ -12,8 +12,10 @@
...
@@ -12,8 +12,10 @@
namespace
Silex\Provider
;
namespace
Silex\Provider
;
use
Silex\Application
;
use
Silex\Application
;
use
Silex\ServiceProviderInterface
;
use
Silex\HttpCache
;
use
Silex\HttpCache
;
use
Silex\ServiceProviderInterface
;
use
Silex\EventListenerProviderInterface
;
use
Symfony\Component\EventDispatcher\EventDispatcherInterface
;
use
Symfony\Component\HttpKernel\HttpCache\Esi
;
use
Symfony\Component\HttpKernel\HttpCache\Esi
;
use
Symfony\Component\HttpKernel\HttpCache\Store
;
use
Symfony\Component\HttpKernel\HttpCache\Store
;
use
Symfony\Component\HttpKernel\EventListener\EsiListener
;
use
Symfony\Component\HttpKernel\EventListener\EsiListener
;
...
@@ -23,7 +25,7 @@ use Symfony\Component\HttpKernel\EventListener\EsiListener;
...
@@ -23,7 +25,7 @@ use Symfony\Component\HttpKernel\EventListener\EsiListener;
*
*
* @author Fabien Potencier <fabien@symfony.com>
* @author Fabien Potencier <fabien@symfony.com>
*/
*/
class
HttpCacheServiceProvider
implements
ServiceProviderInterface
class
HttpCacheServiceProvider
implements
ServiceProviderInterface
,
EventListenerProviderInterface
{
{
public
function
register
(
Application
$app
)
public
function
register
(
Application
$app
)
{
{
...
@@ -52,8 +54,12 @@ class HttpCacheServiceProvider implements ServiceProviderInterface
...
@@ -52,8 +54,12 @@ class HttpCacheServiceProvider implements ServiceProviderInterface
$app
[
'http_cache.options'
]
=
array
();
$app
[
'http_cache.options'
]
=
array
();
}
}
public
function
subscribe
(
Application
$app
,
EventDispatcherInterface
$dispatcher
)
{
$dispatcher
->
addSubscriber
(
$app
[
'http_cache.esi_listener'
]);
}
public
function
boot
(
Application
$app
)
public
function
boot
(
Application
$app
)
{
{
$app
[
'dispatcher'
]
->
addSubscriber
(
$app
[
'http_cache.esi_listener'
]);
}
}
}
}
src/Silex/Provider/HttpFragmentServiceProvider.php
View file @
7bee6bfd
...
@@ -13,6 +13,8 @@ namespace Silex\Provider;
...
@@ -13,6 +13,8 @@ namespace Silex\Provider;
use
Silex\Application
;
use
Silex\Application
;
use
Silex\ServiceProviderInterface
;
use
Silex\ServiceProviderInterface
;
use
Silex\EventListenerProviderInterface
;
use
Symfony\Component\EventDispatcher\EventDispatcherInterface
;
use
Symfony\Component\HttpKernel\Fragment\FragmentHandler
;
use
Symfony\Component\HttpKernel\Fragment\FragmentHandler
;
use
Symfony\Component\HttpKernel\Fragment\InlineFragmentRenderer
;
use
Symfony\Component\HttpKernel\Fragment\InlineFragmentRenderer
;
use
Symfony\Component\HttpKernel\Fragment\EsiFragmentRenderer
;
use
Symfony\Component\HttpKernel\Fragment\EsiFragmentRenderer
;
...
@@ -25,7 +27,7 @@ use Symfony\Component\HttpKernel\UriSigner;
...
@@ -25,7 +27,7 @@ use Symfony\Component\HttpKernel\UriSigner;
*
*
* @author Fabien Potencier <fabien@symfony.com>
* @author Fabien Potencier <fabien@symfony.com>
*/
*/
class
HttpFragmentServiceProvider
implements
ServiceProviderInterface
class
HttpFragmentServiceProvider
implements
ServiceProviderInterface
,
EventListenerProviderInterface
{
{
public
function
register
(
Application
$app
)
public
function
register
(
Application
$app
)
{
{
...
@@ -76,8 +78,12 @@ class HttpFragmentServiceProvider implements ServiceProviderInterface
...
@@ -76,8 +78,12 @@ class HttpFragmentServiceProvider implements ServiceProviderInterface
});
});
}
}
public
function
subscribe
(
Application
$app
,
EventDispatcherInterface
$dispatcher
)
{
$dispatcher
->
addSubscriber
(
$app
[
'fragment.listener'
]);
}
public
function
boot
(
Application
$app
)
public
function
boot
(
Application
$app
)
{
{
$app
[
'dispatcher'
]
->
addSubscriber
(
$app
[
'fragment.listener'
]);
}
}
}
}
src/Silex/Provider/LocaleServiceProvider.php
View file @
7bee6bfd
...
@@ -14,14 +14,16 @@ namespace Silex\Provider;
...
@@ -14,14 +14,16 @@ namespace Silex\Provider;
use
Silex\Application
;
use
Silex\Application
;
use
Silex\LazyUrlMatcher
;
use
Silex\LazyUrlMatcher
;
use
Silex\ServiceProviderInterface
;
use
Silex\ServiceProviderInterface
;
use
Silex\EventListenerProviderInterface
;
use
Silex\EventListener\LocaleListener
;
use
Silex\EventListener\LocaleListener
;
use
Symfony\Component\EventDispatcher\EventDispatcherInterface
;
/**
/**
* Locale Provider.
* Locale Provider.
*
*
* @author Fabien Potencier <fabien@symfony.com>
* @author Fabien Potencier <fabien@symfony.com>
*/
*/
class
LocaleServiceProvider
implements
ServiceProviderInterface
class
LocaleServiceProvider
implements
ServiceProviderInterface
,
EventListenerProviderInterface
{
{
public
function
register
(
Application
$app
)
public
function
register
(
Application
$app
)
{
{
...
@@ -39,8 +41,12 @@ class LocaleServiceProvider implements ServiceProviderInterface
...
@@ -39,8 +41,12 @@ class LocaleServiceProvider implements ServiceProviderInterface
$app
[
'locale'
]
=
'en'
;
$app
[
'locale'
]
=
'en'
;
}
}
public
function
subscribe
(
Application
$app
,
EventDispatcherInterface
$dispatcher
)
{
$dispatcher
->
addSubscriber
(
$app
[
'locale.listener'
]);
}
public
function
boot
(
Application
$app
)
public
function
boot
(
Application
$app
)
{
{
$app
[
'dispatcher'
]
->
addSubscriber
(
$app
[
'locale.listener'
]);
}
}
}
}
src/Silex/Provider/RememberMeServiceProvider.php
View file @
7bee6bfd
...
@@ -13,6 +13,8 @@ namespace Silex\Provider;
...
@@ -13,6 +13,8 @@ namespace Silex\Provider;
use
Silex\Application
;
use
Silex\Application
;
use
Silex\ServiceProviderInterface
;
use
Silex\ServiceProviderInterface
;
use
Silex\EventListenerProviderInterface
;
use
Symfony\Component\EventDispatcher\EventDispatcherInterface
;
use
Symfony\Component\Security\Core\Authentication\Provider\RememberMeAuthenticationProvider
;
use
Symfony\Component\Security\Core\Authentication\Provider\RememberMeAuthenticationProvider
;
use
Symfony\Component\Security\Http\Firewall\RememberMeListener
;
use
Symfony\Component\Security\Http\Firewall\RememberMeListener
;
use
Symfony\Component\Security\Http\RememberMe\TokenBasedRememberMeServices
;
use
Symfony\Component\Security\Http\RememberMe\TokenBasedRememberMeServices
;
...
@@ -23,7 +25,7 @@ use Symfony\Component\Security\Http\RememberMe\ResponseListener;
...
@@ -23,7 +25,7 @@ use Symfony\Component\Security\Http\RememberMe\ResponseListener;
*
*
* @author Jérôme Tamarelle <jerome@tamarelle.net>
* @author Jérôme Tamarelle <jerome@tamarelle.net>
*/
*/
class
RememberMeServiceProvider
implements
ServiceProviderInterface
class
RememberMeServiceProvider
implements
ServiceProviderInterface
,
EventListenerProviderInterface
{
{
public
function
register
(
Application
$app
)
public
function
register
(
Application
$app
)
{
{
...
@@ -93,12 +95,15 @@ class RememberMeServiceProvider implements ServiceProviderInterface
...
@@ -93,12 +95,15 @@ class RememberMeServiceProvider implements ServiceProviderInterface
});
});
}
}
public
function
subscribe
(
Application
$app
,
EventDispatcherInterface
$dispatcher
)
{
$dispatcher
->
addSubscriber
(
$app
[
'security.remember_me.response_listener'
]);
}
public
function
boot
(
Application
$app
)
public
function
boot
(
Application
$app
)
{
{
if
(
!
isset
(
$app
[
'security'
]))
{
if
(
!
isset
(
$app
[
'security'
]))
{
throw
new
\LogicException
(
'You must register the SecurityServiceProvider to use the RememberMeServiceProvider'
);
throw
new
\LogicException
(
'You must register the SecurityServiceProvider to use the RememberMeServiceProvider'
);
}
}
$app
[
'dispatcher'
]
->
addSubscriber
(
$app
[
'security.remember_me.response_listener'
]);
}
}
}
}
src/Silex/Provider/SecurityServiceProvider.php
View file @
7bee6bfd
...
@@ -13,6 +13,8 @@ namespace Silex\Provider;
...
@@ -13,6 +13,8 @@ namespace Silex\Provider;
use
Silex\Application
;
use
Silex\Application
;
use
Silex\ServiceProviderInterface
;
use
Silex\ServiceProviderInterface
;
use
Silex\EventListenerProviderInterface
;
use
Symfony\Component\EventDispatcher\EventDispatcherInterface
;
use
Symfony\Component\HttpFoundation\RequestMatcher
;
use
Symfony\Component\HttpFoundation\RequestMatcher
;
use
Symfony\Component\HttpFoundation\Request
;
use
Symfony\Component\HttpFoundation\Request
;
use
Symfony\Component\Security\Core\SecurityContext
;
use
Symfony\Component\Security\Core\SecurityContext
;
...
@@ -57,7 +59,7 @@ use Symfony\Component\Security\Http\HttpUtils;
...
@@ -57,7 +59,7 @@ use Symfony\Component\Security\Http\HttpUtils;
*
*
* @author Fabien Potencier <fabien@symfony.com>
* @author Fabien Potencier <fabien@symfony.com>
*/
*/
class
SecurityServiceProvider
implements
ServiceProviderInterface
class
SecurityServiceProvider
implements
ServiceProviderInterface
,
EventListenerProviderInterface
{
{
protected
$fakeRoutes
;
protected
$fakeRoutes
;
...
@@ -535,10 +537,13 @@ class SecurityServiceProvider implements ServiceProviderInterface
...
@@ -535,10 +537,13 @@ class SecurityServiceProvider implements ServiceProviderInterface
}
}
}
}
public
function
boot
(
Application
$app
)
public
function
subscribe
(
Application
$app
,
EventDispatcherInterface
$dispatcher
)
{
{
$app
[
'dispatcher'
]
->
addSubscriber
(
$app
[
'security.firewall'
]);
$dispatcher
->
addSubscriber
(
$app
[
'security.firewall'
]);
}
public
function
boot
(
Application
$app
)
{
foreach
(
$this
->
fakeRoutes
as
$route
)
{
foreach
(
$this
->
fakeRoutes
as
$route
)
{
list
(
$method
,
$pattern
,
$name
)
=
$route
;
list
(
$method
,
$pattern
,
$name
)
=
$route
;
...
...
src/Silex/Provider/SessionServiceProvider.php
View file @
7bee6bfd
...
@@ -13,8 +13,10 @@ namespace Silex\Provider;
...
@@ -13,8 +13,10 @@ namespace Silex\Provider;
use
Silex\Application
;
use
Silex\Application
;
use
Silex\ServiceProviderInterface
;
use
Silex\ServiceProviderInterface
;
use
Silex\EventListenerProviderInterface
;
use
Silex\EventListener\SessionListener
;
use
Silex\EventListener\SessionListener
;
use
Silex\EventListener\TestSessionListener
;
use
Silex\EventListener\TestSessionListener
;
use
Symfony\Component\EventDispatcher\EventDispatcherInterface
;
use
Symfony\Component\HttpFoundation\Session\Storage\Handler\NativeFileSessionHandler
;
use
Symfony\Component\HttpFoundation\Session\Storage\Handler\NativeFileSessionHandler
;
use
Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage
;
use
Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage
;
use
Symfony\Component\HttpFoundation\Session\Storage\MockFileSessionStorage
;
use
Symfony\Component\HttpFoundation\Session\Storage\MockFileSessionStorage
;
...
@@ -25,7 +27,7 @@ use Symfony\Component\HttpFoundation\Session\Session;
...
@@ -25,7 +27,7 @@ use Symfony\Component\HttpFoundation\Session\Session;
*
*
* @author Fabien Potencier <fabien@symfony.com>
* @author Fabien Potencier <fabien@symfony.com>
*/
*/
class
SessionServiceProvider
implements
ServiceProviderInterface
class
SessionServiceProvider
implements
ServiceProviderInterface
,
EventListenerProviderInterface
{
{
private
$app
;
private
$app
;
...
@@ -75,12 +77,16 @@ class SessionServiceProvider implements ServiceProviderInterface
...
@@ -75,12 +77,16 @@ class SessionServiceProvider implements ServiceProviderInterface
$app
[
'session.storage.save_path'
]
=
null
;
$app
[
'session.storage.save_path'
]
=
null
;
}
}
public
function
boot
(
Application
$app
)
public
function
subscribe
(
Application
$app
,
EventDispatcherInterface
$dispatcher
)
{
{
$
app
[
'dispatcher'
]
->
addSubscriber
(
$app
[
'session.listener'
]);
$
dispatcher
->
addSubscriber
(
$app
[
'session.listener'
]);
if
(
$app
[
'session.test'
])
{
if
(
$app
[
'session.test'
])
{
$app
[
'dispatcher'
]
->
addSubscriber
(
$app
[
'session.listener.test'
]);
$app
[
'dispatcher'
]
->
addSubscriber
(
$app
[
'session.listener.test'
]);
}
}
}
}
public
function
boot
(
Application
$app
)
{
}
}
}
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