sefra/container
最新稳定版本:v1.0.1
Composer 安装命令:
composer require sefra/container
包简介
service container for wordpress plugins and themes
README 文档
README
A lightweight service container for WordPress plugins and themes, inspired by Laravel's and other modern PHP frameworks’ dependency injection containers.
It allows you to bind classes, singletons, and closures, and automatically resolves dependencies via constructor injection.
Purpose
This container is a core part of the Sefra WordPress Plugin Starter Kit, providing dependency injection and service management for plugins.
Documentation
If you have a WordPress plugin and want to integrate Sefra Container to manage dependency injection, check this guide: How To Use Sefra Container
If you’re starting a new plugin, you might find this starter kit useful:
- repository: Sefra WordPress Plugin Starter Kit
- documentation on it built: documentation
Installation
Use Composer to install:
composer require sefra/container
Usage
use Sefra\Core\Container; // Get container instance $container = Container::getInstance(); // Bind a class $container->bind(App\Services\MyService::class); // Bind a singleton $container->singleton(App\Services\MySingletonService::class); // Resolve an instance $service = $container->get(App\Services\MyService::class);
Constructor Injection
Dependencies are automatically resolved:
class Logger { public function log($message) { /* ... */ } } class Mailer { public function __construct(Logger $logger) { $this->logger = $logger; } } $mailer = $container->resolve(Mailer::class); // Logger is injected automatically
Restrictions
Injecting the container itself into services is forbidden to prevent tight coupling.
Circular dependencies are detected and will throw an exception.
License
MIT
统计信息
- 总下载量: 6
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-01-06