PHPackages                             alex-patterson-webdev/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. alex-patterson-webdev/container

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

alex-patterson-webdev/container
===============================

Simple implementation of the PSR-11 dependency injection container

0.1.0(2y ago)212[1 issues](https://github.com/alex-patterson-webdev/container/issues)[1 PRs](https://github.com/alex-patterson-webdev/container/pulls)PHPPHP &gt;=7.4 || &gt;=8.0CI failing

Since May 29Pushed 3mo ago2 watchersCompare

[ Source](https://github.com/alex-patterson-webdev/container)[ Packagist](https://packagist.org/packages/alex-patterson-webdev/container)[ RSS](/packages/alex-patterson-webdev-container/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (1)Dependencies (2)Versions (3)Used By (0)

[![Build Status](https://camo.githubusercontent.com/f2ae9dbd0db594985f8e51c0cf83227c602536794a7d0edb80bd6bfbed1ce64c/68747470733a2f2f7472617669732d63692e636f6d2f616c65782d706174746572736f6e2d7765626465762f636f6e7461696e65722d61727261792e7376673f6272616e63683d6d6173746572)](https://travis-ci.com/alex-patterson-webdev/container)[![codecov](https://camo.githubusercontent.com/ce1bf02ab31adfff4b76b82db6a9475a043f3f118d6c2163bd02101ccefa2671/68747470733a2f2f636f6465636f762e696f2f67682f616c65782d706174746572736f6e2d7765626465762f636f6e7461696e65722d61727261792f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/alex-patterson-webdev/container)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/3f1dcdbc36555cd190d8b8ac000964231961b36f0d5f1d497685ed227b6169bd/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f616c65782d706174746572736f6e2d7765626465762f636f6e7461696e65722d61727261792f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/alex-patterson-webdev/container/?branch=master)

Arp\\Container
==============

[](#arpcontainer)

About
-----

[](#about)

A simple PSR-11 compatible Dependency Injection Container

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

[](#installation)

Installation via [Composer](https://getcomposer.org).

```
require alex-patterson-webdev/container ^0.1

```

Usage
-----

[](#usage)

To begin using the container, we simply need to create an instance of it

```
use Arp\Container\Container;

$container = new Container();

```

The `Arp\Container\Container` implements the `Psr\ContainerInterface` and therefore can be used to check and fetch services by name.

```
if (true === $container->has('ServiceName')) {
    $service = $container->get('ServiceName');
}

```

Registering services with the container
---------------------------------------

[](#registering-services-with-the-container)

There are a number of different ways we can register a 'service' with the container, the method you choose will depend on how you wish the service to be created.

### Objects and Values

[](#objects-and-values)

The simplest use case is when you need to `set()` an object or value on the container. These values do not require instantiation, the container will simply store and return this value unmodified when requested via `get()`.

```
$container = new Container();
$container->set('TodaysDate', new \DateTime('today'));
$todaysDate = $container->get('TodaysDate');

```

### Factories

[](#factories)

Factories provide us with a location to construct and resolve dependencies using the container. The factory can be any php `callable`and can be set by calling `$container->setFactory()`.

```
$container = new Container();
$container->setFactory('TodaysDate', static function() {
    return new \DateTime('today');
});

```

When invoked the factory class will also have the container injected into it as the first argument. We can use the container to resolve other dependencies.

```
$container->setFactory('TodaysDateService', static function(ContainerInterface $container) {
    return new TodayDateService($container->get('TodaysDate');
});

```

We also have access to the requested service name as the second argument, `$name`. By being aware of the name of the service which is being created it allows the creation of reusable factories.

```
$factory = static function(ContainerInterface $container, string $name) {
   $todaysDate = $container->get('TodaysDate');
   if ('EnglishDateService' === $name) {
        return new EnglishDateService($todaysDate);
   }
   return new FrenchDateService($todaysDate);
};

```

We can then assign the same factory with different service names.

```
$container->setFactory('EnglishDateService', $factory);
$container->setFactory('FrenchDateService', $factory);

```

### Object Factory

[](#object-factory)

In cases where you need have a service without dependencies we can use the `Arp\Container\Factory\ObjectFactory` and the container will create the class for us based on the service `$name`. If the service `$name` is not a valid class name an exception is thrown.

```
use Arp\Container\Factory\ObjectFactory;
$container = new Container();
$container->setFactory(\stdClass(), ObjectFactory::class);

// @var \stdClass $object
$object = $container->get(\stcClass());

```

*The above configuration isn't explicitly required as any service `$name` using a FQCN not registered with the container with be automatically registered to use `ObjectFactory`. We recommended that you explicitly define the service for clarity*.

Unit Tests
----------

[](#unit-tests)

The project unit tests can be executed using PHPUnit

```
php vendor/bin/phpunit

```

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance43

Moderate activity, may be stable

Popularity8

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity40

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

1084d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1563851?v=4)[Alex Patterson](/maintainers/alex-patterson-webdev)[@alex-patterson-webdev](https://github.com/alex-patterson-webdev)

---

Top Contributors

[![alex-patterson-webdev](https://avatars.githubusercontent.com/u/1563851?v=4)](https://github.com/alex-patterson-webdev "alex-patterson-webdev (39 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/alex-patterson-webdev-container/health.svg)

```
[![Health](https://phpackages.com/badges/alex-patterson-webdev-container/health.svg)](https://phpackages.com/packages/alex-patterson-webdev-container)
```

###  Alternatives

[pimple/pimple

Pimple, a simple Dependency Injection Container

2.7k130.5M1.4k](/packages/pimple-pimple)[league/container

A fast and intuitive dependency injection container.

86387.8M343](/packages/league-container)[lctrs/psalm-psr-container-plugin

Let Psalm understand better psr11 containers

17648.1k13](/packages/lctrs-psalm-psr-container-plugin)[phpwatch/simple-container

A fast and minimal PSR-11 compatible Dependency Injection Container with array-syntax and without auto-wiring

1810.1k2](/packages/phpwatch-simple-container)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
