PHPackages                             phpwatch/simple-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. phpwatch/simple-container

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

phpwatch/simple-container
=========================

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

v2.1.0(2y ago)1811.7k↑205.7%22MITPHPPHP ^8.3CI failing

Since May 7Pushed 2y ago1 watchersCompare

[ Source](https://github.com/PHPWatch/simple-container)[ Packagist](https://packagist.org/packages/phpwatch/simple-container)[ RSS](/packages/phpwatch-simple-container/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (2)Versions (13)Used By (2)

Simple Container
================

[](#simple-container)

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

[![Latest Stable Version](https://camo.githubusercontent.com/7f05afe293c925f210f8270529dd698633b3fe289d18441164a2cc39358d10dd/68747470733a2f2f706f7365722e707567782e6f72672f70687077617463682f73696d706c652d636f6e7461696e65722f762f737461626c65)](https://packagist.org/packages/phpwatch/simple-container) [![CI](https://github.com/PHPWatch/simple-container/workflows/CI/badge.svg?branch=master)](https://github.com/PHPWatch/simple-container/workflows/CI/badge.svg?branch=master) [![codecov](https://camo.githubusercontent.com/3b2340dc0c6846db8aace285d87067c26fb392d448ae3b871ea9bebf7ad0017c/68747470733a2f2f636f6465636f762e696f2f67682f50485057617463682f73696d706c652d636f6e7461696e65722f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/PHPWatch/simple-container) [![Scrutinizer Code Quality](https://camo.githubusercontent.com/e4e073e1cc3b1a4c769edb2013ec53427d024a39b7c6b6fe53acc3cd138a0d6d/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f50485057617463682f73696d706c652d636f6e7461696e65722f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/PHPWatch/simple-container/?branch=master) [![License](https://camo.githubusercontent.com/224ffbc33d0c1e6bab903093576cabeb7d94cebbea7f9bcb575e6b2f2e911c7e/68747470733a2f2f706f7365722e707567782e6f72672f70687077617463682f73696d706c652d636f6e7461696e65722f6c6963656e7365)](https://packagist.org/packages/phpwatch/simple-container)

Design goals
------------

[](#design-goals)

- Do one thing and do it well
- ~100 LOC
- **No auto-wiring** by design
- Services are declared as closures
- Array-syntax to access and set services (`$container['database']`)
- Fully PSR-11 compliant
- Support for protected services (return closures verbatim)
- Support for factory services (return a new instance instead of returning the same instance)
- 100% test coverage
- Services can over overwritten later, marked factory/protected
- Function at full speed without a compilation step

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

[](#installation)

```
composer require phpwatch/simple-container
```

Usage
-----

[](#usage)

*Simple Container* supports array-syntax for setting and fetching of services and values. You can mark certain services as factory or protected later too.

### Declare services and values

[](#declare-services-and-values)

```
