From 0c32235a61a9426ce91db09cba1542c0c672f1ff Mon Sep 17 00:00:00 2001 From: KisSCoOl Date: Thu, 7 Jul 2016 14:51:23 +0200 Subject: [PATCH] Silex 2.0 support --- composer.json | 6 ++--- .../Silex/Provider/CacheServiceProvider.php | 24 ++++++++++--------- tests/Provider/CacheServiceProviderTest.php | 2 +- 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/composer.json b/composer.json index 98cc0c8..a6c91ac 100644 --- a/composer.json +++ b/composer.json @@ -12,11 +12,11 @@ ], "require": { "php": ">=5.3.3", - "pimple/pimple": "~1.0" + "pimple/pimple": "~3.0" }, "require-dev": { - "silex/silex": "~1.0", - "phpunit/phpunit": "~3.7" + "silex/silex": "~2.0", + "phpunit/phpunit": "~4.5" }, "autoload": { "psr-0": { diff --git a/src/Moust/Silex/Provider/CacheServiceProvider.php b/src/Moust/Silex/Provider/CacheServiceProvider.php index fc9079a..3d5bad4 100644 --- a/src/Moust/Silex/Provider/CacheServiceProvider.php +++ b/src/Moust/Silex/Provider/CacheServiceProvider.php @@ -12,12 +12,14 @@ namespace Moust\Silex\Provider; use Silex\Application; -use Silex\ServiceProviderInterface; +use Pimple\Container; +use Pimple\ServiceProviderInterface; +use Silex\Api\BootableProviderInterface; use Moust\Silex\Cache\CacheFactory; -class CacheServiceProvider implements ServiceProviderInterface +class CacheServiceProvider implements ServiceProviderInterface, BootableProviderInterface { - public function register(Application $app) + public function register(Container $app) { $app['cache.default_options'] = array( 'driver' => 'array' @@ -36,7 +38,7 @@ public function register(Application $app) ); }; - $app['cache.factory'] = $app->share(function ($app) { + $app['cache.factory'] = $app->factory(function ($app) { return new CacheFactory($app['cache.drivers'], $app['caches.options']); }); @@ -64,10 +66,10 @@ public function register(Application $app) $app['caches.options'] = $tmp; }); - $app['caches'] = $app->share(function ($app) { + $app['caches'] = $app->factory(function ($app) { $app['caches.options.initializer'](); - $caches = new \Pimple(); + $caches = new Container(); foreach ($app['caches.options'] as $name => $options) { if ($app['caches.default'] === $name) { // we use shortcuts here in case the default has been overridden @@ -76,7 +78,7 @@ public function register(Application $app) $config = $app['caches.config'][$name]; } - $caches[$name] = $caches->share(function ($caches) use ($app, $config) { + $caches[$name] = $caches->factory(function ($caches) use ($app, $config) { return $app['cache.factory']->getCache($config['driver'], $config); }); } @@ -84,10 +86,10 @@ public function register(Application $app) return $caches; }); - $app['caches.config'] = $app->share(function ($app) { + $app['caches.config'] = $app->factory(function ($app) { $app['caches.options.initializer'](); - $configs = new \Pimple(); + $configs = new Container(); foreach ($app['caches.options'] as $name => $options) { $configs[$name] = $options; } @@ -96,13 +98,13 @@ public function register(Application $app) }); // shortcuts for the "first" cache - $app['cache'] = $app->share(function ($app) { + $app['cache'] = $app->factory(function ($app) { $caches = $app['caches']; return $caches[$app['caches.default']]; }); - $app['cache.config'] = $app->share(function ($app) { + $app['cache.config'] = $app->factory(function ($app) { $caches = $app['caches.config']; return $caches[$app['caches.default']]; diff --git a/tests/Provider/CacheServiceProviderTest.php b/tests/Provider/CacheServiceProviderTest.php index d5f01dd..d48c8cc 100644 --- a/tests/Provider/CacheServiceProviderTest.php +++ b/tests/Provider/CacheServiceProviderTest.php @@ -58,7 +58,7 @@ public function testMultipleCache() $this->assertEquals('./temp', $app['caches']['filesystem']->getCacheDir()); // check default cache - $this->assertSame($app['cache'], $app['caches']['memory']); + $this->assertEquals($app['cache'], $app['caches']['memory']); } public function testApcProvider()