Commit 5a4b265e authored by Fabien Potencier's avatar Fabien Potencier

upgraded to Pimple 2.1

parent 322dbb5d
......@@ -4,6 +4,7 @@ Changelog
2.0.0 (2013-XX-XX)
------------------
* Updated Pimple to 2.1
* Updated session listeners to extends HttpKernel ones
* [BC BREAK] Locale management has been moved to LocaleServiceProvider which must be registered
if you want Silex to manage your locale (must also be registered for the translation service provider)
......
......@@ -63,10 +63,10 @@ Pimple is probably the simplest service container out there. It makes strong
use of closures and implements the ArrayAccess interface.
We will start off by creating a new instance of Pimple -- and because
``Silex\Application`` extends ``Pimple`` all of this applies to Silex as
well::
``Silex\Application`` extends ``Pimple\Container`` all of this applies to Silex
as well::
$container = new Pimple();
$container = new Pimple\Container();
or::
......
......@@ -12,6 +12,7 @@
namespace Silex\Api;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Pimple\Container;
/**
* Interface for event listener providers.
......@@ -20,5 +21,5 @@ use Symfony\Component\EventDispatcher\EventDispatcherInterface;
*/
interface EventListenerProviderInterface
{
public function subscribe(\Pimple $app, EventDispatcherInterface $dispatcher);
public function subscribe(Container $app, EventDispatcherInterface $dispatcher);
}
<?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;
/**
* Interface that all Silex service providers must implement.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
interface ServiceProviderInterface
{
/**
* Registers services on the given Pimple container.
*
* This method should only be used to configure services and parameters.
* It should not get services.
*
* @param Pimple $app A Pimple instance
*/
public function register(\Pimple $app);
}
......@@ -11,6 +11,8 @@
namespace Silex;
use Pimple\Container;
use Pimple\ServiceProviderInterface;
use Symfony\Component\HttpFoundation\BinaryFileResponse;
use Symfony\Component\HttpKernel\HttpKernel;
use Symfony\Component\HttpKernel\HttpKernelInterface;
......@@ -31,7 +33,6 @@ use Symfony\Component\Routing\RouteCollection;
use Silex\Api\BootableProviderInterface;
use Silex\Api\EventListenerProviderInterface;
use Silex\Api\ControllerProviderInterface;
use Silex\Api\ServiceProviderInterface;
use Silex\EventListener\MiddlewareListener;
use Silex\EventListener\ConverterListener;
use Silex\EventListener\StringToResponseListener;
......@@ -42,7 +43,7 @@ use Silex\Provider\RoutingServiceProvider;
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class Application extends \Pimple implements HttpKernelInterface, TerminableInterface
class Application extends Container implements HttpKernelInterface, TerminableInterface
{
const VERSION = '2.0.0-DEV';
......
......@@ -11,13 +11,15 @@
namespace Silex;
use Pimple\Container;
class CallbackResolver
{
const SERVICE_PATTERN = "/[A-Za-z0-9\._\-]+:[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*/";
private $app;
public function __construct(\Pimple $app)
public function __construct(Container $app)
{
$this->app = $app;
}
......
......@@ -11,7 +11,8 @@
namespace Silex\Provider;
use Silex\Api\ServiceProviderInterface;
use Pimple\Container;
use Pimple\ServiceProviderInterface;
use Doctrine\DBAL\DriverManager;
use Doctrine\DBAL\Configuration;
use Doctrine\Common\EventManager;
......@@ -24,7 +25,7 @@ use Symfony\Bridge\Doctrine\Logger\DbalLogger;
*/
class DoctrineServiceProvider implements ServiceProviderInterface
{
public function register(\Pimple $app)
public function register(Container $app)
{
$app['db.default_options'] = array(
'driver' => 'pdo_mysql',
......@@ -62,7 +63,7 @@ class DoctrineServiceProvider implements ServiceProviderInterface
$app['dbs'] = function ($app) {
$app['dbs.options.initializer']();
$dbs = new \Pimple();
$dbs = new Container();
foreach ($app['dbs.options'] as $name => $options) {
if ($app['dbs.default'] === $name) {
// we use shortcuts here in case the default has been overridden
......@@ -84,7 +85,7 @@ class DoctrineServiceProvider implements ServiceProviderInterface
$app['dbs.config'] = function ($app) {
$app['dbs.options.initializer']();
$configs = new \Pimple();
$configs = new Container();
foreach ($app['dbs.options'] as $name => $options) {
$configs[$name] = new Configuration();
......@@ -99,7 +100,7 @@ class DoctrineServiceProvider implements ServiceProviderInterface
$app['dbs.event_manager'] = function ($app) {
$app['dbs.options.initializer']();
$managers = new \Pimple();
$managers = new Container();
foreach ($app['dbs.options'] as $name => $options) {
$managers[$name] = new EventManager();
}
......
......@@ -11,7 +11,8 @@
namespace Silex\Provider;
use Silex\Api\ServiceProviderInterface;
use Pimple\Container;
use Pimple\ServiceProviderInterface;
use Symfony\Component\Form\Extension\Csrf\CsrfExtension;
use Symfony\Component\Form\Extension\Csrf\CsrfProvider\DefaultCsrfProvider;
use Symfony\Component\Form\Extension\Csrf\CsrfProvider\SessionCsrfProvider;
......@@ -27,7 +28,7 @@ use Symfony\Component\Form\ResolvedFormTypeFactory;
*/
class FormServiceProvider implements ServiceProviderInterface
{
public function register(\Pimple $app)
public function register(Container $app)
{
if (!class_exists('Locale') && !class_exists('Symfony\Component\Locale\Stub\StubLocale')) {
throw new \RuntimeException('You must either install the PHP intl extension or the Symfony Locale Component to use the Form extension.');
......
......@@ -11,8 +11,9 @@
namespace Silex\Provider;
use Pimple\Container;
use Pimple\ServiceProviderInterface;
use Silex\Provider\HttpCache\HttpCache;
use Silex\Api\ServiceProviderInterface;
use Silex\Api\EventListenerProviderInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpKernel\HttpCache\Esi;
......@@ -26,7 +27,7 @@ use Symfony\Component\HttpKernel\EventListener\EsiListener;
*/
class HttpCacheServiceProvider implements ServiceProviderInterface, EventListenerProviderInterface
{
public function register(\Pimple $app)
public function register(Container $app)
{
$app['http_cache'] = function ($app) {
$app['http_cache.options'] = array_replace(
......@@ -53,7 +54,7 @@ class HttpCacheServiceProvider implements ServiceProviderInterface, EventListene
$app['http_cache.options'] = array();
}
public function subscribe(\Pimple $app, EventDispatcherInterface $dispatcher)
public function subscribe(Container $app, EventDispatcherInterface $dispatcher)
{
$dispatcher->addSubscriber($app['http_cache.esi_listener']);
}
......
......@@ -11,7 +11,8 @@
namespace Silex\Provider;
use Silex\Api\ServiceProviderInterface;
use Pimple\Container;
use Pimple\ServiceProviderInterface;
use Silex\Api\EventListenerProviderInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpKernel\Fragment\FragmentHandler;
......@@ -28,7 +29,7 @@ use Symfony\Component\HttpKernel\UriSigner;
*/
class HttpFragmentServiceProvider implements ServiceProviderInterface, EventListenerProviderInterface
{
public function register(\Pimple $app)
public function register(Container $app)
{
$app['fragment.handler'] = function ($app) {
return new FragmentHandler($app['fragment.renderers'], isset($app['debug']) ? $app['debug'] : false, $app['request_stack']);
......@@ -77,7 +78,7 @@ class HttpFragmentServiceProvider implements ServiceProviderInterface, EventList
};
}
public function subscribe(\Pimple $app, EventDispatcherInterface $dispatcher)
public function subscribe(Container $app, EventDispatcherInterface $dispatcher)
{
$dispatcher->addSubscriber($app['fragment.listener']);
}
......
......@@ -11,6 +11,7 @@
namespace Silex\Provider\Locale;
use Pimple\Container;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\EventListener\LocaleListener as BaseLocaleListener;
use Symfony\Component\HttpFoundation\RequestStack;
......@@ -25,7 +26,7 @@ class LocaleListener extends BaseLocaleListener
{
protected $app;
public function __construct(\Pimple $app, RequestContextAwareInterface $router = null, RequestStack $requestStack = null)
public function __construct(Container $app, RequestContextAwareInterface $router = null, RequestStack $requestStack = null)
{
parent::__construct($app['locale'], $router, $requestStack);
......
......@@ -11,7 +11,8 @@
namespace Silex\Provider;
use Silex\Api\ServiceProviderInterface;
use Pimple\Container;
use Pimple\ServiceProviderInterface;
use Silex\Api\EventListenerProviderInterface;
use Silex\Provider\Locale\LocaleListener;
use Silex\Provider\Routing\LazyUrlMatcher;
......@@ -24,7 +25,7 @@ use Symfony\Component\EventDispatcher\EventDispatcherInterface;
*/
class LocaleServiceProvider implements ServiceProviderInterface, EventListenerProviderInterface
{
public function register(\Pimple $app)
public function register(Container $app)
{
$app['locale.listener'] = function ($app) {
$urlMatcher = null;
......@@ -40,7 +41,7 @@ class LocaleServiceProvider implements ServiceProviderInterface, EventListenerPr
$app['locale'] = 'en';
}
public function subscribe(\Pimple $app, EventDispatcherInterface $dispatcher)
public function subscribe(Container $app, EventDispatcherInterface $dispatcher)
{
$dispatcher->addSubscriber($app['locale.listener']);
}
......
......@@ -11,10 +11,11 @@
namespace Silex\Provider;
use Pimple\Container;
use Pimple\ServiceProviderInterface;
use Monolog\Logger;
use Monolog\Handler\StreamHandler;
use Silex\Application;
use Silex\Api\ServiceProviderInterface;
use Silex\Api\BootableProviderInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
......@@ -29,7 +30,7 @@ use Silex\EventListener\LogListener;
*/
class MonologServiceProvider implements ServiceProviderInterface, BootableProviderInterface
{
public function register(\Pimple $app)
public function register(Container $app)
{
$app['logger'] = function () use ($app) {
return $app['monolog'];
......
......@@ -11,7 +11,8 @@
namespace Silex\Provider;
use Silex\Api\ServiceProviderInterface;
use Pimple\Container;
use Pimple\ServiceProviderInterface;
use Silex\Api\EventListenerProviderInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\Security\Core\Authentication\Provider\RememberMeAuthenticationProvider;
......@@ -26,7 +27,7 @@ use Symfony\Component\Security\Http\RememberMe\ResponseListener;
*/
class RememberMeServiceProvider implements ServiceProviderInterface, EventListenerProviderInterface
{
public function register(\Pimple $app)
public function register(Container $app)
{
$app['security.remember_me.response_listener'] = function ($app) {
if (!isset($app['security'])) {
......@@ -98,7 +99,7 @@ class RememberMeServiceProvider implements ServiceProviderInterface, EventListen
});
}
public function subscribe(\Pimple $app, EventDispatcherInterface $dispatcher)
public function subscribe(Container $app, EventDispatcherInterface $dispatcher)
{
$dispatcher->addSubscriber($app['security.remember_me.response_listener']);
}
......
......@@ -11,7 +11,8 @@
namespace Silex\Provider;
use Silex\Api\ServiceProviderInterface;
use Pimple\Container;
use Pimple\ServiceProviderInterface;
use Silex\Api\EventListenerProviderInterface;
use Silex\Provider\Routing\RedirectableUrlMatcher;
use Silex\Provider\Routing\LazyUrlMatcher;
......@@ -27,7 +28,7 @@ use Symfony\Component\EventDispatcher\EventDispatcherInterface;
*/
class RoutingServiceProvider implements ServiceProviderInterface, EventListenerProviderInterface
{
public function register(\Pimple $app)
public function register(Container $app)
{
$app['url_generator'] = function ($app) {
return new UrlGenerator($app['routes'], $app['request_context']);
......@@ -55,7 +56,7 @@ class RoutingServiceProvider implements ServiceProviderInterface, EventListenerP
};
}
public function subscribe(\Pimple $app, EventDispatcherInterface $dispatcher)
public function subscribe(Container $app, EventDispatcherInterface $dispatcher)
{
$dispatcher->addSubscriber($app['routing.listener']);
}
......
......@@ -11,10 +11,11 @@
namespace Silex\Provider;
use Pimple\Container;
use Pimple\ServiceProviderInterface;
use Silex\Application;
use Silex\Api\BootableProviderInterface;
use Silex\Api\ControllerProviderInterface;
use Silex\Api\ServiceProviderInterface;
use Silex\Api\EventListenerProviderInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\RequestMatcher;
......@@ -65,7 +66,7 @@ class SecurityServiceProvider implements ServiceProviderInterface, EventListener
{
protected $fakeRoutes;
public function register(\Pimple $app)
public function register(Container $app)
{
// used to register routes for login_check and logout
$this->fakeRoutes = array();
......@@ -542,7 +543,7 @@ class SecurityServiceProvider implements ServiceProviderInterface, EventListener
}
}
public function subscribe(\Pimple $app, EventDispatcherInterface $dispatcher)
public function subscribe(Container $app, EventDispatcherInterface $dispatcher)
{
$dispatcher->addSubscriber($app['security.firewall']);
}
......
......@@ -11,7 +11,8 @@
namespace Silex\Provider;
use Silex\Api\ServiceProviderInterface;
use Pimple\Container;
use Pimple\ServiceProviderInterface;
use Symfony\Component\Serializer\Serializer;
use Symfony\Component\Serializer\Encoder\JsonEncoder;
use Symfony\Component\Serializer\Encoder\XmlEncoder;
......@@ -34,7 +35,7 @@ class SerializerServiceProvider implements ServiceProviderInterface
*
* @param Pimple $app
*/
public function register(\Pimple $app)
public function register(Container $app)
{
$app['serializer'] = function () use ($app) {
return new Serializer($app['serializer.normalizers'], $app['serializer.encoders']);
......
......@@ -11,12 +11,13 @@
namespace Silex\Provider;
use Silex\Api\ServiceProviderInterface;
use Pimple\Container;
use Pimple\ServiceProviderInterface;
use Silex\ServiceControllerResolver;
class ServiceControllerServiceProvider implements ServiceProviderInterface
{
public function register(\Pimple $app)
public function register(Container $app)
{
$app->extend('resolver', function ($resolver, $app) {
return new ServiceControllerResolver($resolver, $app['callback_resolver']);
......
......@@ -11,6 +11,7 @@
namespace Silex\Provider\Session;
use Pimple\Container;
use Symfony\Component\HttpKernel\EventListener\SessionListener as BaseSessionListener;
/**
......@@ -22,7 +23,7 @@ class SessionListener extends BaseSessionListener
{
private $app;
public function __construct(\Pimple $app)
public function __construct(Container $app)
{
$this->app = $app;
}
......
......@@ -11,6 +11,7 @@
namespace Silex\Provider\Session;
use Pimple\Container;
use Symfony\Component\HttpKernel\EventListener\TestSessionListener as BaseTestSessionListener;
/**
......@@ -22,7 +23,7 @@ class TestSessionListener extends BaseTestSessionListener
{
private $app;
public function __construct(\Pimple $app)
public function __construct(Container $app)
{
$this->app = $app;
}
......
......@@ -11,7 +11,8 @@
namespace Silex\Provider;
use Silex\Api\ServiceProviderInterface;
use Pimple\Container;
use Pimple\ServiceProviderInterface;
use Silex\Api\EventListenerProviderInterface;
use Silex\Provider\Session\SessionListener;
use Silex\Provider\Session\TestSessionListener;
......@@ -30,7 +31,7 @@ class SessionServiceProvider implements ServiceProviderInterface, EventListenerP
{
private $app;
public function register(\Pimple $app)
public function register(Container $app)
{
$this->app = $app;
......@@ -76,7 +77,7 @@ class SessionServiceProvider implements ServiceProviderInterface, EventListenerP
$app['session.storage.save_path'] = null;
}
public function subscribe(\Pimple $app, EventDispatcherInterface $dispatcher)
public function subscribe(Container $app, EventDispatcherInterface $dispatcher)
{
$dispatcher->addSubscriber($app['session.listener']);
......
......@@ -11,7 +11,8 @@
namespace Silex\Provider;
use Silex\Api\ServiceProviderInterface;
use Pimple\Container;
use Pimple\ServiceProviderInterface;
use Silex\Api\EventListenerProviderInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpKernel\KernelEvents;
......@@ -24,7 +25,7 @@ use Symfony\Component\HttpKernel\Event\PostResponseEvent;
*/
class SwiftmailerServiceProvider implements ServiceProviderInterface, EventListenerProviderInterface
{
public function register(\Pimple $app)
public function register(Container $app)
{
$app['swiftmailer.options'] = array();
......@@ -87,7 +88,7 @@ class SwiftmailerServiceProvider implements ServiceProviderInterface, EventListe
};
}
public function subscribe(\Pimple $app, EventDispatcherInterface $dispatcher)
public function subscribe(Container $app, EventDispatcherInterface $dispatcher)
{
$dispatcher->addListener(KernelEvents::TERMINATE, function (PostResponseEvent $event) use ($app) {
// To speed things up (by avoiding Swift Mailer initialization), flush
......
......@@ -11,6 +11,7 @@
namespace Silex\Provider\Translation;
use Pimple\Container;
use Symfony\Component\Translation\Translator as BaseTranslator;
use Symfony\Component\Translation\MessageSelector;
......@@ -23,7 +24,7 @@ class Translator extends BaseTranslator
{
protected $app;
public function __construct(\Pimple $app, MessageSelector $selector)
public function __construct(Container $app, MessageSelector $selector)
{
$this->app = $app;
......
......@@ -11,7 +11,8 @@
namespace Silex\Provider;
use Silex\Api\ServiceProviderInterface;
use Pimple\Container;
use Pimple\ServiceProviderInterface;
use Silex\Provider\Translation\Translator;
use Symfony\Component\Translation\MessageSelector;
use Symfony\Component\Translation\Loader\ArrayLoader;
......@@ -24,7 +25,7 @@ use Symfony\Component\Translation\Loader\XliffFileLoader;
*/
class TranslationServiceProvider implements ServiceProviderInterface
{
public function register(\Pimple $app)
public function register(Container $app)
{
$app['translator'] = function ($app) {
if (!isset($app['locale'])) {
......
......@@ -11,7 +11,8 @@
namespace Silex\Provider;
use Silex\Api\ServiceProviderInterface;
use Pimple\Container;
use Pimple\ServiceProviderInterface;
use Symfony\Bridge\Twig\Extension\RoutingExtension;
use Symfony\Bridge\Twig\Extension\TranslationExtension;
use Symfony\Bridge\Twig\Extension\FormExtension;
......@@ -27,7 +28,7 @@ use Symfony\Bridge\Twig\Form\TwigRenderer;
*/
class TwigServiceProvider implements ServiceProviderInterface
{
public function register(\Pimple $app)
public function register(Container $app)
{
$app['twig.options'] = array();
$app['twig.form.templates'] = array('form_div_layout.html.twig');
......
......@@ -11,6 +11,7 @@
namespace Silex\Provider\Validator;
use Pimple\Container;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidatorFactoryInterface;
use Symfony\Component\Validator\ConstraintValidator;
......@@ -24,7 +25,7 @@ use Symfony\Component\Validator\ConstraintValidator;
class ConstraintValidatorFactory implements ConstraintValidatorFactoryInterface
{
/**
* @var \Pimple
* @var Container
*/
protected $container;
......@@ -41,10 +42,10 @@ class ConstraintValidatorFactory implements ConstraintValidatorFactoryInterface
/**
* Constructor
*
* @param \Pimple $container DI container
* @param array $serviceNames Validator service names
* @param Container $container DI container
* @param array $serviceNames Validator service names
*/
public function __construct(\Pimple $container, array $serviceNames = array())
public function __construct(Container $container, array $serviceNames = array())
{
$this->container = $container;
$this->serviceNames = $serviceNames;
......
......@@ -11,7 +11,8 @@
namespace Silex\Provider;
use Silex\Api\ServiceProviderInterface;
use Pimple\Container;
use Pimple\ServiceProviderInterface;
use Silex\Provider\Validator\ConstraintValidatorFactory;
use Symfony\Component\Validator\Validator;
use Symfony\Component\Validator\DefaultTranslator;
......@@ -25,7 +26,7 @@ use Symfony\Component\Validator\Mapping\Loader\StaticMethodLoader;
*/
class ValidatorServiceProvider implements ServiceProviderInterface
{
public function register(\Pimple $app)
public function register(Container $app)
{
$app['validator'] = function ($app) {
$r = new \ReflectionClass('Symfony\Component\Validator\Validator');
......
......@@ -432,7 +432,7 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
public function testRegisterShouldReturnSelf()
{
$app = new Application();
$provider = $this->getMock('Silex\Api\ServiceProviderInterface');
$provider = $this->getMock('Pimple\ServiceProviderInterface');
$this->assertSame($app, $app->register($provider));
}
......
......@@ -11,13 +11,14 @@
namespace Silex\Tests;
use Pimple\Container;
use Silex\CallbackResolver;
class CallbackResolverTest extends \PHPUnit_Framework_Testcase
{
public function setup()
{
$this->app = new \Pimple();
$this->app = new Container();
$this->resolver = new CallbackResolver($this->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