PHPackages                             rmp-up/wp-di - 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. [Framework](/categories/framework)
4. /
5. rmp-up/wp-di

ActiveLibrary[Framework](/categories/framework)

rmp-up/wp-di
============

Simple Dependency Injection / Service Container for more OOP in WordPress (PSR-11 compatible)

0.8.0(5y ago)168.8k↑50%[8 issues](https://github.com/rmp-up/wp-di/issues)proprietaryPHP

Since Apr 27Pushed 4y agoCompare

[ Source](https://github.com/rmp-up/wp-di)[ Packagist](https://packagist.org/packages/rmp-up/wp-di)[ RSS](/packages/rmp-up-wp-di/feed)WikiDiscussions release/0.8 Synced 1mo ago

READMEChangelog (10)Dependencies (4)Versions (21)Used By (0)

[![](https://camo.githubusercontent.com/eaa544e9f998f7dc3126f60ee933b31e92ef0bfb3e4694fbf8490b0a75c6a1e0/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d372e302532302d2d253230382e302d626c75653f7374796c653d666f722d7468652d6261646765266c6f676f3d706870)](https://camo.githubusercontent.com/eaa544e9f998f7dc3126f60ee933b31e92ef0bfb3e4694fbf8490b0a75c6a1e0/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d372e302532302d2d253230382e302d626c75653f7374796c653d666f722d7468652d6261646765266c6f676f3d706870)[![](https://camo.githubusercontent.com/bed0cfcf4c8d0935624e4feebab4fb1fe0da2f034210f72846399e034cbd5b16/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f576f726450726573732d342e382532302d2d253230352e362d626c75653f7374796c653d666f722d7468652d6261646765266c6f676f3d776f72647072657373)](https://camo.githubusercontent.com/bed0cfcf4c8d0935624e4feebab4fb1fe0da2f034210f72846399e034cbd5b16/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f576f726450726573732d342e382532302d2d253230352e362d626c75653f7374796c653d666f722d7468652d6261646765266c6f676f3d776f72647072657373)

[![Build Status](https://camo.githubusercontent.com/c0d4742dbfe503ead88ca77202f6e398e3e301262af40f60aaff6ba859dbff4f/68747470733a2f2f7472617669732d63692e6f72672f726d702d75702f77702d64692e7376673f6272616e63683d72656c656173652f302e38)](https://travis-ci.org/rmp-up/wp-di)[![Coverage Status](https://camo.githubusercontent.com/c93e8b7ed125ba3bd90ce0975bb962b4899df43d4323dc211c18c3fc0d197791/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f726d702d75702f77702d64692f62616467652e7376673f6272616e63683d72656c656173652f302e38)](https://coveralls.io/github/rmp-up/wp-di?branch=release/0.8)

WP DI
=====

[](#wp-di)

> PHP Dependency Injection for WordPress (based on Pimple)

This is nothing new but we added some magic:

- Compatible with projects using Pimple already
- Configuration via plain arrays, Yaml or other
- "Less WordPress more OOP"

and still searching for other magic to apply.

Getting started
---------------

[](#getting-started)

Add the package to your project

```
composer require rmp-up/wp-di
```

and set up the container provider

```
RmpUp\WpDi\WpDi::load( require 'services.php' );

$container = \RmpUp\WpDi\WpDi::pimple();
```

Friends of YAML can add `composer require symfony/yaml`and use

```
RmpUp\WpDi\WpDi::load(
	RmpUp\WpDi\Yaml::parseFile( 'services.yaml' )
);
```

Features
--------

[](#features)

A full documentation can be found in the [documentation of the latest releases](https://github.com/rmp-up/wp-di/releases). The following is just a sneak peek into some of the possibilities. Try using the "preload.php" when you have PHP &gt;= 7.4 or a composer workflow to get even more performance:

```
{
  "autoload": {
    "files": [ "vendor/rmp-up/wp-di/preload.php" ]
  }
}
```

### Services and parameters

[](#services-and-parameters)

Define services as known from classical DI but also ...

- Primitive parameters as usual
- Default values for options
- Path to templates
- Inject all of them into services
- Allow factories to create services

```
# Primitive parameters as usual
parameters:
  some: "primitives"
  like: 42

# Default values for options
options:
  _my_plugin_rating: 5/7
  _this_is: cool

# Path to templates
templates:
  admin-view: my-own-plugin/template-parts/fester.php
  frontend-view: my-own-plugin/public/coogan.jpg
  # looks up the file in theme, theme-compat and plugin directory

# Inject all of them into services
services:
  SimpleOne:
    arguments:
      - "Hello there!"
      - 1337

  SomeThing:
    arguments:
      - "%like%" # the parameter
      - "%_this_is%" # the option
      - "%frontend-view%" # path to the template
      - "@SimpleOne" # the other service
```

### Register services in WordPress

[](#register-services-in-wordpress)

Services can also be used to ...

- Add actions / filters
- Add Meta-Boxes
- Register Post-Types
- Register Shortcodes
- Register Widgets
- Add WP-CLI commands

```
services:
  StrrevEverything:
    filter: the_content
    # calling `::__invoke` for the "the_content"-filter

  BackendAdminListThing:
    meta_box:
      title: Greatest box in the World!
      screen: post

  MyOwnPostType:
    post_type: animals
    # cast service to array and forward to register_post_type

  BestShortcodeEver:
    shortcode: shortcode_wont_die
    widget: ~
    # Shortcode and widget at once. Wow!

  DoItCommand:
    wp_cli:
      do-it: __invoke
      doit: __invoke
      seriously do-it do-it do-it: seriously
      # cli commands mapped to methods
```

### Use tags to enhance YAML

[](#use-tags-to-enhance-yaml)

Within YAML you can:

- Access PHP-Constants
- Concatenate text
- Translate text

Mostly lazy to get the best performance.

```
services:
  # Access PHP-Constants
  InjectingConstants:
    arguments:
      - !php/const ABSPATH

  # Concatenate text
  ThisIsSomeTemplate:
    arguments:
      - !join [ !php/const WP_CONTENT_DIR, "/plugins/grey-matter/walter.jpg" ]

  # Translations within YAML
  ThisThingNeedsTranslations:
    arguments:
      - !__ [ Who is Adam?, dark ]
      - !esc_attr__ [ white ]
      # ... many more translation functions available ...
```

All of this is only possible when using `\RmpUp\WpDi\Yaml::parseFile(...)`or `::parse(...)`.

Contributing
------------

[](#contributing)

We used this in some projects and still maintain/enhance it, so please [open an issue](https://github.com/rmp-up/wp-di/issues/new)if there is anything we can help with.

If you'd like to contribute, please fork the repository and make changes as you'd like. Pull requests are warmly welcome.

Related projects
----------------

[](#related-projects)

Please also note the following projects about dependency injection container in WordPress:

- [Pimple Dependency Injection Container](https://packagist.org/packages/pimple/pimple)
- [Plugin-Boilerplate by Gary Jones](https://github.com/GaryJones/plugin-boilerplate)

Licensing
---------

[](#licensing)

See the [LICENSE.txt](./LICENSE.txt) for details.

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance10

Infrequent updates — may be unmaintained

Popularity29

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 96.7% 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 ~35 days

Recently: every ~13 days

Total

19

Last Release

1948d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/24290366?v=4)[Pretzlaw](/maintainers/pretzlaw)[@pretzlaw](https://github.com/pretzlaw)

---

Top Contributors

[![pretzlaw](https://avatars.githubusercontent.com/u/24290366?v=4)](https://github.com/pretzlaw "pretzlaw (29 commits)")[![rmp-up-102](https://avatars.githubusercontent.com/u/55878802?v=4)](https://github.com/rmp-up-102 "rmp-up-102 (1 commits)")

---

Tags

magicphpphp-dependency-injectionpimplepsr-11wordpresswp-di

### Embed Badge

![Health badge](/badges/rmp-up-wp-di/health.svg)

```
[![Health](https://phpackages.com/badges/rmp-up-wp-di/health.svg)](https://phpackages.com/packages/rmp-up-wp-di)
```

###  Alternatives

[corneltek/cliframework

Command-line framework for PHP

435160.5k16](/packages/corneltek-cliframework)[htmlburger/wpemerge

A micro framework which modernizes WordPress as a CMS development by providing tools to implement MVC and more.

456137.8k8](/packages/htmlburger-wpemerge)[vlucas/bulletphp

A heierarchical resource-oriented micro-framework built on nested closures instead of route-based callbacks

41949.9k1](/packages/vlucas-bulletphp)[mouf/pimple-interop

This project is a very simple extension to the Pimple microframework. It adds to Pimple compatibility with the container-interop APIs.

102.4M2](/packages/mouf-pimple-interop)[php-di/silex-bridge

PHP-DI integration in Silex

2465.4k1](/packages/php-di-silex-bridge)

PHPackages © 2026

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