PHPackages                             kenphp/container - 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. [Framework](/categories/framework)
4. /
5. kenphp/container

ActiveLibrary[Framework](/categories/framework)

kenphp/container
================

PSR-11 compliant PHP container

1.0.1(7y ago)06011MITPHPPHP &gt;=7.0.0

Since Jan 16Pushed 7y ago1 watchersCompare

[ Source](https://github.com/kenphp/container)[ Packagist](https://packagist.org/packages/kenphp/container)[ RSS](/packages/kenphp-container/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependencies (3)Versions (3)Used By (1)

Container [![Build Status](https://camo.githubusercontent.com/5a6cca3d3f12c978f8bd23ff6016883b2f59587b88cba8bf3e0887837cf89c02/68747470733a2f2f7472617669732d63692e6f72672f6b656e7068702f636f6e7461696e65722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/kenphp/container)
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

[](#container-)

A simple PSR-11 compliant PHP container. This library is part of KenPHP Project, but can be used independently.

Requirements
------------

[](#requirements)

- PHP 7.0 or greater

Instalation
-----------

[](#instalation)

The easiest way to install is using Composer

```
$ composer require kenphp/container

```

Methods
-------

[](#methods)

List of available methods :

- `get($id)`

    Finds an entry of the container by its identifier and returns it.
- `has($id)`

    Returns true if the container can return an entry for the given identifier. Returns false otherwise.
- `set($id, $item)`

    Sets an item into container. The `item` can be a value or a function. If the function returns an object, it will be treated as a singleton.
- `setFactory($id, callable $factory)`

    Sets an object factory. The `factory` must be an instance of `callable` that returns an object and the `factory` will be called whenever the item is fetched using `get` method.

Example
-------

[](#example)

```
