Download the PHP package ronanchilvers/container without Composer
On this page you can find all versions of the php package ronanchilvers/container. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download ronanchilvers/container
More information about ronanchilvers/container
Files in ronanchilvers/container
Package container
Short Description A very simple, PSR-11 compatible container
License MIT
Informations about the package container
container
A simple, small PSR-11 compliant container for PHP 7+. It has the following features:
- Factory and shared definitions
- Support for non object services (ie: storing key values)
- Aliases
- Autowiring
Installation
The easiest way to install is via composer:
Usage
Basic usage is simple:
By default services added to the container are factory services - you'll get a new one every time. If you want to define a shared service you can do:
You can also register primitives with the container:
Aliases
Sometimes its useful to be able to alias a service. For example if you want to register a service with a simple string name but also refer to it by an interface name. To do this you can use a Symfony style prefix on the definition to indicate that its a reference to another service.
Here's an example:
Extending services
The container allows services to be extended (just like Pimple) using the extend()
method. You can extend both factory and shared services. Call extend()
with the service id and a callable. The callable will recieve the service instance as its first argument and the container as the second. You can extend a service as many times as you like.
Autowiring
The container supports basic autowiring. This means that you can supply a fully qualified class name as a service definition and the container will attempt to instantiate it for you.
Constructor injection is also supported for type hinted parameters.
The injected objects do not have to be registered with the container to be injected. If the container encounters a dependency that is not defined as a service it will attempt to create a new instance with no constructor parameters.
Service Providers
The container supports pimple style service providers. Your provider must implement .
Testing
The container is quite simple and has 100% test coverage. You can run the tests by doing:
The default phpunit.xml.dist file creates coverage information in a build/coverage subdirectory.
Contributing
If anyone has any patches they want to contribute I'd be more than happy to review them. Please raise a PR. You should:
- Follow PSR2
- Maintain 100% test coverage or give the reasons why you aren't
- Follow a one feature per pull request rule
License
This software is licensed under the MIT license. Please see the License File for more information.