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

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

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

lee/simple-container

Composer 安装命令:

composer require lee/simple-container

包简介

PHP library that reflect the specific classes

README 文档

README

Build Status Coverage Status

Introduction

This is about the simple container to help developers to understand how the Reflection works.

Usage

Firstly, you have to specify a class that you want to inject.

For example, we assume that you want to inject following Profile class:

class Profile
{
    protected $userName;

    public function __construct($userName = 'lee')
    {
        $this->userName = $userName;
    }

    public function getUserName()
    {
        return $this->userName;
    }
}

Then we use the Container class to inject this Profile class.

use Lee\Container\Container;

$container = new Container();
$container->set(Profile::class);
$profile = $container->get(Profile::class);

echo $profile->getUserName(); // lee

If you want to inject class that its constructor arguments is without the default value, we should specify them by ourselves.

The sample codes are as follows:

class Profile
{
    protected $userName;

    public function __construct($userName)
    {
        $this->userName = $userName;
    }

    public function getUserName()
    {
        return $this->userName;
    }
}

Then we use Container class to inject this class.

use Lee\Container\Container;

$container = new Container();
$container->set(Profile::class);
$profile = $container->get(Profile::class, ['userName' => 'Peter']);

echo $profile->getUserName(); // Peter

References

This simple-container is about implementing this post.

However, this post we refer is incorrect on some approaches.

We decide to implement this PHP package to complete the correct container example.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-02-26

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固