承接 nacosvel/container-interop 相关项目开发

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

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

nacosvel/container-interop

Composer 安装命令:

composer require nacosvel/container-interop

包简介

Achieve compatibility and interoperability among different container objects.

README 文档

README

Achieve compatibility and interoperability among different container objects.

The library discovers available PSR-11 container implementations by searching for a list of known classes that implement the relevant interfaces, and returns an instance of the first one found. It supports binding, instantiation, and allows executing specific callbacks or logic when a class or dependency is resolving (i.e., instantiated or injected).

GitHub Tag Total Downloads Packagist Version Packagist PHP Version Support Packagist License

Installation

You can install the package via Composer:

composer require nacosvel/container-interop

Usage

Default Method Names

If your container uses the standard method names (bind, make, resolving), you can simply call:

use Nacosvel\Container\Interop\Discover;

Discover::container();

discovers available PSR-11 container implementations by searching for a list of known classes that implement the relevant interfaces

Custom Method Names

If your container uses different method names, specify them as follows:

use Nacosvel\Container\Interop\Discover;

Discover::container(
    container: $container,
    bind: 'customBindMethod',
    make: 'customMakeMethod',
    resolving: 'customResolvingMethod'
);
  • container: The container instance you want to work with.
  • bind: The name of the method used for binding dependencies.
  • make: The name of the method used for creating instances.
  • resolving: The name of the method used for resolving dependencies.

Accessing the Application

Let's look at a simple example:

use Nacosvel\Container\Interop\Application;

$application = Application::getInstance();

The application function returns the Application instance:

$application = application();

Accessing the Container

Once configured, third-party packages can access the container using:

use Nacosvel\Container\Interop\Application;

$container = Application::getInstance()->getContainer();

If needed, you may specify which Container instance you would like to access:

$container = application()->getContainer();

Accessing the Service

You may pass a class or interface name to resolve service from the container:

$cache = application(Cache::class);
$cache = application()->make(Cache::class);

This method ensures compatibility with various container implementations without worrying about their specific methods.

License

Nacosvel Container Interop is made available under the MIT License (MIT). Please see License File for more information.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-09-10