PHP code example of aicrion / container

1. Go to this page and download the library: Download aicrion/container 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/ */

    

aicrion / container example snippets


use Aicrion\Container\Container;

$container = new Container();

$container->singleton(Logger::class);
$container->bind(LoggerInterface::class, Logger::class);
$container->alias('logger', LoggerInterface::class);

$userService = $container->make(UserService::class);

use Aicrion\Container\Service;

class ServiceA extends Service
{
    public ServiceB $b;

    public function injectDependencies(ServiceB $b): void
    {
        $this->b = $b;
    }
}

class ServiceB extends Service
{
    public ServiceA $a;

    public function injectDependencies(ServiceA $a): void
    {
        $this->a = $a;
    }
}

$container->singleton(ServiceA::class);
$container->singleton(ServiceB::class);

$a = $container->make(ServiceA::class); // fully wired, no exceptions