PHP code example of kodcube / dependency-injection
1. Go to this page and download the library: Download kodcube/dependency-injection 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/ */
kodcube / dependency-injection example snippets
PHP
$di = new KodCube\DependencyInjection\Container();
or
$di = new KodCube\DependencyInjection\Container($config);
or
$di = new KodCube\DependencyInjection\Container([
'MyAlias' => 'Vendor\Package\Class',
'Vendor\Package\Interface' => 'Vendor\Package\Class'
])
PHP
$object = $di->get('Vendor\Package\Class');
or
$object = $di('Vendor\Package\Class');
PHP
$object = $di->get('Vendor\Package\Interface');
or
$object = $di('Vendor\Package\Interface');
PHP
Alias
$object = $di->has('MyAlias');
Class
$object = $di->has('Vendor\Package\Class');