承接 parable-php/di 相关项目开发

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

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

parable-php/di

Composer 安装命令:

composer require parable-php/di

包简介

Parable DI is a micro Dependency Injection Container

README 文档

README

Workflow Status Latest Stable Version Latest Unstable Version License

Parable DI is a no-nonsense dependency injection container that gets the job done.

Install

Php 8.0+ and composer are required.

$ composer require parable-php/di

Usage

Example usage of a straightforward situation:

use \Parable\Di\Container;

$container = new Container();

$app = $container->get(App::class);
$app->run();

Example usage of an interface-hinted dependency being mapped:

use \Parable\Di\Container;

$container = new Container();

class App
{
    public function __construct(ThatInterface $classWithThatInterface)
    {
    }
    
    public function run()
    {
        echo "Run? RUN!";
    }
}

$container->map(ThatInterface::class, ClassWithThatInterface::class);

$app = $container->get(App::class);
$app->run();

The above situation can also be solved by instantiating and then storing ClassWithThatInterface under ThatInterface.

Example usage of a class that needs the di itself, in case you need to do dynamic DI:

use \Parable\Di\Container;

$container = new Container();

class App
{
    public $container;
    public function __construct(
        public Container $container
    ) {}
}

$app = $container->get(App::class);
var_dump($app->container->has(App::class)); // output: bool(true)

For all other use cases, simply check the tests in tests/ContainerTest.php.

API

  • get(string $name): object - creates or gets instance
  • has(string $name): bool - check if instance is stored
  • assertHas(string $name): void - check and throw exception if instance is not stored
  • build(string $name): object - build instance with stored deps, don't store
  • buildAll(string $name): object - build instance with new deps, don't store
  • map(string $requested, string $replacement): void - allow pre-emptively defining a replacement class to be instantiated when the requested name is retrieved or built. Use for lazy-loading classes, i.e. for interface deps.
  • unmap(string $requested): void - removes the mapping and clears any previously mapped instances
  • getDependenciesFor(string $name, [int $storedDependencies]): array - get dependencies for instance, with stored (default) or new deps
  • store(object $instance, [string $name]): void - store instance under name, or under instance name by default
  • clear(string $name): void - clear instance
  • clearExcept(array $keep): void - clear all except provided names, throws if any of the instances to keep doesn't exist
  • clearAll(): void - clear all

Where object refers to any instance of any class.

Contributing

Any suggestions, bug reports or general feedback is welcome. Use github issues and pull requests, or find me over at devvoh.com.

License

All Parable components are open-source software, licensed under the MIT license.

parable-php/di 适用场景与选型建议

parable-php/di 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 903 次下载、GitHub Stars 达 5, 最近一次更新时间为 2018 年 08 月 09 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「container」 「library」 「micro」 「di」 「dependency-injection」 「parable」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 parable-php/di 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 parable-php/di 我们能提供哪些服务?
定制开发 / 二次开发

基于 parable-php/di 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

  • Stars: 5
  • Watchers: 1
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-08-09