Download the PHP package davidecesarano/embryo-container without Composer
On this page you can find all versions of the php package davidecesarano/embryo-container. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download davidecesarano/embryo-container
More information about davidecesarano/embryo-container
Files in davidecesarano/embryo-container
Package embryo-container
Short Description A simple and PSR-11 compatible Container.
License MIT
Homepage https://github.com/davidecesarano/embryo-container
Informations about the package embryo-container
Embryo Container
Embryo Container is a small and PSR-11 compatible Dependency Injection Container for PHP.
Requirements
- PHP >= 7.1
Installation
Using Composer:
Usage
Create Service
Services are defined by anonymous functions that return an instance of an object:
Note that the anonymous function has access to the current container instance.
Using Service
Using the defined services:
Automatic Injection
Container can automatically create and inject dependencies with Autowiring. Autowiring is enabled by default. You can disable it using the container builder:
Autowiring is the ability of the container to automatically create and inject dependencies. Embryo Container uses PHP's reflection to detect what parameters a constructor needs.
In this example, Embryo Container creates a Person
instance (if it wasn't already created) and pass it as a constructor parameter.
Service Provider
Embryo Container can defines a service into a provider extending ServiceProvider
instance:
Example
You may quickly test this using the built-in PHP server:
Going to http://localhost:8000.