定制 wpdiggerstudio/wpzylos-container 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

wpdiggerstudio/wpzylos-container

最新稳定版本:v1.0.0

Composer 安装命令:

composer require wpdiggerstudio/wpzylos-container

包简介

PSR-11 compatible dependency injection container with auto-wiring for WPZylos framework

README 文档

README

PHP Version License GitHub

PSR-11 compatible dependency injection container with auto-wiring for WordPress plugins.

📖 Full Documentation | 🐛 Report Issues

✨ Features

  • PSR-11 Compatible — Implements ContainerInterface
  • Auto-wiring — Automatic constructor injection
  • Singletons — Shared instances across resolves
  • Factories — New instances per resolution
  • Tagged Services — Group related services
  • Contextual Binding — Different implementations per consumer

📋 Requirements

Requirement Version
PHP ^8.0

🚀 Installation

composer require wpdiggerstudio/wpzylos-container

📖 Quick Start

use WPZylos\Framework\Container\Container;

$container = new Container();

// Bind a singleton (shared instance)
$container->singleton(DatabaseConnection::class, fn() => new DatabaseConnection());

// Bind a factory (new instance each time)
$container->bind(Logger::class, fn() => new Logger());

// Auto-wiring (automatic dependency resolution)
$container->bind(UserService::class);

// Resolve
$db = $container->get(DatabaseConnection::class);
$logger = $container->get(Logger::class);
$userService = $container->get(UserService::class);

🏗️ Core Features

Singleton Binding

// Registered once, shared everywhere
$container->singleton(Config::class, fn() => new Config('config.php'));

$config1 = $container->get(Config::class);
$config2 = $container->get(Config::class);
// $config1 === $config2

Factory Binding

// New instance every time
$container->bind(Request::class, fn() => new Request());

$req1 = $container->get(Request::class);
$req2 = $container->get(Request::class);
// $req1 !== $req2

Auto-wiring

class UserService {
    public function __construct(
        private DatabaseConnection $db,
        private Logger $logger
    ) {}
}

// Container automatically resolves dependencies
$container->bind(UserService::class);
$userService = $container->get(UserService::class);

Interface Binding

$container->bind(CacheInterface::class, RedisCache::class);
$container->singleton(LoggerInterface::class, FileLogger::class);

Tagged Services

$container->tag([EmailNotifier::class, SlackNotifier::class], 'notifiers');

$notifiers = $container->tagged('notifiers');
foreach ($notifiers as $notifier) {
    $notifier->send($message);
}

📦 Related Packages

Package Description
wpzylos-core Application foundation
wpzylos-config Configuration management
wpzylos-scaffold Plugin template

📖 Documentation

For comprehensive documentation, tutorials, and API reference, visit wpzylos.com.

☕ Support the Project

If you find this package helpful, consider buying me a coffee! Your support helps maintain and improve the WPZylos ecosystem.

Donate with PayPal

📄 License

MIT License. See LICENSE for details.

🤝 Contributing

Contributions are welcome! Please see CONTRIBUTING.md for guidelines.

Made with ❤️ by WPDiggerStudio

统计信息

  • 总下载量: 232
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-31

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固