netolabs/simple-container 问题修复 & 功能扩展

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

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

netolabs/simple-container

Composer 安装命令:

composer require netolabs/simple-container

包简介

Extremely basic and fast implementation of PSR-11

README 文档

README

Extremely basic and fast implementation of the PSR-11 container standard. It's not intended to do fancy dependency injection, just the absolute bare minimum. Consider using PHP-DI or Symfony DI for a more complete implementation.

Install

Via Composer

$ composer require netolabs/simple-container

Requirements

PHP version 7.3 and up is required.

Usage

Adding a definition to the container

$container = new SimpleContainer();
$service = new MySuperCoolService();

$container->set(MySuperCoolService::class, $service);

Fetching from the container

if ($container->has(MySuperCoolService::class) {
    $service = $container->get(MySuperCoolService::class);
}

Adding a callable definition

Here we are adding an anonymous function which will be invoked the first time the definition is accessed via set(). The computed value will be cached for subsequent accesses.

$container = new SimpleContainer();

$container->set('myCallable', function() {
    return 'a computed value';
});

$value = $container->get('myCallable');
// value is 'a computed value'

Invoking the callable for every access

If you require the callable to be invoked every time you access the definition, you can use the resolve() method instead.

$value = $container->resolve('myCallable');
// value is 'a computed value'

License

The MIT License (MIT). Please see the License File for more information.

统计信息

  • 总下载量: 2.09k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 4
  • 点击次数: 7
  • 依赖项目数: 2
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-03-09

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固