pixelplugin / wp-container
WordPress Container Plugin
Installs: 2
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:wordpress-plugin
Requires
- php: >=7.0
- composer/installers: ^1.0 || ^2.0
- league/container: ^3.4
Requires (Dev)
- 10up/wp_mock: ^0.3.0
- phpcompatibility/php-compatibility: ^9.3
- phpunit/phpunit: ^6.5
- psr/container: ^1.0
- squizlabs/php_codesniffer: ^3.7
README
pixelplugin/wp-container
is a WordPress plugin that provides a global PSR-compatible
dependency container accordingly to WordPress Container API.
Installation
composer require pixelplugin/wp-container
https://packagist.org/packages/pixelplugin/wp-container
Usage
- Install this plugin
- Require pixelplugin/wp-container-api via composer in your project
- Now you can use the Container API
Filters
wp_container
/** * @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).