2017 © Pedro Peláez
 

library di

PHP 7.0 Dependency Container Implementation.

image

fitdev-pro/di

PHP 7.0 Dependency Container Implementation.

  • Thursday, March 8, 2018
  • by fitdev-pro
  • Repository
  • 0 Watchers
  • 0 Stars
  • 15 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 7 Versions
  • 0 % Grown

The README.md

FitDI

PHP 7.0 Dependency Container Implementation., (*1)

Installation

composer require fitdev-pro/di

Usage

Base usage, (*2)

<?php

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();
}

Create complicated services, (*3)

<?php

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')]),
    ],
]
);

Contribute

Please feel free to fork and extend existing or add new plugins and send a pull request with your changes! To establish a consistent code quality, please provide unit tests for all your changes and may adapt the documentation., (*4)

License

The MIT License (MIT). Please see License File for more information., (*5)

The Versions

08/03 2018

dev-master

9999999-dev https://fitdev.pro

PHP 7.0 Dependency Container Implementation.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Karol Kondraciuk

08/03 2018

1.1.0

1.1.0.0 https://fitdev.pro

PHP 7.0 Dependency Container Implementation.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Karol Kondraciuk

19/07 2017

1.0.4

1.0.4.0 https://fitdev.pro

PHP 7.0 Dependency Container Implementation.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Karol Kondraciuk

11/07 2017

1.0.3

1.0.3.0 https://fitdev.pro

PHP 7.0 Dependency Container Implementation.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Karol Kondraciuk

07/07 2017

1.0.2

1.0.2.0 https://fitdev.pro

PHP 7.0 Dependency Container Implementation.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Karol Kondraciuk

07/07 2017

1.0.1

1.0.1.0 https://fitdev.pro

PHP 7.0 Dependency Container Implementation.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Karol Kondraciuk

06/07 2017

1.0.0

1.0.0.0 https://fitdev.pro

PHP 7.0 Dependency Container Implementation.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Karol Kondraciuk