unity/container
Composer 安装命令:
composer require unity/container
包简介
Unity framework dependency manager.
README 文档
README
An out of box dependency manager for PHP projects.
Introduction
Let's take a look at this class:
class Logger { protected $fileLogger; public function __construct(FileLogger $fileLogger) { $this->fileLogger = $fileLogger; } public function log($message) { return $this->fileLogger->log($message); } }
The problem with this class is that it's coupled to a specific Logger.
What if one day we change our mind and want to start sending our logs via email? We need to get back to this class and change the logger from FileLogger to EmailLogger
Refatoring:
class Logger { protected $driver; public function __construct(LoggerDriverInterface $driver) { $this->driver = $driver; } public function log($message) { return $this->driver->load($message); } }
That way our class can accept any kind of file drivers and is coupled to a contract instead of a concrete implememnation.
But what if you have a lot of classes to manage?
There's where the container comes.
Installation
composer require unity/container
Usage
统计信息
- 总下载量: 25
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 1
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-08-03