From e5f21bb4f7f327b5ee8492dca4b8e10b06e0cb03 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Tue, 11 Apr 2017 14:07:14 -0500 Subject: [PATCH 1/2] Ensure we can detect globally qualified config providers This fixes #37. Essentially, the `$isRegisteredPattern` was failing if the `$package` was globally qualified within the configuration (e.g., `\Zend\Validator\ConfigProvider`). The pattern now checks for an optional `\\` prefix to the FQCN. --- src/Injector/ConfigAggregatorInjector.php | 7 +++- .../Injector/ConfigAggregatorInjectorTest.php | 11 ++++++ ...ssive-application-from-skeleton.config.php | 37 +++++++++++++++++++ 3 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 test/Injector/TestAsset/expressive-application-from-skeleton.config.php diff --git a/src/Injector/ConfigAggregatorInjector.php b/src/Injector/ConfigAggregatorInjector.php index 6e0b11d..4613059 100644 --- a/src/Injector/ConfigAggregatorInjector.php +++ b/src/Injector/ConfigAggregatorInjector.php @@ -78,11 +78,14 @@ class ConfigAggregatorInjector extends AbstractInjector */ public function __construct($projectRoot = '') { + $ns = preg_quote('\\'); $this->isRegisteredPattern = '/new (?:' - . preg_quote('\\') + . $ns . '?' . preg_quote('Zend\ConfigAggregator\\') - . ')?ConfigAggregator\(\s*(?:array\(|\[).*\s+%s::class/s'; + . ')?ConfigAggregator\(\s*(?:array\(|\[).*\s+' + . $ns + . '?%s::class/s'; $this->injectionPatterns[self::TYPE_CONFIG_PROVIDER]['pattern'] = sprintf( "/(new (?:%s?%s)?ConfigAggregator\(\s*(?:array\(|\[)\s*)(?:\r|\n|\r\n)(\s*)/", diff --git a/test/Injector/ConfigAggregatorInjectorTest.php b/test/Injector/ConfigAggregatorInjectorTest.php index 372132b..122d4f1 100644 --- a/test/Injector/ConfigAggregatorInjectorTest.php +++ b/test/Injector/ConfigAggregatorInjectorTest.php @@ -7,6 +7,7 @@ namespace ZendTest\ComponentInstaller\Injector; +use org\bovigo\vfs\vfsStream; use Zend\ComponentInstaller\Injector\ConfigAggregatorInjector; class ConfigAggregatorInjectorTest extends AbstractInjectorTestCase @@ -151,4 +152,14 @@ public function packagePopulatedInConfiguration() ]; // @codingStandardsIgnoreEnd } + + public function testProperlyDetectsExistingConfigProviderInConfigWithMixedRelativeAndGloballyQualifiedNames() + { + $contents = file_get_contents(__DIR__ . '/TestAsset/expressive-application-from-skeleton.config.php'); + vfsStream::newFile('config/config.php') + ->at($this->configDir) + ->setContent($contents); + + $this->assertTrue($this->injector->isRegistered('Zend\Validator\ConfigProvider')); + } } diff --git a/test/Injector/TestAsset/expressive-application-from-skeleton.config.php b/test/Injector/TestAsset/expressive-application-from-skeleton.config.php new file mode 100644 index 0000000..7fb18f6 --- /dev/null +++ b/test/Injector/TestAsset/expressive-application-from-skeleton.config.php @@ -0,0 +1,37 @@ + 'data/config-cache.php', +]; + +$aggregator = new ConfigAggregator([ + \Zend\Validator\ConfigProvider::class, + \Zend\InputFilter\ConfigProvider::class, + \Zend\Filter\ConfigProvider::class, + \Zend\Mail\ConfigProvider::class, + \Contact\ConfigProvider::class, + // Include cache configuration + new ArrayProvider($cacheConfig), + + // Default App module config + App\ConfigProvider::class, + + // Load application config in a pre-defined order in such a way that local settings + // overwrite global settings. (Loaded as first to last): + // - `global.php` + // - `*.global.php` + // - `local.php` + // - `*.local.php` + new PhpFileProvider('config/autoload/{{,*.}global,{,*.}local}.php'), + + // Load development config if it exists + new PhpFileProvider('config/development.config.php'), +], $cacheConfig['config_cache_path']); + +return $aggregator->getMergedConfig(); From ad6a7c3ff3c85f98ceee85c9185e26e6a499a11a Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Tue, 11 Apr 2017 14:15:59 -0500 Subject: [PATCH 2/2] Added CHANGELOG for #38 --- CHANGELOG.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 17b0aa2..7289d56 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,28 @@ All notable changes to this project will be documented in this file, in reverse chronological order by release. +## 0.7.1 - 2017-04-11 + +### Added + +- Nothing. + +### Deprecated + +- Nothing. + +### Removed + +- Nothing. + +### Fixed + +- [#38](https://github.com/zendframework/zend-component-installer/pull/38) fixes + an issue with detection of config providers in `ConfigAggregator`-based + configuration files. Previously, entries that were globally qualified + (prefixed with `\\`) were not properly detected, leading to the installer + re-asking to inject. + ## 0.7.0 - 2017-02-22 ### Added