PHP code example of php-component / di

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

    

php-component / di example snippets


class Translator
{
    /** @var string */
    private $default_language;
    
    public function __construct($default_language)
    {
        $this->default_language = $default_langauge;
    }
}

$parameters = new \PHPComponent\DI\ParametersBag(array('default_language' => 'en'));
$container_builder = new \PHPComponent\DI\ContainerBuilder($parameters);
$container_builder->registerService('translator', Translator::class)
    ->setArguments(array('%default_language%'));
$translator = $container_builder->getService('translator');