承接 wptechnix/di-container 相关项目开发

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

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

wptechnix/di-container

Composer 安装命令:

composer require wptechnix/di-container

包简介

A minimal, explicit PSR-11 dependency injection container for PHP.

README 文档

README

Packagist Version PHP 8.0+ PSR-11 MIT

A minimal, explicit PSR-11 dependency injection container for PHP. No autowiring, no reflection, no annotations, no magic — what you register is exactly what you get.

Requirements & Installation

composer require wptechnix/di-container
  • PHP 8.0+
  • PSR-11 compliant (psr/container ^1.1 || ^2.0)

Quick Start

use WPTechnix\DI\Container;

$c = new Container();

// Register a singleton — factory runs once, instance is cached
$c->singleton('logger', fn() => new Logger());
$logger = $c->get('logger'); // same instance every time

// Register a factory — factory runs on every resolution
$c->factory('mail', fn() => new Mailer());
$mail1 = $c->get('mail'); // fresh instance
$mail2 = $c->get('mail'); // another fresh instance

The Three Resolver Forms

// Closure — full control, receives container + resolved params
$c->singleton('db', fn(Container $c) => new Connection($c->get('config')));

// String — class name, validated at registration time
$c->singleton('logger', Logger::class);

// Null — identifier IS the class name (shorthand)
$c->singleton(Logger::class);

Feature Overview

Feature What it does Learn more
Singletons & factories Shared instance vs fresh per resolution Singletons and Factories
Resolver forms Closure, class string, null shorthand Resolvers
Constructor parameters Positional args + optional service resolution Constructor Parameters
Aliases Bind one name to another; the interface-binding pattern Aliases
Tagged services Group services; resolve them as a collection Tagged Services
Service decoration Wrap or replace a service before resolution Extending Services
Service providers Two-phase modular bootstrapping Service Providers
PSR-11 Interoperates with any PSR-11-aware framework Container Lifecycle

Learn More

For a guided tour, read the documentation in this order:

  1. Singletons and Factories — the fundamental registration choice
  2. Resolvers — the three ways to tell the container how to build a service
  3. Constructor Parameters — passing values and service dependencies to constructors
  4. Aliases — the interface-binding pattern
  5. Tagged Services — grouping related services for bulk resolution
  6. Extending Services — decorating services you don't own
  7. Service Providers — modular bootstrapping with two-phase registration
  8. Container Lifecycle — lazy initialization, resolution stack, boot freeze
  9. Exceptions — when things go wrong (and how to prevent it)
  10. API Reference — complete method signatures

License

MIT

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-06-28