Download the PHP package x-wp/di without Composer
On this page you can find all versions of the php package x-wp/di. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package di
XWP-DI
Dependency Injection Container for WordPress
[](https://packagist.org/packages/x-wp/di)


[](https://github.com/x-wp/di/actions/workflows/release.yml)
This library allows you to implement dependency injection design pattern in your WordPress plugin or theme. It provides a simple and easy-to-use interface to manage dependencies and hook callbacks.
Key Features
- Reliable - Powered by PHP-DI, a mature and feature-rich dependency injection container.
- Interoperable - Provides PSR-11 compliant container interface.
- Easy to use - Reduces the boilerplate code required to manage dependencies and hook callbacks.
- Customizable - Allows various configuration options to customize the container behavior.
- Flexible - Enables advanced hook callback mechanisms.
- Fast - Dependencies are resolved only when needed, and the container can be compiled for better performance.
Installation
You can install this package via composer:
[!TIP] We recommend using the
automattic/jetpack-autoloader
with this package to prevent autoloading issues.
Usage
Below is a simple example to demonstrate how to use this library in your plugin or theme.
Creating the Application and Container
You will need a class which will be used as the entry point for your plugin/theme. This class must have a #[Module]
attribute to define the container configuration.
After defining the module, you can create the application using the xwp_create_app
function.
Using handlers and callbacks
Handler is any class which is annotated with a #[Handler]
attribute. Class methods can be annotated with #[Action]
or #[Filter]
attributes to define hook callbacks.
Examples
You can find the examples in the examples directory.
Documentation
For more information, please refer to the official documentation.
All versions of di with dependencies
automattic/jetpack-constants Version ^2 || ^3
php-di/php-di Version ^7
psr/log Version ^2.0 || ^3.0
symfony/polyfill-php81 Version ^1.31
x-wp/helper-classes Version ^1.13
x-wp/helper-functions Version ^1.13