PHP code example of thiagocordeiro / tiny-container

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

    

thiagocordeiro / tiny-container example snippets


$config = [
    UserRepositoryInterface::class => fn(ContainerInterface $container) => new DoctrineUserRepository(),
    CacheInterface::class => fn(ContainerInterface $container) => new RedisCache(),
    'http.api-client' => fn(ContainerInterface $container) => new GuzzleClient([]),
    MyService::class => fn(ContainerInterface $container) => new MyService(
        $container->get(UserRepositoryInterface::class),
        $container->get(CacheInterface::class),
        $container->get('http.api-client'),
    ),
];

$container = \TinyContainer\TinyContainer($config);

$service = $container->get(MyService::class);
$service->doTheThing();