Download the PHP package moro/container7 without Composer
On this page you can find all versions of the php package moro/container7. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download moro/container7
More information about moro/container7
Files in moro/container7
Package container7
Short Description Dependency Injection container for PHP-7
License MIT
Informations about the package container7
Container7
Container7 is a medium Dependency Injection Container for PHP-7.
This package is compliant with PSR-1, PSR-2, PSR-4 and PSR-11. If you notice compliance oversights, please send a patch via pull request.
Features: providers, singletons, factories, parameters, aliases, tags, configuration, serialization.
Install
Via composer
$ composer require moro/container7
Requirements
- PHP 7.1
Usage
Creating a container is a matter of creating a Container instance:
As many other dependency injection containers, Container7 manages two different kind of data: services and parameters. Services receives from container by their class or alias. Parameters stores in their service "parameters".
For service definition used Service Providers.
Service Providers allow you to package code or configuration for packages that you reuse regularly.
Service provider
Any Service Provider is simple PHP class. Services are defined by methods that return an instance of an object. You must define results of this methods as class or interface. And then you can receive service by that class or interface.
Singleton
Factory
If you want define factory - add variadic argument.
Dependencies
When your service require other, you can add this dependency to method arguments.
Remember, that parameters is service too:
Modifying Services after Definition
In some cases you may want to modify a service definition after it has been defined. You can use method that receive service object and can return null.
If you need to replace the service instance use that definition:
You can add dependencies here as in the definition of factories.
Parameters
Add default parameters.
Set current values of parameters, that replace default values.
And use it.
Aliases
When you can not get service by class or interface, then you must define alias for class, interface or method.
Now you can get service by alias.
Tags
You can group services by setting a common tag for them.
And then get a collection of the services.
Collection implements Iterator interface and you can use it in foreach.
Manipulation with collection
Configuration
Container7 support configuration files in JSON format. You can create provider from that files.
Configuration files can be nested.
Singleton
Factory
Dependencies
Modifying Services after Definition
If you need to replace the service instance use that definition:
Parameters, Aliases and Tags
Dynamic services
License
The MIT License (MIT). Please see License File for more information.