From a1bf4540aaff737388af7d35d8560bf77ac5e63e Mon Sep 17 00:00:00 2001 From: Kevin Boyd Date: Sat, 4 Jun 2016 11:26:46 -0700 Subject: [PATCH 1/4] Adding support for Silex 2 --- composer.json | 3 ++- src/Igorw/Silex/ConfigServiceProvider.php | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index a20436a..e864617 100644 --- a/composer.json +++ b/composer.json @@ -14,9 +14,10 @@ } ], "require": { - "silex/silex": "~1.0" + "silex/silex": "~2.0" }, "require-dev": { + "phpunit/phpunit": "^4.0", "symfony/yaml": "~2.1", "jamesmoss/toml": "~0.1" }, diff --git a/src/Igorw/Silex/ConfigServiceProvider.php b/src/Igorw/Silex/ConfigServiceProvider.php index ee70599..b17b9fd 100644 --- a/src/Igorw/Silex/ConfigServiceProvider.php +++ b/src/Igorw/Silex/ConfigServiceProvider.php @@ -11,8 +11,9 @@ namespace Igorw\Silex; +use Pimple\Container; +use Pimple\ServiceProviderInterface; use Silex\Application; -use Silex\ServiceProviderInterface; class ConfigServiceProvider implements ServiceProviderInterface { @@ -40,7 +41,7 @@ public function __construct($filename, array $replacements = array(), ConfigDriv )); } - public function register(Application $app) + public function register(Container $app) { $config = $this->readConfig(); From e5ace5a73cc9637815506d39a8971dfe6c3a7653 Mon Sep 17 00:00:00 2001 From: Kevin Boyd Date: Sun, 12 Jun 2016 01:30:13 -0700 Subject: [PATCH 2/4] Updating travis to remove support for PHP 5.3 and 5.4 --- .travis.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index f6595d5..5d44420 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,11 +1,9 @@ language: php php: - - 5.3.3 - - 5.3 - - 5.4 - 5.5 - 5.6 + - 7.0 - hhvm before_script: From 0df2372888f3b73764ee27f019ebb5dfd4a0ebe3 Mon Sep 17 00:00:00 2001 From: Kevin Boyd Date: Sun, 12 Jun 2016 21:29:55 -0700 Subject: [PATCH 3/4] Converting YamlConfigDriver to use new 3.x method of fetching file contents before parsing; passing a filename is being deprecated --- src/Igorw/Silex/YamlConfigDriver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Igorw/Silex/YamlConfigDriver.php b/src/Igorw/Silex/YamlConfigDriver.php index 5b849a9..03d1bb3 100644 --- a/src/Igorw/Silex/YamlConfigDriver.php +++ b/src/Igorw/Silex/YamlConfigDriver.php @@ -11,7 +11,7 @@ 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); + $config = Yaml::parse(file_get_contents($filename)); return $config ?: array(); } From cfa2eaa898c14414cb3f11c885fa0f3aa990f7ea Mon Sep 17 00:00:00 2001 From: Kevin Boyd Date: Sun, 12 Jun 2016 21:51:32 -0700 Subject: [PATCH 4/4] Handling a change to JSON decoding in PHP 7. Empty strings are now registered as a syntax error, which ConfigServiceProvider users won't be expecting and likely won't be concerned about. --- src/Igorw/Silex/JsonConfigDriver.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/Igorw/Silex/JsonConfigDriver.php b/src/Igorw/Silex/JsonConfigDriver.php index c9c8680..5481e4b 100644 --- a/src/Igorw/Silex/JsonConfigDriver.php +++ b/src/Igorw/Silex/JsonConfigDriver.php @@ -6,10 +6,14 @@ class JsonConfigDriver implements ConfigDriver { public function load($filename) { - $config = $this->parseJson($filename); + $json = file_get_contents($filename); + $config = $this->parseJson($json); - if (JSON_ERROR_NONE !== json_last_error()) { - $jsonError = $this->getJsonError(json_last_error()); + // determine if there was an error + // suppress PHP 7's syntax error for empty JSON strings + $errorCode = json_last_error(); + if (JSON_ERROR_NONE !== $errorCode && ($errorCode !== JSON_ERROR_SYNTAX || $json !== '')) { + $jsonError = $this->getJsonError($errorCode); throw new \RuntimeException( sprintf('Invalid JSON provided "%s" in "%s"', $jsonError, $filename)); } @@ -22,9 +26,8 @@ public function supports($filename) return (bool) preg_match('#\.json(\.dist)?$#', $filename); } - private function parseJson($filename) + private function parseJson($json) { - $json = file_get_contents($filename); return json_decode($json, true); }