diff --git a/.travis.yml b/.travis.yml index f6595d5..0ea1df4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,11 +1,11 @@ language: php php: - - 5.3.3 - 5.3 - 5.4 - 5.5 - 5.6 + - 7.0 - hhvm before_script: diff --git a/README.md b/README.md index 1950a9a..4565e09 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,10 @@ # ConfigServiceProvider +[![Build Status](https://api.travis-ci.org/saxulum/ConfigServiceProvider.png?branch=master)](https://travis-ci.org/saxulum/ConfigServiceProvider) +[![Total Downloads](https://poser.pugx.org/saxulum/config-service-provider/downloads.png)](https://packagist.org/packages/saxulum/config-service-provider) +[![Latest Stable Version](https://poser.pugx.org/saxulum/config-service-provider/v/stable.png)](https://packagist.org/packages/saxulum/config-service-provider) +[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/saxulum/ConfigServiceProvider/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/saxulum/ConfigServiceProvider/?branch=master) + A config ServiceProvider for [Silex](http://silex.sensiolabs.org) with support for php, json, yaml, and toml. @@ -66,7 +71,7 @@ To use Yaml instead of JSON, just pass a file that ends on `.yml`: $app->register(new Igorw\Silex\ConfigServiceProvider(__DIR__."/../config/services.yml")); -Note, you will have to require the `~2.1` of the `symfony/yaml` package. +Note, you will have to require the `~2.2` of the `symfony/yaml` package. ### Using TOML diff --git a/composer.json b/composer.json index a20436a..0a6ab47 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { - "name": "igorw/config-service-provider", - "description": "A config ServiceProvider for Silex with support for php, json and yaml.", - "keywords": ["silex"], + "name": "saxulum/config-service-provider", + "description": "A config ServiceProvider for Pimple with support for php, json and yaml.", + "keywords": ["silex", "pimple"], "license": "MIT", "authors": [ { @@ -14,22 +14,28 @@ } ], "require": { - "silex/silex": "~1.0" + "php": ">=5.3.3,<8.0", + "pimple/pimple": "~3.0" }, "require-dev": { - "symfony/yaml": "~2.1", + "phpunit/phpunit": "4.0.*", + "symfony/yaml": "~2.2|~3.0", "jamesmoss/toml": "~0.1" }, "suggest": { - "symfony/yaml": "~2.1", + "symfony/yaml": "~2.2|~3.0", "jamesmoss/toml": "~0.1" }, "autoload": { - "psr-0": { "Igorw\\Silex": "src" } + "psr-4": { "Igorw\\Silex\\": "src/Igorw/Silex/" } + }, + "replace": { + "igorw/config-service-provider": "self.version" }, "extra": { "branch-alias": { - "dev-master": "1.2-dev" + "dev-master": "2.0-dev" } - } + }, + "abandoned": true } diff --git a/src/Igorw/Silex/ConfigServiceProvider.php b/src/Igorw/Silex/ConfigServiceProvider.php index ee70599..e77ca70 100644 --- a/src/Igorw/Silex/ConfigServiceProvider.php +++ b/src/Igorw/Silex/ConfigServiceProvider.php @@ -11,8 +11,8 @@ namespace Igorw\Silex; -use Silex\Application; -use Silex\ServiceProviderInterface; +use Pimple\Container; +use Pimple\ServiceProviderInterface; class ConfigServiceProvider implements ServiceProviderInterface { @@ -40,7 +40,7 @@ public function __construct($filename, array $replacements = array(), ConfigDriv )); } - public function register(Application $app) + public function register(Container $app) { $config = $this->readConfig(); @@ -51,11 +51,11 @@ public function register(Application $app) $this->merge($app, $config); } - public function boot(Application $app) + public function boot(Container $app) { } - private function merge(Application $app, array $config) + private function merge(Container $app, array $config) { if ($this->prefix) { $config = array($this->prefix => $config); diff --git a/src/Igorw/Silex/JsonConfigDriver.php b/src/Igorw/Silex/JsonConfigDriver.php index c9c8680..566d707 100644 --- a/src/Igorw/Silex/JsonConfigDriver.php +++ b/src/Igorw/Silex/JsonConfigDriver.php @@ -25,6 +25,12 @@ public function supports($filename) private function parseJson($filename) { $json = file_get_contents($filename); + + // handle empty as [] + if(empty($json)) { + return array(); + } + return json_decode($json, true); } diff --git a/src/Igorw/Silex/YamlConfigDriver.php b/src/Igorw/Silex/YamlConfigDriver.php index 5b849a9..8a36b51 100644 --- a/src/Igorw/Silex/YamlConfigDriver.php +++ b/src/Igorw/Silex/YamlConfigDriver.php @@ -11,7 +11,9 @@ public function load($filename) if (!class_exists('Symfony\\Component\\Yaml\\Yaml')) { throw new \RuntimeException('Unable to read yaml as the Symfony Yaml Component is not installed.'); } - $config = Yaml::parse($filename); + + $input = file_get_contents($filename); + $config = Yaml::parse($input); return $config ?: array(); } diff --git a/tests/integration/ConfigServiceProviderTest.php b/tests/integration/ConfigServiceProviderTest.php index 168b721..f98bfdc 100644 --- a/tests/integration/ConfigServiceProviderTest.php +++ b/tests/integration/ConfigServiceProviderTest.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -use Silex\Application; +use Pimple\Container; use Igorw\Silex\ConfigServiceProvider; /** @@ -23,7 +23,7 @@ class ConfigServiceProviderTest extends \PHPUnit_Framework_TestCase */ public function testRegisterWithoutReplacement($filename) { - $app = new Application(); + $app = new Container(); $app->register(new ConfigServiceProvider($filename)); @@ -36,7 +36,7 @@ public function testRegisterWithoutReplacement($filename) */ public function testRegisterWithReplacement($filename) { - $app = new Application(); + $app = new Container(); $app->register(new ConfigServiceProvider($filename, array( 'data' => 'test-replacement' @@ -65,7 +65,7 @@ public function testEmptyConfigs($filename) */ public function testInFileReplacements($filename) { - $app = new Application(); + $app = new Container(); $app->register(new ConfigServiceProvider($filename)); @@ -81,7 +81,7 @@ public function testInFileReplacements($filename) */ public function testTomlMergeConfigs() { - $app = new Application(); + $app = new Container(); $filenameBase = __DIR__."/Fixtures/config_base.toml"; $filenameExtended = __DIR__."/Fixtures/config_extend.toml"; @@ -110,7 +110,7 @@ public function testTomlMergeConfigs() */ public function testConfigWithPrefix($filename) { - $app = new Application(); + $app = new Container(); $app->register(new ConfigServiceProvider($filename, array(), null, 'prefix')); $this->assertNotNull($app['prefix']); $this->assertSame(true, $app['prefix']['debug']); @@ -122,7 +122,7 @@ public function testConfigWithPrefix($filename) */ public function testMergeConfigsWithPrefix($filenameBase, $filenameExtended) { - $app = new Application(); + $app = new Container(); $app->register(new ConfigServiceProvider($filenameBase, array(), null, 'prefix')); $app->register(new ConfigServiceProvider($filenameExtended, array(), null, 'prefix')); @@ -143,7 +143,7 @@ public function testMergeConfigsWithPrefix($filenameBase, $filenameExtended) */ public function testConfigsWithMultiplePrefixes($filenameBase, $filenameExtended) { - $app = new Application(); + $app = new Container(); $app->register(new ConfigServiceProvider($filenameBase, array(), null, 'base')); $app->register(new ConfigServiceProvider($filenameExtended, array(), null, 'extended')); @@ -160,7 +160,7 @@ public function testConfigsWithMultiplePrefixes($filenameBase, $filenameExtended */ public function testMergeConfigs($filenameBase, $filenameExtended) { - $app = new Application(); + $app = new Container(); $app->register(new ConfigServiceProvider($filenameBase)); $app->register(new ConfigServiceProvider($filenameExtended)); @@ -189,7 +189,7 @@ public function testMergeConfigs($filenameBase, $filenameExtended) */ public function invalidJsonShouldThrowException() { - $app = new Application(); + $app = new Container(); $app->register(new ConfigServiceProvider(__DIR__."/Fixtures/broken.json")); } @@ -199,7 +199,7 @@ public function invalidJsonShouldThrowException() */ public function invalidYamlShouldThrowException() { - $app = new Application(); + $app = new Container(); $app->register(new ConfigServiceProvider(__DIR__."/Fixtures/broken.yml")); } @@ -209,7 +209,7 @@ public function invalidYamlShouldThrowException() */ public function invalidTomlShouldThrowException() { - $app = new Application(); + $app = new Container(); $app->register(new ConfigServiceProvider(__DIR__."/Fixtures/broken.toml")); }