I’m getting the following error on a new Mezzo install. On macOS using home-brew - I have tried with PHP 8.3 and 8.4.
Does anyone have an idea of the cause, please?
Tom
php bin/clear-config-cache.php
PHP Fatal error: Uncaught Laminas\ConfigAggregator\InvalidConfigProviderException: Mezzio\Helper\ConfigProvider is registered more than once. Config providers should be unique. In case a specific order is required, please double check before deleting the duplicate(s). in /Users/tom/Sites/mezzio/vendor/laminas/laminas-config-aggregator/src/InvalidConfigProviderException.php:15
Stack trace:
#0 /Users/tom/Sites/mezzio/vendor/laminas/laminas-config-aggregator/src/ConfigAggregator.php(117): Laminas\ConfigAggregator\InvalidConfigProviderException::fromDuplicateProvider('Mezzio\\Helper\\C...')
#1 /Users/tom/Sites/mezzio/vendor/laminas/laminas-config-aggregator/src/ConfigAggregator.php(85): Laminas\ConfigAggregator\ConfigAggregator->validateNoDuplicateProviders(Array)
#2 /Users/tom/Sites/mezzio/config/config.php(16): Laminas\ConfigAggregator\ConfigAggregator->__construct(Array, 'data/cache/conf...')
#3 /Users/tom/Sites/mezzio/bin/clear-config-cache.php(9): include('/Users/tom/Site...')
#4 {main}
thrown in /Users/tom/Sites/mezzio/vendor/laminas/laminas-config-aggregator/src/InvalidConfigProviderException.php on line 15
Fatal error: Uncaught Laminas\ConfigAggregator\InvalidConfigProviderException: Mezzio\Helper\ConfigProvider is registered more than once. Config providers should be unique. In case a specific order is required, please double check before deleting the duplicate(s). in /Users/tom/Sites/mezzio/vendor/laminas/laminas-config-aggregator/src/InvalidConfigProviderException.php:15
Stack trace:
#0 /Users/tom/Sites/mezzio/vendor/laminas/laminas-config-aggregator/src/ConfigAggregator.php(117): Laminas\ConfigAggregator\InvalidConfigProviderException::fromDuplicateProvider('Mezzio\\Helper\\C...')
#1 /Users/tom/Sites/mezzio/vendor/laminas/laminas-config-aggregator/src/ConfigAggregator.php(85): Laminas\ConfigAggregator\ConfigAggregator->validateNoDuplicateProviders(Array)
#2 /Users/tom/Sites/mezzio/config/config.php(16): Laminas\ConfigAggregator\ConfigAggregator->__construct(Array, 'data/cache/conf...')
#3 /Users/tom/Sites/mezzio/bin/clear-config-cache.php(9): include('/Users/tom/Site...')
#4 {main}
thrown in /Users/tom/Sites/mezzio/vendor/laminas/laminas-config-aggregator/src/InvalidConfigProviderException.php on line 15
Script php bin/clear-config-cache.php handling the clear-config-cache event returned with error code 255
Script @clear-config-cache was called via post-update-cmd
Install command and mezzio-skeleton version (3.15.0):
tom@tmbp sites % composer create-project mezzio/mezzio-skeleton mezzio
Creating a "mezzio/mezzio-skeleton" project at "./mezzio"
Installing mezzio/mezzio-skeleton (3.15.0)
- Installing mezzio/mezzio-skeleton (3.15.0): Extracting archive
Created project in /Users/tom/Sites/mezzio
> MezzioInstaller\OptionalPackages::install
Setting up optional packages
Setup data and cache dir
Removing installer development dependencies
At the top of the file you will see a use statement for Mezzio\Helper\ConfigProvider. Just remove it and its reference in the array. ConfigAggregator now checks to verify that each ConfigProvider is only registered once.
So to recap.
1 Remove the helper use statement.
2 Remove the entry in the array that references it, its the only ConfigProvider::class entry.
I wasn’t sure which file I should be modifying, so I searched the new Mezzo folder for “Mezzio\Helper\ConfigProvider” and the only occurrence was in the /config/config.php file - so I commented out line 8 and 19 as per below:
<?php
declare(strict_types=1);
use Laminas\ConfigAggregator\ArrayProvider;
use Laminas\ConfigAggregator\ConfigAggregator;
use Laminas\ConfigAggregator\PhpFileProvider;
//use Mezzio\Helper\ConfigProvider;
// To enable or disable caching, set the `ConfigAggregator::ENABLE_CACHE` boolean in
// `config/autoload/local.php`.
$cacheConfig = [
'config_cache_path' => 'data/cache/config-cache.php',
];
$aggregator = new ConfigAggregator([
\Mezzio\Tooling\ConfigProvider::class,
\Mezzio\LaminasView\ConfigProvider::class,
// \Mezzio\Helper\ConfigProvider::class,
\Mezzio\Router\FastRouteRouter\ConfigProvider::class,
\Laminas\HttpHandlerRunner\ConfigProvider::class,
// Include cache configuration
new ArrayProvider($cacheConfig),
ConfigProvider::class,
\Mezzio\ConfigProvider::class,
\Mezzio\Router\ConfigProvider::class,
\Laminas\Diactoros\ConfigProvider::class,
// Swoole config to overwrite some services (if installed)
class_exists(\Mezzio\Swoole\ConfigProvider::class)
? \Mezzio\Swoole\ConfigProvider::class
: function (): array {
return [];
},
// 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(realpath(__DIR__) . '/autoload/{{,*.}global,{,*.}local}.php'),
// Load development config if it exists
new PhpFileProvider(realpath(__DIR__) . '/development.config.php'),
], $cacheConfig['config_cache_path']);
return $aggregator->getMergedConfig();
Which now causes different error messages when, for example, trying to composer update:
> php bin/clear-config-cache.php
PHP Fatal error: Uncaught Laminas\ConfigAggregator\InvalidConfigProviderException: Cannot read config from ConfigProvider - class cannot be loaded. in /Users/tom/Sites/mezzio/vendor/laminas/laminas-config-aggregator/src/InvalidConfigProviderException.php:28
Stack trace:
#0 /Users/tom/Sites/mezzio/vendor/laminas/laminas-config-aggregator/src/ConfigAggregator.php(146): Laminas\ConfigAggregator\InvalidConfigProviderException::fromNamedProvider('ConfigProvider')
#1 /Users/tom/Sites/mezzio/vendor/laminas/laminas-config-aggregator/src/ConfigAggregator.php(260): Laminas\ConfigAggregator\ConfigAggregator->resolveProvider('ConfigProvider')
#2 /Users/tom/Sites/mezzio/vendor/laminas/laminas-config-aggregator/src/ConfigAggregator.php(86): Laminas\ConfigAggregator\ConfigAggregator->loadConfigFromProviders(Array)
#3 /Users/tom/Sites/mezzio/config/config.php(16): Laminas\ConfigAggregator\ConfigAggregator->__construct(Array, 'data/cache/conf...')
#4 /Users/tom/Sites/mezzio/bin/clear-config-cache.php(9): include('/Users/tom/Site...')
#5 {main}
thrown in /Users/tom/Sites/mezzio/vendor/laminas/laminas-config-aggregator/src/InvalidConfigProviderException.php on line 28
Fatal error: Uncaught Laminas\ConfigAggregator\InvalidConfigProviderException: Cannot read config from ConfigProvider - class cannot be loaded. in /Users/tom/Sites/mezzio/vendor/laminas/laminas-config-aggregator/src/InvalidConfigProviderException.php:28
Stack trace:
#0 /Users/tom/Sites/mezzio/vendor/laminas/laminas-config-aggregator/src/ConfigAggregator.php(146): Laminas\ConfigAggregator\InvalidConfigProviderException::fromNamedProvider('ConfigProvider')
#1 /Users/tom/Sites/mezzio/vendor/laminas/laminas-config-aggregator/src/ConfigAggregator.php(260): Laminas\ConfigAggregator\ConfigAggregator->resolveProvider('ConfigProvider')
#2 /Users/tom/Sites/mezzio/vendor/laminas/laminas-config-aggregator/src/ConfigAggregator.php(86): Laminas\ConfigAggregator\ConfigAggregator->loadConfigFromProviders(Array)
#3 /Users/tom/Sites/mezzio/config/config.php(16): Laminas\ConfigAggregator\ConfigAggregator->__construct(Array, 'data/cache/conf...')
#4 /Users/tom/Sites/mezzio/bin/clear-config-cache.php(9): include('/Users/tom/Site...')
#5 {main}
thrown in /Users/tom/Sites/mezzio/vendor/laminas/laminas-config-aggregator/src/InvalidConfigProviderException.php on line 28
Script php bin/clear-config-cache.php handling the clear-config-cache event returned with error code 255
Script @clear-config-cache was called via post-update-cmd
tom@tmbp mezzio %
Typical namespace problem. You cannot comment out the following line if it is used later.
Another variant:
use Laminas\ConfigAggregator\ArrayProvider;
use Laminas\ConfigAggregator\ConfigAggregator;
use Laminas\ConfigAggregator\PhpFileProvider;
$aggregator = new ConfigAggregator([
\Mezzio\Tooling\ConfigProvider::class,
\Mezzio\LaminasView\ConfigProvider::class,
\Mezzio\Helper\ConfigProvider::class,
\Mezzio\Router\FastRouteRouter\ConfigProvider::class,
\Laminas\HttpHandlerRunner\ConfigProvider::class,
// Include cache configuration
new ArrayProvider($cacheConfig),
\Mezzio\ConfigProvider::class,
\Mezzio\Router\ConfigProvider::class,
\Laminas\Diactoros\ConfigProvider::class,
// …