Download the PHP package gravatalonga/container without Composer
On this page you can find all versions of the php package gravatalonga/container. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download gravatalonga/container
More information about gravatalonga/container
Files in gravatalonga/container
Package container
Short Description Implementation of PSR-11 Container, it is lightweight yet powerful. Feature such as Lazy Factory, Factory, Optinal Share of Services, Array Access and other it can be very versatile.
License MIT
Informations about the package container
Container
Container implementation which follow PSR-11.
Requirements
PHP | VERSION | Container Version |
---|---|---|
8.0 < | <= 1.6 | 1.0 |
>= 8.0 | >= 1.7 | 1.0 |
>= 8.0 | >= 1.8 | 2.0 |
Installation
Usage
Basic Usage
When creating a new instance of Container, you can pass on first argument configurations or entries to be already bonded into container.
Using Service Provider
When using set
, factory
or share
with Closure and if you want to get Container
it's self, you can pass type hint of ContainerInterface
as argument.
Using Array like access
Alias
Alias like the name show, it to make a possibility to make an alias from one entry to another. It will throw an exception if can't be found.
Callable as alternative
Extend
In order implementation to be ease for other services providers extend
method was created.
Advance usage
Container is capable to resolve class who isn't bounded, it will resolve dependencies from __construct
type-hint/built-in which is bounded. Read example code below:
Information: built-in is type which is built in on PHP, which is
string
,int
,boolean
, etc. Type Hint is type which is created by user land, such as, when creating a class you are creating a new type.
Using Type Hint Class
Note: We only support resolving auto wiring argument on construction if they are bounded into container. Otherwise it will throw an exception if can't find entry.
Using Built in type
If argument accept nullable if can't be resolve it will pass default value which in this case is null
.
In also attempt to resolve auto wiring of construction by its default value, it will check default value of __construct
and it will pass that default value.
First case, if value is a simple built-in type value.
Tip
It's well-known that using singleton pattern, it's an anti-pattern. But small feature can't hurt you
So, you can use:
Then you can get instance of container,
Tips: The container can detected circular dependencies.
Change log
Please see CHANGELOG for more information on what has changed recently.
Testing
Contributing
Please see CODE_OF_CONDUCT for details.
Security
If you discover any security related issues, please email jonathan.alexey16[at]gmail.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.