bapcat/services

0.3 2019-01-03 21:26 UTC

This package is auto-updated.

Last update: 2024-09-15 06:00:01 UTC


README

Build Status Coverage Status License

服务

此软件包提供了一种对跨包依赖进行控制的启动环境。

安装

Composer

Composer 是安装 BapCat 软件包的推荐方法。

$ composer require bapcat/services

GitHub

可以从 GitHub 下载 BapCat 软件包。

功能

注册

Services 的主要用途是注册 IoC 绑定。

<?php namespace BapCat\CoolLogger;

use BapCat\CoolLogger\Logger;

use BapCat\Interfaces\Ioc\Ioc;

class LoggingServiceProvider implements ServiceProvider {
  private $ioc;
  
  public function __construct(Ioc $ioc) {
    $this->ioc = $ioc;
  }
  
  public function register() {
    // Make Logger a singleton
    $this->ioc->singleton(Logger::class, Logger::class);
    
    // Bind the bap.log alias to the Logger singleton
    $this->ioc->bind('bap.log', Logger::class);
  }
}