Commit df568cb2 authored by Fabien Potencier's avatar Fabien Potencier

added BootableProviderInterface

parent 1ba15a17
<?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\Api;
use Silex\Application;
/**
* Interface that must implement all Silex service providers.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
interface BootableProviderInterface
{
/**
* Bootstraps the application.
*
* This method is called after all services are registered
* and should be used for "dynamic" configuration (whenever
* a service must be requested).
*/
public function boot(Application $app);
}
...@@ -29,13 +29,4 @@ interface ServiceProviderInterface ...@@ -29,13 +29,4 @@ interface ServiceProviderInterface
* @param Application $app An Application instance * @param Application $app An Application instance
*/ */
public function register(Application $app); public function register(Application $app);
/**
* Bootstraps the application.
*
* This method is called after all services are registered
* and should be used for "dynamic" configuration (whenever
* a service must be requested).
*/
public function boot(Application $app);
} }
...@@ -30,6 +30,7 @@ use Symfony\Component\HttpFoundation\StreamedResponse; ...@@ -30,6 +30,7 @@ use Symfony\Component\HttpFoundation\StreamedResponse;
use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Routing\RouteCollection; use Symfony\Component\Routing\RouteCollection;
use Symfony\Component\Routing\RequestContext; use Symfony\Component\Routing\RequestContext;
use Silex\Api\BootableProviderInterface;
use Silex\Api\EventListenerProviderInterface; use Silex\Api\EventListenerProviderInterface;
use Silex\Api\ControllerProviderInterface; use Silex\Api\ControllerProviderInterface;
use Silex\Api\ServiceProviderInterface; use Silex\Api\ServiceProviderInterface;
...@@ -189,10 +190,12 @@ class Application extends \Pimple implements HttpKernelInterface, TerminableInte ...@@ -189,10 +190,12 @@ class Application extends \Pimple implements HttpKernelInterface, TerminableInte
$provider->subscribe($this, $this['dispatcher']); $provider->subscribe($this, $this['dispatcher']);
} }
if ($provider instanceof BootableProviderInterface) {
$provider->boot($this); $provider->boot($this);
} }
} }
} }
}
/** /**
* Maps a pattern to a callable. * Maps a pattern to a callable.
......
...@@ -127,8 +127,4 @@ class DoctrineServiceProvider implements ServiceProviderInterface ...@@ -127,8 +127,4 @@ class DoctrineServiceProvider implements ServiceProviderInterface
return $dbs[$app['dbs.default']]; return $dbs[$app['dbs.default']];
}); });
} }
public function boot(Application $app)
{
}
} }
...@@ -103,8 +103,4 @@ class FormServiceProvider implements ServiceProviderInterface ...@@ -103,8 +103,4 @@ class FormServiceProvider implements ServiceProviderInterface
return new DefaultCsrfProvider($app['form.secret']); return new DefaultCsrfProvider($app['form.secret']);
}); });
} }
public function boot(Application $app)
{
}
} }
...@@ -58,8 +58,4 @@ class HttpCacheServiceProvider implements ServiceProviderInterface, EventListene ...@@ -58,8 +58,4 @@ class HttpCacheServiceProvider implements ServiceProviderInterface, EventListene
{ {
$dispatcher->addSubscriber($app['http_cache.esi_listener']); $dispatcher->addSubscriber($app['http_cache.esi_listener']);
} }
public function boot(Application $app)
{
}
} }
...@@ -82,8 +82,4 @@ class HttpFragmentServiceProvider implements ServiceProviderInterface, EventList ...@@ -82,8 +82,4 @@ class HttpFragmentServiceProvider implements ServiceProviderInterface, EventList
{ {
$dispatcher->addSubscriber($app['fragment.listener']); $dispatcher->addSubscriber($app['fragment.listener']);
} }
public function boot(Application $app)
{
}
} }
...@@ -15,6 +15,7 @@ use Monolog\Logger; ...@@ -15,6 +15,7 @@ use Monolog\Logger;
use Monolog\Handler\StreamHandler; use Monolog\Handler\StreamHandler;
use Silex\Application; use Silex\Application;
use Silex\Api\ServiceProviderInterface; use Silex\Api\ServiceProviderInterface;
use Silex\Api\BootableProviderInterface;
use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
...@@ -26,7 +27,7 @@ use Silex\EventListener\LogListener; ...@@ -26,7 +27,7 @@ use Silex\EventListener\LogListener;
* *
* @author Fabien Potencier <fabien@symfony.com> * @author Fabien Potencier <fabien@symfony.com>
*/ */
class MonologServiceProvider implements ServiceProviderInterface class MonologServiceProvider implements ServiceProviderInterface, BootableProviderInterface
{ {
public function register(Application $app) public function register(Application $app)
{ {
......
...@@ -103,8 +103,4 @@ class RememberMeServiceProvider implements ServiceProviderInterface, EventListen ...@@ -103,8 +103,4 @@ class RememberMeServiceProvider implements ServiceProviderInterface, EventListen
{ {
$dispatcher->addSubscriber($app['security.remember_me.response_listener']); $dispatcher->addSubscriber($app['security.remember_me.response_listener']);
} }
public function boot(Application $app)
{
}
} }
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
namespace Silex\Provider; namespace Silex\Provider;
use Silex\Application; use Silex\Application;
use Silex\Api\BootableProviderInterface;
use Silex\Api\ControllerProviderInterface; use Silex\Api\ControllerProviderInterface;
use Silex\Api\ServiceProviderInterface; use Silex\Api\ServiceProviderInterface;
use Silex\Api\EventListenerProviderInterface; use Silex\Api\EventListenerProviderInterface;
...@@ -60,7 +61,7 @@ use Symfony\Component\Security\Http\HttpUtils; ...@@ -60,7 +61,7 @@ use Symfony\Component\Security\Http\HttpUtils;
* *
* @author Fabien Potencier <fabien@symfony.com> * @author Fabien Potencier <fabien@symfony.com>
*/ */
class SecurityServiceProvider implements ServiceProviderInterface, EventListenerProviderInterface, ControllerProviderInterface class SecurityServiceProvider implements ServiceProviderInterface, EventListenerProviderInterface, ControllerProviderInterface, BootableProviderInterface
{ {
protected $fakeRoutes; protected $fakeRoutes;
......
...@@ -49,15 +49,4 @@ class SerializerServiceProvider implements ServiceProviderInterface ...@@ -49,15 +49,4 @@ class SerializerServiceProvider implements ServiceProviderInterface
return array(new CustomNormalizer(), new GetSetMethodNormalizer()); return array(new CustomNormalizer(), new GetSetMethodNormalizer());
}); });
} }
/**
* {@inheritDoc}
*
* This provider does not execute any code when booting.
*
* @param Silex\Application $app
*/
public function boot(Application $app)
{
}
} }
...@@ -23,9 +23,4 @@ class ServiceControllerServiceProvider implements ServiceProviderInterface ...@@ -23,9 +23,4 @@ class ServiceControllerServiceProvider implements ServiceProviderInterface
return new ServiceControllerResolver($resolver, $app['callback_resolver']); return new ServiceControllerResolver($resolver, $app['callback_resolver']);
})); }));
} }
public function boot(Application $app)
{
// noop
}
} }
...@@ -85,8 +85,4 @@ class SessionServiceProvider implements ServiceProviderInterface, EventListenerP ...@@ -85,8 +85,4 @@ class SessionServiceProvider implements ServiceProviderInterface, EventListenerP
$app['dispatcher']->addSubscriber($app['session.listener.test']); $app['dispatcher']->addSubscriber($app['session.listener.test']);
} }
} }
public function boot(Application $app)
{
}
} }
...@@ -98,8 +98,4 @@ class SwiftmailerServiceProvider implements ServiceProviderInterface, EventListe ...@@ -98,8 +98,4 @@ class SwiftmailerServiceProvider implements ServiceProviderInterface, EventListe
} }
}); });
} }
public function boot(Application $app)
{
}
} }
...@@ -53,8 +53,4 @@ class TranslationServiceProvider implements ServiceProviderInterface ...@@ -53,8 +53,4 @@ class TranslationServiceProvider implements ServiceProviderInterface
$app['translator.domains'] = array(); $app['translator.domains'] = array();
$app['locale_fallbacks'] = array('en'); $app['locale_fallbacks'] = array('en');
} }
public function boot(Application $app)
{
}
} }
...@@ -106,8 +106,4 @@ class TwigServiceProvider implements ServiceProviderInterface ...@@ -106,8 +106,4 @@ class TwigServiceProvider implements ServiceProviderInterface
)); ));
}); });
} }
public function boot(Application $app)
{
}
} }
...@@ -30,8 +30,4 @@ class UrlGeneratorServiceProvider implements ServiceProviderInterface ...@@ -30,8 +30,4 @@ class UrlGeneratorServiceProvider implements ServiceProviderInterface
return new UrlGenerator($app['routes'], $app['request_context']); return new UrlGenerator($app['routes'], $app['request_context']);
}); });
} }
public function boot(Application $app)
{
}
} }
...@@ -58,8 +58,4 @@ class ValidatorServiceProvider implements ServiceProviderInterface ...@@ -58,8 +58,4 @@ class ValidatorServiceProvider implements ServiceProviderInterface
return array(); return array();
}); });
} }
public function boot(Application $app)
{
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment