Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/00f100/fcphp-di
Package to manage dependency injection
https://github.com/00f100/fcphp-di
dependency dependency-injection fcphp fcphp-di injection php7
Last synced: about 8 hours ago
JSON representation
Package to manage dependency injection
- Host: GitHub
- URL: https://github.com/00f100/fcphp-di
- Owner: 00F100
- License: mit
- Created: 2017-06-07T00:11:33.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-07-29T00:47:21.000Z (over 5 years ago)
- Last Synced: 2024-04-12T19:25:53.729Z (7 months ago)
- Topics: dependency, dependency-injection, fcphp, fcphp-di, injection, php7
- Language: PHP
- Homepage:
- Size: 75.2 KB
- Stars: 4
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# FcPhp Dependency Injection
Package to manage dependencies of project.
[![Build Status](https://travis-ci.org/00F100/fcphp-di.svg?branch=master)](https://travis-ci.org/00F100/fcphp-di) [![codecov](https://codecov.io/gh/00F100/fcphp-di/branch/master/graph/badge.svg)](https://codecov.io/gh/00F100/fcphp-di) [![Total Downloads](https://poser.pugx.org/00F100/fcphp-di/downloads)](https://packagist.org/packages/00F100/fcphp-di)
## How to install
Composer:
```sh
$ composer require 00f100/fcphp-di
```or add in composer.json
```json
{
"require": {
"00f100/fcphp-di": "*"
}
}
```## How to use
```php
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
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
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) {}
]);
```