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
[![Packagist Version](https://img.shields.io/packagist/v/x-wp/di?label=Release&style=flat-square)](https://packagist.org/packages/x-wp/di)
![Packagist PHP Version](https://img.shields.io/packagist/dependency-v/x-wp/di/php?label=PHP&logo=php&logoColor=white&logoSize=auto&style=flat-square)
![Static Badge](https://img.shields.io/badge/WP-%3E%3D6.4-3858e9?style=flat-square&logo=wordpress&logoSize=auto)
[![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/x-wp/di/release.yml?label=Build&event=push&style=flat-square&logo=githubactions&logoColor=white&logoSize=auto)](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.
Documentation
For more information, please refer to the official documentation.
All versions of di with dependencies
automattic/jetpack-constants Version ^2
php-di/php-di Version ^7
symfony/polyfill-php81 Version ^1.31
x-wp/helper-classes Version ^1.13
x-wp/helper-functions Version ^1.13