wscore/dicontainer 问题修复 & 功能扩展

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

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

wscore/dicontainer

最新稳定版本:0.1.0

Composer 安装命令:

composer require wscore/dicontainer

包简介

Simple DI container with auto-wiring.

README 文档

README

A simple Dependency Injection Container.

Usage

###Creating an instance

Use instance scripts

$container = include( 'WScore.DiContainer/scripts/instance.php' );

###Setting and retrieving values.

Set and retrieve a value.

$container->set( 'some-id', 'a value' );
$value = $container->get( 'some-id' ); // gets a string: "a value".

Set a service object.

$container->set( 'service-this', '\name\space\className' );
$object = $container->get( 'service-this' ); // it's \name\space\className class.

Or, simply specify a class name to get an object.

$object = $container->get( '\name\space\className2' );

###Getting another class

Set another class for a given class.

$container->set( '\some\class', '\name\space\className' );
$object = $container->get( '\some\class' ); // it's \name\space\className class.

Auto-Wiring/Discovery

Supports simple auto-wiring or auto-discovery of dependencies using annotations in phpdocs. The supported tags are: @Inject, @param, and @var.

The @Singleton annotation is also supported.

Sample PHP class code:

/**
 * @Singleton
 */
class Sample {
    /**
     * @Inject
     * @var /class/class
     */
    private $property;

    /**
     * @Inject
     * @param /some/class1 $var
     * @param /some/class2 $var2
     */
    function __construct( $var, $var2 ) {}

    /**
     * @Inject
     * @param /some/class1 $var3
     */
    function setVar3( $var3 ) {}
}

Overwriting DI Option

The container can overwrite the dependency of any of the injection types: construct, setter, and property injections. Specify the option at get,

$container->option( 'Some\Class' )
    ->setConstructor( 'var', 'another\class' )
    ->setSetter( 'setVar3', 'setter\class', )
    ->setProperty( 'property', 'property\class' );
$object = $container->get( 'Some\Class );

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: Unknown
  • 更新时间: 2013-02-19