PHP code example of digit-soft / re-action-di

1. Go to this page and download the library: Download digit-soft/re-action-di 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/ */

    

digit-soft / re-action-di example snippets


//Creation
$container = new \Reaction\DI\Container([
    'definitions' => [
        'componentId' => [
            'class' => 'Component\Class\Path',
            'property_1' => 1,
            'property_2' => InstanceOf('Component\Class\Path2'),
        ],
        //Alias
        'componentAlias' => 'componentId',
    ],
    'singletons' => [
        'componentId2' => 'componentId2',
    ],
]);
//Set entry
$container->set('component', ['class' => '...'], [...]);
//Get entry
$cmp  = $container->get('componentId');
//Singletons
$cmp2 = $container->get('componentId2');
$cmp3 = $container->get('componentId2');
echo $cmp2 === $cmp3; //TRUE