dev-master
9999999-dev https://github.com/fuelphp/dependencyFuel Dependency package based on League\Container
MIT
The Requires
- php >=5.4
- league/container ^2.0
The Development Requires
by FuelPHP Development Team
dependency injection dependencies
Wallogit.com
2017 © Pedro Peláez
Fuel Dependency package based on League\Container
Fuel Dependency package based on League\Container., (*2)
The Dependency package is an extension of League\Container responsible for handling dependencies in FuelPHP framework. Most of the functionalities are the same, but there are some custom ones as well. It means that we don't encourage anyone to use this package on it's own since the additions are mostly FuelPHP specific., (*3)
This documentation covers the basic usage of the Container, also the added features. For full documentation check the original documentation., (*4)
The container is the primary component of the dependency package and ties all the parts together. You can look at this as the (PHP) object store. The container is where you register resources, service providers and retrieve dependencies., (*5)
``` php $container = new Fuel\Dependency\Container;, (*6)
### Definitions A definition is either a class string name or a closure which returns an instance or a class name. #### String definition ``` php // Register $container->add('string', 'stdClass'); // Resolve $instance = $container->get('string');
``` php // Register $container->add('closure.object', function() { return new stdClass; });, (*7)
// Resolve $instance = $container->get('closure.object');, (*8)
### Service Providers Service providers are used to expose packages to the Container. A Service Provider can provide the container with resources but also act on a namespace. A namespace is a string prefix which maps identifiers to the providers factory method. ``` php use League\Container\ServiceProvider; class MyProvider extends ServiceProvider { protected $provides = ['some.identifier', 'other.resource']; public function register() { $this->container->add('some.identifier', 'stdClass'); $this->container->singleton('other.resource', function() { return new Something($this->container->resolve('database.connection')); )); } }
Fuel adds two main functionalities to the Container:, (*9)
``` php // Register $container->add('closure::object1', function() { return new stdClass; }); $container->add('closure::object2', function() { return new stdClass; });, (*10)
// Resolve object1 = $container->multiton('closure', 'object1'); objects = $container->multiton('closure');, (*11)
#### Forge ``` php // Register $container->singleton('closure.object', function() { return new stdClass; }); // Resolve // Always returns a newly resolved definition $instance = $container->forge('closure.object');
Thank you for considering contribution to FuelPHP framework. Please see CONTRIBUTING for details., (*12)
The MIT License (MIT). Please see License File for more information., (*13)
Fuel Dependency package based on League\Container
MIT
dependency injection dependencies