PHPackages                             wp-oop/containers - 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. wp-oop/containers

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

wp-oop/containers
=================

PSR-11 container implementations that wrap some WP features, for convenience and interoperability.

0.1.x-dev(2y ago)131.2kMITPHPPHP ^7.1 | ^8.0

Since May 6Pushed 2y agoCompare

[ Source](https://github.com/wp-oop/containers)[ Packagist](https://packagist.org/packages/wp-oop/containers)[ RSS](/packages/wp-oop-containers/feed)WikiDiscussions 0.1.x Synced 1mo ago

READMEChangelog (4)Dependencies (9)Versions (6)Used By (0)

WP Containers
=============

[](#wp-containers)

[![Continuous Integration](https://github.com/wp-oop/containers/workflows/Continuous%20Integration/badge.svg)](https://github.com/wp-oop/containers/workflows/Continuous%20Integration/badge.svg)

Details
-------

[](#details)

[PSR-11](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-11-container.md) container implementations that wrap some WP features, for convenience and interoperability.

Features
--------

[](#features)

### Retrieve sites by key

[](#retrieve-sites-by-key)

```
use WpOop\Containers\Sites;
use WP_Site;

$sites = new Sites();
$site2 = $sites->get('2');
assert($site2 instanceof WP_Site);
```

### Retrieve site options by key

[](#retrieve-site-options-by-key)

```
use WpOop\Containers\Options\BlogOptions;
use WpOop\Containers\Options\BlogOptionsContainer;
use WpOop\Containers\Sites;

// Set up sites container (see other example)
// ...
assert($sites instanceof Sites);

// Definition
$optionsContainer = new BlogOptionsContainer(
    function ($id) {
        return new BlogOptions($id, uniqid('default-option-value'));
    },
    $sites
);

// Usage
$blog3Options = $optionsContainer->get('3');
$myOption = $blog3Options->get('my_option');
```

### Retrieve site meta by key

[](#retrieve-site-meta-by-key)

```
use WpOop\Containers\Options\SiteMeta;
use WpOop\Containers\Options\SiteMetaContainer;
use WpOop\Containers\Sites;

// Set up sites container (see other example)
// ...
assert($sites instanceof Sites);

// Definition
$metaContainer = new SiteMetaContainer(
    function ($id) {
        return new SiteMeta($id, uniqid('default-meta-value'));
    },
    $sites
);

// Usage
$blog4Meta = $metaContainer->get('4');
$myMeta = $blog4Meta->get('my_meta');
```

### Structured error handling

[](#structured-error-handling)

```
use WpOop\Containers\Options\BlogOptions;
use Psr\Container\NotFoundExceptionInterface;
use WpOop\Containers\Exception\NotFoundException;

// Set up options (see previous examples)
// ...
assert($options instanceof BlogOptions);

try {
    $options->set('other_option', 'My Value');
    $value = $options->get('my_option');
} catch (NotFoundExceptionInterface $e) {
    assert($e instanceof NotFoundException);
    echo sprintf('Option "%1$s" does not exist', $e->getDataKey());
    assert($e->getContainer() === $options);
}
```

This solves the problem of inconsistent behaviour of native WordPress option-related funtions:

- retrieved options returned `false` for both a `false` value and when not found, making them hard to distinguish;
- setting an option returned `false` for both failure, an when the value is the same as the curent value, often resulting in a false error.

This is no longer the case with the above containers: option operations succeed or correctly fail by throwing PSR-11 exceptions. Furthermore, the original behaviour of these exceptions has been extended to allow retrieval of the key that was not found (when applicable) and the container that failed the operation. This is optional, however, and depending simply on the PSR-11 exceptions will work as expected.

The `set()`, `has()`, and `unset()` also throw [`ContainerExceptionInterface`](https://github.com/Dhii/data-container-interface/blob/develop/src/Exception/ContainerExceptionInterface.php#L14) on failure.

### Wraps WP

[](#wraps-wp)

The containers do not re-create the functionality to go around WordPress. Instead, they wrap native WordPress functionality, so you can be sure that everything is done in the same way, all the hooks, such as `option_*` or `pre_update_option_*`, still work.

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity27

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity54

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

Every ~236 days

Total

5

Last Release

961d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/1894e91b32c9f80d8f30a42d360af6983a507f1cf2c621b7c9a0a0de14e011c5?d=identicon)[XedinUnknown](/maintainers/XedinUnknown)

---

Top Contributors

[![XedinUnknown](https://avatars.githubusercontent.com/u/1428973?v=4)](https://github.com/XedinUnknown "XedinUnknown (125 commits)")

---

Tags

containerwordpressdependency-injectiondi

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Type Coverage Yes

### Embed Badge

![Health badge](/badges/wp-oop-containers/health.svg)

```
[![Health](https://phpackages.com/badges/wp-oop-containers/health.svg)](https://phpackages.com/packages/wp-oop-containers)
```

###  Alternatives

[php-di/php-di

The dependency injection container for humans

2.8k48.9M987](/packages/php-di-php-di)[aura/di

A serializable dependency injection container with constructor and setter injection, interface and trait awareness, configuration inheritance, and much more.

356968.3k57](/packages/aura-di)[mrclay/props-dic

Props is a simple DI container that allows retrieving values via custom property and method names

3611.7M3](/packages/mrclay-props-dic)[slince/di

A flexible dependency injection container

20260.4k6](/packages/slince-di)[capsule/di

A PSR-11 compliant autowiring dependency injection container.

2857.5k2](/packages/capsule-di)

PHPackages © 2026

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