PHP code example of laminas / laminas-pimple-config

1. Go to this page and download the library: Download laminas/laminas-pimple-config library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

laminas / laminas-pimple-config example snippets



use Laminas\Pimple\Config\Config;
use Laminas\Pimple\Config\ContainerFactory;

$factory = new ContainerFactory();

$container = $factory(
    new Config([
        'dependencies' => [
            'services'          => [],
            'invokables'        => [],
            'factories'         => [],
            'aliases'           => [],
            'delegators'        => [],
            'extensions'        => [],
            'shared'            => [],
            'shared_by_default' => true,
        ],
        // ... other configuration
    ])
);

> $config = $container->get('config');
> 

use Psr\Container\ContainerInterface;

public function __invoke(
    $service,
    ContainerInterface $container,
    $name
);

use Psr\Container\ContainerInterface;

class ExtensionFactory
{
    public function __invoke($service, ContainerInterface $container, $name)
    {
        // do something with $service

        return $service;
    }
}

use Psr\Container\ContainerInterface;

class ExtensionFactory
{
    public function __invoke($service, ContainerInterface $container, $name)
    {
        return new Decorator($service);
    }
}

new Config([
    'dependencies' => [
        'invokables' => [
            'my-service' => MyInvokable\Service::class,
        ],
        'extensions' => [
            'my-service' => [
                Extension1Factory::class,
                Extension2Factory::class,
                // ...
            ],
        ],
    ],
]);



use Laminas\Pimple\Config\Config;
use Laminas\Pimple\Config\ContainerFactory;

$config  =