How to Use laminas-config-aggregator In Slim

Hi, i want to use laminas-config-aggregator inside my slim app but it’s not working
as i don’t have the needed know to make it work,
This is what i have done so far.

<?php

declare(strict_types=1);

namespace Ultral\Config;

use Laminas\ConfigAggregator\ConfigAggregator;
use Laminas\ConfigAggregator\PhpFileProvider;

class AppConfig {

    public function __construct(Config $config)
    {
        $this->config = $config;
    }

     /**
     * @return mixed
     */
    public function getConfigAggregator($MergedConfig): Aggregator
    {
        $aggregator = new ConfigAggregator([
            new PhpFileProvider('/../../config/*.php'),
        ]);

        return ($aggregator->getMergedConfig()) ? $this->config : $this->config[$MergedConfig];
    }
    
}

This is the class to configure Laminas-config and to load the nedded config files and merged them.

And inside my container.php file i want to get the merged files and use them.

// Config
    AppConfig::class => function (ContainerInterface $container) {
        return new PhpFileProvider($container->get(App::class));
    },

Please help me.
Thanks.

I have quickly checked the documentation and your code examples and I would refactor it like this.

First try to fix the DI container definition, because you have to return the correct object.

use Laminas\Config\Config;
use Laminas\ConfigAggregator\ConfigAggregator;
use Laminas\ConfigAggregator\PhpFileProvider;
// ...

Config::class => function () {
    $aggregator = new ConfigAggregator([
        new PhpFileProvider(__DIR__ . '/../config/*.php')
    ]);

    return new Config($aggregator->getMergedConfig());
}

With this definition you don’t need an extra wrapper class like AppConfig.

1 Like

Thanks a lot.
I was very confused at first.