awd-studio/di 问题修复 & 功能扩展

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

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

awd-studio/di

Composer 安装命令:

composer require awd-studio/di

包简介

The implementation of a dependency injection on PHP

README 文档

README

Build Status Coverage Status

Usage:

<?php

use \Acme\Services\MyService1;
use \Acme\Services\MyService2;
use \Acme\Services\MyService2Factory;
use \Acme\Services\MyService3;
use \AwdStudio\DI\Storage\Registry;
use \AwdStudio\DI\ContainerFactory;

// Create a new registry
$registry = new Registry();

// Builds the container
$container = ContainerFactory::build($registry);

// Minimum service registration
$registry->register(MyService1::class);

// Named service
$registry->register('my.second.service')
         ->class(MyService2::class)
         ->factory(MyService2Factory::class, 'build', []);

// Add tagged services
$service = MyService1::class;
$serviceWeight = 25; // Set up service weight for custom sorting
$registry->register($service);
$registry->tag('my.tag', $service, $serviceWeight);


// Service with arguments
$registry->register('my.service')
         ->class(MyService2::class) // Service interface or class
         ->arguments([              // Arguments for the construct the service
             'Simple Argument',     // Raw parameter
             '\!skip',              // Argument to skip
             '@my.second.service',  // Another named service
         ]);

// Check service existing
$container->has('@my.second.service');

// Fetch a service
$container->get('@my.second.service');
$container->get(MyService2::class);

// Factory method
$registry->register(MyService1::class)
         ->factory(MyStatic::class, 'factoryMethodName', [
             'Simple Argument', 
             '@my.second.service'
         ]);

// Static factory method
$registry->register(MyService1::class)
         ->fromCallable([MyStatic::class, 'build']);
//         ->fromCallable(['\Full\Namespace\MyStatic', 'build']);

// Common function
$registry->register(MyService1::class)
         ->fromCallable('callableFunction');
         
// Closure factory
$registry->register(MyService1::class)
         ->fromCallable(function ($arg) {
             return new MyService1($arg);
         })
         ->arguments(['My argument']);

Testing:

composer test

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-06-19

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固