Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pixelpluginhq/wp-container
WordPress Container Plugin
https://github.com/pixelpluginhq/wp-container
composer container dependency-injection php psr psr-11 wordpress wordpress-plugin
Last synced: 16 days ago
JSON representation
WordPress Container Plugin
- Host: GitHub
- URL: https://github.com/pixelpluginhq/wp-container
- Owner: pixelpluginhq
- License: mit
- Created: 2023-11-03T19:33:19.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2023-11-19T00:06:38.000Z (about 1 year ago)
- Last Synced: 2024-12-19T03:18:40.678Z (17 days ago)
- Topics: composer, container, dependency-injection, php, psr, psr-11, wordpress, wordpress-plugin
- Language: PHP
- Homepage: https://pixelplugin.com
- Size: 117 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# WordPress Container Plugin
`pixelplugin/wp-container` is a WordPress plugin that provides a global PSR-compatible
dependency container accordingly to [WordPress Container API](https://github.com/pixelpluginhq/wp-container-api).## Installation
```shell
composer require pixelplugin/wp-container
```https://packagist.org/packages/pixelplugin/wp-container
## Usage
1. Install this plugin
2. Require [pixelplugin/wp-container-api](https://github.com/pixelpluginhq/wp-container-api) via composer in your project
3. Now you can use the Container API## Filters
### wp_container
```php
/**
* @param array $definitions container definitions.
*/
apply_filters('wp_container', $definitions);
```The filter should be used to configure container definitions for your code. It supports the following formats:
- `ClassName::class` to simply add some class to the container, but normally it's not needed, because the container supports auto-wiring.
- `InterfaceName::class => ClassName::class` to specify another implementation of some class/interface.
- `ClassName::class => $instance` to bind a class name with a pre-created instance.
- `ClassName::class => $callable` to bind a class name with some callable factory.This filter is used on `after_setup_theme` action to create the container,
so the container is completely available on `init` hook
(or on the same `after_setup_theme` but with lower priority).