PHPackages                             acclimate/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. [PSR &amp; Standards](/categories/psr-standards)
4. /
5. acclimate/container

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

acclimate/container
===================

Provides adapters for various third-party service containers.

2.0.0(9y ago)219390.6k—3.8%17[2 issues](https://github.com/AcclimateContainer/acclimate-container/issues)[2 PRs](https://github.com/AcclimateContainer/acclimate-container/pulls)15MITPHPPHP &gt;=5.6.0

Since Sep 25Pushed 2y ago12 watchersCompare

[ Source](https://github.com/AcclimateContainer/acclimate-container)[ Packagist](https://packagist.org/packages/acclimate/container)[ RSS](/packages/acclimate-container/feed)WikiDiscussions 2.x Synced 1mo ago

READMEChangelog (7)Dependencies (10)Versions (10)Used By (15)

Acclimate - Container Adapters
==============================

[](#acclimate---container-adapters)

[![License](https://camo.githubusercontent.com/dcb2eddd2fc1ddf796c404cbd535c77e0acca74341eeac17b9aa80b88f5c2e78/68747470733a2f2f706f7365722e707567782e6f72672f6163636c696d6174652f636f6e7461696e65722f6c6963656e73652e706e67)](https://packagist.org/packages/acclimate/container) [![Latest Stable Version](https://camo.githubusercontent.com/4ca8965cc162f7fa74d9c1192429b9cdd5fbf5c6948ad627ee04ceffbed76e65/68747470733a2f2f706f7365722e707567782e6f72672f6163636c696d6174652f636f6e7461696e65722f762f737461626c652e706e67)](https://packagist.org/packages/acclimate/container) [![Build Status](https://camo.githubusercontent.com/01a43249c1d3e6df8c743b52d37d3369100a236d9f7cb00ca04392ef6cbab0e5/68747470733a2f2f7472617669732d63692e6f72672f6a6572656d65616d69612f6163636c696d6174652d636f6e7461696e65722e706e67)](https://travis-ci.org/jeremeamia/acclimate-container) [![Code Coverage](https://camo.githubusercontent.com/47a1936184036bfe53cee7d526171a552a17b82fac0396d05998fcf1428afda2/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6a6572656d65616d69612f6163636c696d6174652d636f6e7461696e65722f6261646765732f636f7665726167652e706e673f733d66653131373632653363373664393266666264346137323230653662373263393538643632623431)](https://scrutinizer-ci.com/g/jeremeamia/acclimate-container/) [![Scrutinizer Code Quality](https://camo.githubusercontent.com/71bea3c136eb3ad5b8c0480c71905b6c529ea1b12e06d5b7c42b4ee222aa2f19/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6a6572656d65616d69612f6163636c696d6174652d636f6e7461696e65722f6261646765732f7175616c6974792d73636f72652e706e673f733d33306363303137633861353366353066656335623562656364376161363438393330623961316330)](https://scrutinizer-ci.com/g/jeremeamia/acclimate-container/)

**Get Acclimated!** Use any third-party dependency injection containers and service locators in your code by adapting them to a common container interface. Acclimate was created by [Jeremy Lindblom](https://twitter.com/jeremeamia).

Introduction
------------

[](#introduction)

It seems like every framework has its own container object. They come in many shapes and sizes (service locator, service manager, service container, dependency injection (DI) container, registry, etc.), but are all generally used in a similar way.

The wide variety of implementations makes it hard for other frameworks, framework-agnostic libraries, or some applications to get the full benefits of using an inversion of control (IoC) system, because they either need to:

1. Write their own container implementation (NIH Syndrome)
2. Have a long-term dependency on a particular, third-party container implementation (and force that dependency on their users, which may already be using a different container implementation)
3. Implement an abstraction layer to support one or more third-party containers

**Acclimate** is a library that does #3 for you. It provides a set of adapters for the most popular container implementations. This allows you to adapt, *or "acclimate"*, instances of these containers to a common, normalized, and **interoperable** interface. Using Acclimate allows your framework, library, or application to retrieve items from the container objects of third-party libraries. That's interoperability!

The Container Interface
-----------------------

[](#the-container-interface)

The `ContainerInterface` used by Acclimate comes from the [`psr/container`](https://github.com/php-fig/container) project. It attempts to normalize the various implementations of container interfaces (whether they be for service locators, dependency injection containers, or something else similar) to a simple, readonly interface, that allows users to retrieve entries from any third-party container in a consistent way.

Acclimate v1 and previous use the similar [`container-interop/container-interop`](https://github.com/container-interop/container-interop) standard

The `ContainerInterface` looks like this:

```
namespace Psr\Container;

interface ContainerInterface
{
    /**
     * @param string $id
     * @return mixed
     * @throws NotFoundException
     * @throws ContainerException
     */
    public function get($id);

    /**
     * @param string $id
     * @return bool
     */
    public function has($id);
}
```

Installation
------------

[](#installation)

Install the `acclimate/container` package using Composer. This will also also install `psr/container`, which provides the `ContainerInterface`.

**Warning:** If you install Acclimate with dev dependencies, you will get A LOT of packages from various frameworks (e.g., ZF, Symfony, Laravel, etc.). These packages are *required for testing only* to ensure that all of the adapter classes work correctly. They are not included when you run Composer with `--no-dev`.

**Note:** We recommend using Composer and Composer's autoloader to load this library. If you are not using Composer's autoloader, be sure to use a PSR-4 compliant autoloader and map the namespace prefix `Acclimate\Container\` to the `src/` directory in order to correct autoload the classes.

Basic Usage
-----------

[](#basic-usage)

**Acclimate: Container** provides a `ContainerAcclimator` object that is used to adapt a container object to a normalized `ContainerInterface`. In terms of design patterns, it's essentially a factory for adapters.

Here is an example of how to use the `ContainerAcclimator`:

```
