PHP code example of babacooll / imbrix

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

    

babacooll / imbrix example snippets




use Imbrix\DependencyManager;

$depManager = new DependencyManager();



$depManager->addService('myService', function () {
    return new MyService();
});



$depManager->get('myService');



$depManager->addParameter('myParameter', 'value');



$depManager->get('myParameter');



// Injection of a parameter into a service

$depManager = new DependencyManager();

$depManager->addParameter('myParameter', 'value');
$depManager->addService('myService', function ($myParameter) {
    return new MyService($myParameter);
});



$depManager = new DependencyManager();

$depManager->addParameter('myParameter', 'value');
$depManager->addService('myService', function ($myParameter) {
    return new MyService($myParameter);
});
$depManager->addService('mySecondService', function ($myService, $myParameter) {
    return new MySecondService($myService, $myParameter);
});

// We suppose MySecondService has both a getMyService() and a getParameter() method and the Service a getParameter()

echo $depManager->get('mySecondService')->getMyService()->getParameter();
echo $depManager->get('mySecondService')->getParameter();

// Both will return "value"

Shell
$ php composer.phar