Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
language: php

php:
- 5.3.3
- 5.3
- 5.4
- 5.5
- 5.6
- 7.0
- hhvm

before_script:
Expand Down
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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.

Expand Down Expand Up @@ -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

Expand Down
24 changes: 15 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
@@ -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": [
{
Expand All @@ -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
}
10 changes: 5 additions & 5 deletions src/Igorw/Silex/ConfigServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

namespace Igorw\Silex;

use Silex\Application;
use Silex\ServiceProviderInterface;
use Pimple\Container;
use Pimple\ServiceProviderInterface;

class ConfigServiceProvider implements ServiceProviderInterface
{
Expand Down Expand Up @@ -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();

Expand All @@ -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);
Expand Down
6 changes: 6 additions & 0 deletions src/Igorw/Silex/JsonConfigDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
4 changes: 3 additions & 1 deletion src/Igorw/Silex/YamlConfigDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
24 changes: 12 additions & 12 deletions tests/integration/ConfigServiceProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/

use Silex\Application;
use Pimple\Container;
use Igorw\Silex\ConfigServiceProvider;

/**
Expand All @@ -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));

Expand All @@ -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'
Expand Down Expand Up @@ -65,7 +65,7 @@ public function testEmptyConfigs($filename)
*/
public function testInFileReplacements($filename)
{
$app = new Application();
$app = new Container();

$app->register(new ConfigServiceProvider($filename));

Expand All @@ -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";
Expand Down Expand Up @@ -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']);
Expand All @@ -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'));

Expand All @@ -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'));

Expand All @@ -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));

Expand Down Expand Up @@ -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"));
}

Expand All @@ -199,7 +199,7 @@ public function invalidJsonShouldThrowException()
*/
public function invalidYamlShouldThrowException()
{
$app = new Application();
$app = new Container();
$app->register(new ConfigServiceProvider(__DIR__."/Fixtures/broken.yml"));
}

Expand All @@ -209,7 +209,7 @@ public function invalidYamlShouldThrowException()
*/
public function invalidTomlShouldThrowException()
{
$app = new Application();
$app = new Container();
$app->register(new ConfigServiceProvider(__DIR__."/Fixtures/broken.toml"));
}

Expand Down