laminas / laminas-component-installer

Composer plugin for injecting modules and configuration providers into application configuration
https://docs.laminas.dev/laminas-component-installer/
BSD 3-Clause "New" or "Revised" License
27 stars 12 forks source link

Added Mezzio development config discovery and injection #68

Closed kynx closed 1 year ago

kynx commented 1 year ago
Q A
Documentation no
Bugfix no
BC Break no
New Feature yes
RFC no
QA no

Description

This PR adds support for injecting config providers into Mezzio's config/development.config.php.dist, following the recommendations from @boesing on https://github.com/mezzio/mezzio-tooling/issues/25. This is useful when adding --dev tools that shouldn't be shipped in production.

If merged a separate PR will be needed against the Mezzio skeleton so the development config looks something like:

declare(strict_types=1);

use Laminas\ConfigAggregator\ConfigAggregator;

$aggregator = new ConfigAggregator([
    function() {
        return [
            'debug'                        => true,
            ConfigAggregator::ENABLE_CACHE => false,
        ];
    }
]);

return $aggregator->getMergedConfig();

Existing applications that do not have this development config will continue to inject only to the main config/config.php.

boesing commented 1 year ago

@kynx did you used this PR in a project to actually verify integrative functionality? I do not have time for it, but I am not 100% sure from reviewing the PR if the installer is actually asking for adding it either to the development or production configuration.

kynx commented 1 year ago

@boesing Yes I've verified it works. If you've got time, give this a try:

git clone git@github.com:kynx/component-installer-demo.git
cd component-installer-demo
composer install

That's a minimal version of mezzio skeleton with mezzio/mezzio-tooling removed. Then:

composer require --dev mezzio/mezzio-tooling
<snip>

  Please select which config file you wish to inject 'Mezzio\Tooling\ConfigProvider' into:
  [0] Do not inject
  [1] config/development.config.php.dist
  [2] config/config.php
  Make your selection (default is 1):1

  Remember this option for other packages of the same type? (Y/n)
    Installing Mezzio\Tooling\ConfigProvider from package mezzio/mezzio-tooling

Selecting 1 has added the ConfigProvider to development.config.php.dist:

git --no-pager diff config
diff --git a/config/development.config.php.dist b/config/development.config.php.dist
index e6a4249..9917504 100644
--- a/config/development.config.php.dist
+++ b/config/development.config.php.dist
@@ -30,6 +30,7 @@ use Laminas\ConfigAggregator\ConfigAggregator;
 use Laminas\ConfigAggregator\PhpFileProvider;

 $aggregator = new ConfigAggregator([
+    \Mezzio\Tooling\ConfigProvider::class,
     new PhpFileProvider(realpath(__DIR__) . '/autoload/{,*.}{global,local}-development.php'),
     new ArrayProvider([
         'debug'                        => true,

Note that this does require there to be a ConfigAggregator in that file - as per https://github.com/mezzio/mezzio-skeleton/pull/122

boesing commented 1 year ago

LGTM, lets ship this. Thx, @kynx