PHP code example of ryanl / flexer

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

    

ryanl / flexer example snippets


$container = new \Flexer\Container();

$container = new \Flexer\Container([
   $id => $definition 
]);

$container = new \Flexer\Container();
$container->add($id, $definition)

$container = new \Flexer\Container();
$container->add(\Test\Sample\NormalClass::class, $definition)

$definition = fn() => new \Test\Sample\NormalClass();
$container->add($id, $definition);

function getNormalClassInstance(): \Test\Sample\NormalClass
{
    return new \Test\Sample\NormalClass();
}
$container->add($id, 'getNormalClassInstance');

$container->add($id, \Test\Sample\NormalClass::create(...));

$container->add($id, new \Test\Sample\NormalClass());

# dependencies.php



declare(strict_types=1);

return [
    \Test\Sample\NormalClass::class => fn () => new \Test\Sample\NormalClass(),
    \PDO::class => function (): \PDO {
        return new PDO('sqlite::memory');
    }
];

# index.php



declare(strict_types=1);

$container = new \Flexer\Container(
bash
composer analyse