Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pixelpluginhq/wp-container-api
WordPress Container API
https://github.com/pixelpluginhq/wp-container-api
composer container container-interface dependency-injection php psr psr-11 wordpress
Last synced: about 2 months ago
JSON representation
WordPress Container API
- Host: GitHub
- URL: https://github.com/pixelpluginhq/wp-container-api
- Owner: pixelpluginhq
- License: mit
- Created: 2023-10-28T08:56:57.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2023-11-13T23:47:44.000Z (about 1 year ago)
- Last Synced: 2024-01-15T03:28:31.847Z (12 months ago)
- Topics: composer, container, container-interface, dependency-injection, php, psr, psr-11, wordpress
- Language: PHP
- Homepage: https://pixelplugin.com
- Size: 32.2 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 API
`pixelplugin/wp-container-api` is a composer package that provides global functions
for working with a global dependency container in WordPress.## Installation
```shell
composer require pixelplugin/wp-container-api
```https://packagist.org/packages/pixelplugin/wp-container-api
## Usage
You need this package and some WordPress plugin that provides a global PSR-compatible container instance in `$wp_container` variable, for example [pixelplugin/wp-container](https://github.com/pixelpluginhq/wp-container). Then you can use the following functions to work with the container from your code.
## Functions
### wp_container_get
`wp_container_get(string $id): mixed` is used to get a value from the global container instance.
```php
$value = wp_container_get(ClassName::class);
```### wp_container_has
`wp_container_has(string $id): bool` checks if a value exists in the global container instance.
```php
if (wp_container_has(ClassName::class)) {
// ClassName exists in the container.
}
```