exan/container 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

exan/container

最新稳定版本:1.0.1

Composer 安装命令:

composer require exan/container

包简介

Generic container implementation

README 文档

README

A minimal PSR-11 compliant container. Automatically resolves dependencies when possible.

Install

composer require exan/container

Usage

$container = new Exan\Container();

$someClass = $container->get(SomeClass::class);

This will try to instantiate an instance of SomeClass for you and returns it. If you then request this class again further on, it will return the same instance.

Assuming no unresolvable dependencies, it will also resolve nested dependencies.

class SomeClass
{
    public function __construct(public readonly Dependency $dependency)
    {
        // ...
    }
}

$container = new Exan\Container();

$someClass = $container->get(SomeClass::class);

SomeClass in this example will be instantiated with an instance of Dependency.

It can also handle interfaces, but will not be able to resolve an implementation of said interface automatically. You will need to register an entry manually.

interface SomeInterface
{
    // ...
}

class SomeClass implements SomeInterface
{
    // ...
}

$container = new Exan\Container();

$container->register(SomeInterface::class, new SomeClass())

$someClass = $container->get(SomeInterface::class);

Note: it does not automatically resolve primitive types like string and int.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-05-24