2017 © Pedro Peláez
 

package fcphp-di

Dependency Injection for FcPHP

image

00f100/fcphp-di

Dependency Injection for FcPHP

  • Tuesday, July 24, 2018
  • by 00F100
  • Repository
  • 1 Watchers
  • 0 Stars
  • 100 Installations
  • PHP
  • 3 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 7 Versions
  • 37 % Grown

The README.md

FcPhp Dependency Injection

Package to manage dependencies of project., (*1)

Build Status codecov Total Downloads, (*2)

How to install

Composer:, (*3)

$ composer require 00f100/fcphp-di

or add in composer.json, (*4)

{
    "require": {
        "00f100/fcphp-di": "*"
    }
}

How to use

<?php

use FcPHP\Di\Facades\DiFacade;

$di = DiFacade::getInstance();

/**
 * Method to set new class
 *
 * @param string $id Identify of instance
 * @param string $namespace Namespace of class
 * @param array $args Args to construct class
 * @return void
 */
$di->set(string $id, string $namespace, array $args = [], array $setters = [], bool $singleton = true);

/**
 * Method to overwrite instance before make
 *
 * @param string $id Identify instance
 * @param string $namespace Namespace of class
 * @param array $args Args to construct class
 * @param array $setters Setters to class
 * @return FcPhp\Di\Interfaces\IDi
 */
$di->overwrite(string $id, string $namespace, array $args = [], array $setters = []) ;

/**
 * Method to get instance of Container
 *
 * @param string $id Identify of instance
 * @param array $args Args to construct instance
 * @return FcPhp\Di\Interfaces\IContainer
 */
$di->get(string $id, array $args = [], array $setters = []);

/**
 * Method to configure setters to class
 *
 * @param string $id Identify instance
 * @param array $setters Setters to class
 * @return FcPhp\Di\Interfaces\IDi
 */
$di->setter(string $id, array $setters);

/**
 * Method instance of class
 *
 * @param string $id Identify of instance
 * @param array $args Args to construct instance
 * @return mixed
 */
$di->make(string $id, array $args = [], array $setters = []);

Examples

<?php

use FcPHP\Di\Facades\DiFacade;

$di = DiFacade::getInstance();

/*
namespace Namespace\To {
    class Example {
        public $foo;
        private $anotherFoo;
        public function __construct(string $foo) {
            $this->foo = $foo;
        }
        public function setAnotherFoo($foo) {
            $this->anotherFoo = $foo;
        }
        public functio getAnotherFoo() {
            return $this->anotherFoo;
        }
    }
    class ExampleBar {
        public $example;
        __construct(Example $example) {
            $this->example = $example;
        }
    }
}
*/
$di->set('Example', 'Namespace\To\Example', ['foo' => 'bar'], ['setAnotherFoo', 'AnotherBar']);
$di->set('ExampleBar', 'Namespace\To\ExampleBar', ['example' => $di->get('Example')]);

// Print "bar"
echo $di->make('ExampleBar')->example->foo

// Print "AnotherBar"
echo $di->make('ExampleBar')->example->getAnotherFoo();

Events

<?php

use FcPHP\Di\Facades\DiFacade;
use FcPhp\Di\Interfaces\IInstance;
use FcPhp\Di\Interfaces\IContainer;

$di = DiFacade::getInstance();

$di->event([
    'beforeSet' => function(string $id, string $namespace, array $args, array $setters, bool $singleton) {

    },
    'afterSet' => function(string $id, string $namespace, array $args, array $setters, bool $singleton, IInstance $instance) {

    },
    'beforeGet' => function(string $id, array $args, array $setters) {

    },
    'afterGet' => function(string $id, array $args, array $setters, IInstance $instance, IContainer $container) {

    },
    'beforeMake' => function(string $id, array $args, array $setters) {

    },
    'afterMake' => function(string $id, array $args, array $setters, IInstance $instance, IContainer $container, $class) {

    }
]);

The Versions

24/07 2018

dev-master

9999999-dev https://github.com/00f100/fcphp-di

Dependency Injection for FcPHP

  Sources   Download

The Requires

  • php >=7.2

 

The Development Requires

php dependency di injection fcphp

24/07 2018

0.3.0

0.3.0.0 https://github.com/00f100/fcphp-di

Dependency Injection for FcPHP

  Sources   Download

The Requires

  • php >=7.2

 

The Development Requires

php dependency di injection fcphp

24/06 2018

0.2.2

0.2.2.0 https://github.com/00f100/fcphp-di

Dependency Injection for FcPHP

  Sources   Download

The Requires

  • php 7.2.*

 

The Development Requires

php dependency di injection fcphp

13/06 2018

0.2.1

0.2.1.0 https://github.com/00f100/fcphp-di

Dependency Injection for FcPHP

  Sources   Download

The Requires

  • php 7.2.*

 

The Development Requires

php dependency di injection fcphp

12/06 2018

0.2.0

0.2.0.0 https://github.com/00f100/fcphp-di

Dependency Injection for FcPHP

  Sources   Download

The Requires

  • php 7.2.*

 

The Development Requires

php dependency di injection fcphp

12/06 2018

dev-feature/setter

dev-feature/setter https://github.com/00f100/fcphp-di

Dependency Injection for FcPHP

  Sources   Download

The Requires

  • php 7.2.*

 

The Development Requires

php dependency di injection fcphp

10/06 2018

0.1.1

0.1.1.0 https://github.com/00f100/fcphp-di

Dependency Injection for FcPHP

  Sources   Download

The Requires

  • php 7.2.*

 

The Development Requires

php dependency di injection fcphp