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

Abandoned → [wp-oop/containers](/?search=wp-oop%2Fcontainers)ArchivedLibrary[PSR &amp; Standards](/categories/psr-standards)

dhii/wp-containers
==================

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

v0.1.0-alpha1(7y ago)14.9k1[1 issues](https://github.com/Dhii/wp-containers/issues)1MITPHPPHP ^7.0 | ^8.0

Since May 6Pushed 5y ago3 watchersCompare

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

READMEChangelog (1)Dependencies (6)Versions (3)Used By (1)

\[Archived\] Dhii - WP Containers
=================================

[](#archived-dhii---wp-containers)

Please check Packagist for alternatives

[![Build Status](https://camo.githubusercontent.com/e7c2321f4bc346c9517330a4a007444bf48ff02896d38033236397efaab47076/68747470733a2f2f7472617669732d63692e6f72672f446869692f77702d636f6e7461696e6572732e7376673f6272616e63683d646576656c6f70)](https://travis-ci.org/Dhii/wp-containers)[![Code Climate](https://camo.githubusercontent.com/966747b46a48d7c84b0986fab5ff96bb124549913634759676c5f4b814d6fee9/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f446869692f77702d636f6e7461696e6572732f6261646765732f6770612e737667)](https://codeclimate.com/github/Dhii/wp-containers)[![Test Coverage](https://camo.githubusercontent.com/8536f06bf7aebb21a359970e6f8ffb7cf31524c0b15c16bfd236af26ddbb22a9/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f446869692f77702d636f6e7461696e6572732f6261646765732f636f7665726167652e737667)](https://codeclimate.com/github/Dhii/wp-containers/coverage)[![Join the chat at https://gitter.im/Dhii/wp-containers](https://camo.githubusercontent.com/5531903aabc14db74406e0c6f4ca37d2b0f47921f98bf925343b8f0d856cfb15/68747470733a2f2f6261646765732e6769747465722e696d2f446869692f77702d636f6e7461696e6572732e737667)](https://gitter.im/Dhii/wp-containers?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)[![This package complies with Dhii standards](https://camo.githubusercontent.com/44bbe8c7678c1784cfc53cabce5d3e32fc22a840453c5ed9c08601522fe7c213/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f446869692d436f6d706c69616e742d677265656e2e7376673f7374796c653d666c61742d737175617265)](https://github.com/Dhii/dhii)

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 Dhii\Wp\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 Dhii\Wp\Containers\Options\BlogOptions;
use Dhii\Wp\Containers\Options\BlogOptionsContainer;
use Dhii\Wp\Containers\Sites;

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

// 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 Dhii\Wp\Containers\Options\SiteMeta;
use Dhii\Wp\Containers\Options\SiteMetaContainer;
use Dhii\Wp\Containers\Sites;

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

// 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 Dhii\Wp\Containers\Options\BlogOptions;
use Psr\Container\NotFoundExceptionInterface;
use Psr\Container\ContainerExceptionInterface;
use Dhii\Data\Container\Exception\NotFoundExceptionInterface as ExtendedNotFoundException;

// 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 ExtendedNotFoundException);
    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 `delete()` 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

24

—

LowBetter than 32% of packages

Maintenance0

Infrequent updates — may be unmaintained

Popularity24

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity51

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

2565d 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 (53 commits)")

---

Tags

containerspsr-11-compliantstandards-compliantwordpresswordpress-php-librarycontainerwordpressdependency-injectiondi

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[php-di/php-di

The dependency injection container for humans

2.8k48.9M994](/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.3k58](/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)
