1. Go to this page and download the library: Download fitdev-pro/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/ */
fitdev-pro / di example snippets
use FitdevPro\DI\Creators\CreatorFactory;
use FitdevPro\DI\DependencyContainer;
$dc = new DependencyContainer(new CreatorFactory());
//add service
$dc->add('config', new stdClass());
//check if service exists
if($dc->has('config'))
{
//get service
$config = $dc->get('config');
//OR
$config = $dc->getConfig();
}
use FitdevPro\DI\Creators\CreatorFactory;
use FitdevPro\DI\DependencyContainer;
use FitdevPro\DI\Options\Actions\CallMethod;
use FitdevPro\DI\Options\Actions\SetProperty;
use FitdevPro\DI\Options\Values\ClassValue;
use FitdevPro\DI\Options\Values\ServiceValue;
use FitdevPro\DI\Options\Values\Value;
$dc = new DependencyContainer(new CreatorFactory());
//add service
$dc->add('bar', \MyFoo\Bar::class,
[
"arguments" => [ // inject to constructor
new Value(123), //simply value
new ServiceValue($dc, 'serviceName'), //other service
new ClassValue('Foo\Bar\Bazz'), //new object of some class
],
"properties" => [ // inject to property
new SetProperty('foo', new Value(123)),
new SetProperty('bar', new ServiceValue($dc, 'serviceName')),
new SetProperty('bazz', new ClassValue('Foo\Bar\Bazz')),
],
"calls" => [ // call service method with arguments
new CallMethod('setFoo', [new ServiceValue($dc, 'serviceName'), new Value('abc')]),
],
]
);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.