PHPackages                             ellipse/container-reflection - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [PSR &amp; Standards](/categories/psr-standards)
4. /
5. ellipse/container-reflection

ActiveLibrary[PSR &amp; Standards](/categories/psr-standards)

ellipse/container-reflection
============================

Psr-11 container decorator providing autowiring feature

1.0.4(8y ago)01611MITPHPPHP &gt;=7.0

Since Dec 6Pushed 8y ago1 watchersCompare

[ Source](https://github.com/ellipsephp/container-reflection)[ Packagist](https://packagist.org/packages/ellipse/container-reflection)[ Docs](https://github.com/ellipsephp/container-reflection)[ RSS](/packages/ellipse-container-reflection/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependencies (4)Versions (6)Used By (1)

Reflection container
====================

[](#reflection-container)

This package provides a **[Psr-11 container](http://www.php-fig.org/psr/psr-11/)** decorator enabling **auto-wiring** to any Psr-11 container implementation.

**Require** php &gt;= 7.0

**Installation** `composer require ellipse/container-reflection`

**Run tests** `./vendor/bin/kahlan`

- [Getting started](#getting-started)
- [Restricted auto wiring](#restricted-auto-wiring)

Getting started
---------------

[](#getting-started)

This package provides an `Ellipse\Container\ReflectionContainer` class which can be used to decorate any Psr-11 container. By default it enables auto wiring for all the existing classes, modifying the behaviors of the original container `->has()` and `->get()` methods:

The `->has()` method now returns true for aliases contained in the original container but also when the given alias is an existing class name.

The `->get()` method returns the value contained in the original container when the given alias is defined. Otherwise when the alias is an existing class name then auto wiring is used to return an new instance of this class. It means php reflection feature is used to extract the class constructor parameters and the reflection container `->get()` method is called to retrieve a value for all parameters type hinted as a class name. For the other parameters their default values are used. Once a value is retrieved for all the class constructor parameters, a new instance of the class is built using those values. When called multiple times, the same instance of the class is returned like any Psr-11 container would do.

This auto wiring feature [can be restricted](#restricted-auto-wiring) to classes implementing a specified list of interfaces.

```
