承接 blackcube/injector 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

blackcube/injector

最新稳定版本:1.0.0

Composer 安装命令:

composer require blackcube/injector

包简介

Static PSR-11 container accessor — get DI everywhere

README 文档

README

⚠️ Blackcube Warning

DI works great — inside methods. Outside, you're on your own.

Static factories, prototype patterns, helper classes — no constructor, no injection point. Injector is a portable container that bridges the gap without depending on the inheritance chain. One init() at bootstrap, get() wherever the container can't reach.

Static PSR-11 bridge for dependency injection outside of method scope.

License Packagist Version Warning

Installation

composer require blackcube/injector

Why Injector?

Situation Problem
Static factory (File::from()) No constructor, no DI
Prototype pattern (CacheFile) Clone-based, container unreachable
Helper classes Need a service, have no injection point
Injector Injector::get(MyService::class) — done

One class. Three methods. Zero magic.

Quick Start

1. Bootstrap (once)

use Blackcube\Injector\Injector;

// In your bootstrap or container setup
Injector::init($container);

With Yii config-plugin, this happens automatically via config/common/bootstrap.php.

2. Use anywhere

use Blackcube\Injector\Injector;

// Get a service
$logger = Injector::get(LoggerInterface::class);

// Check availability
if (Injector::has(CacheInterface::class)) {
    $cache = Injector::get(CacheInterface::class);
}

API

Method Description
Injector::init(ContainerInterface $container) Store the container (call once at bootstrap)
Injector::get(string $id): mixed Retrieve a service — throws RuntimeException if not initialized
Injector::has(string $id): bool Check if a service exists — returns false if not initialized

Yii Integration

The package ships with config-plugin support. Add blackcube/injector to your project and the bootstrap runs automatically:

// config/common/bootstrap.php (shipped with package)
static function (ContainerInterface $container): void {
    Injector::init($container);
};

No manual setup required.

Tests

vendor/bin/codecept run Unit

License

BSD-3-Clause. See LICENSE.md.

Author

Philippe Gaultier philippe@blackcube.io

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2026-03-06

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固