php-strict/container
Composer 安装命令:
composer require php-strict/container
包简介
Interface and implementation of common container.
关键字:
README 文档
README
Interface and implementation of common container.
Strict version of PSR-11 with additional methods to set/get references (instead of values) and get all container entries as array.
Requirements
- PHP >= 7.1
Install
Install with Composer:
composer require php-strict/container
Usage
Classic usage:
use PhpStrict\Container\Container $container = new Container(); $container->set('key1', 1); if ($container->has('key1')) { $var1 = $container->get('key1'); }
Usage to set/get references:
use PhpStrict\Container\Container $myObject = new stdClass(); $container = new Container(); $container->setByRef('key2', $myObject); $anotherObject =& $container->getRef('key2');
Set container values through constructor:
use PhpStrict\Container\Container $container = new Container([ 'key1' => 1, 'key2' => 'value 2', 'key3' => true, ]); if ($container->has('key2')) { $var2 = $container->get('key2'); }
Unpacking container through callback:
use PhpStrict\Container\Container class MyClass { protected $field1; protected $field2; protected $field3; public function unpacker(array $entries): void { foreach ($entries as $key => $value) { $this->$key = $value; } } } $container = new Container([ 'field1' => 1, 'field2' => 'value 2', 'field3' => true, ]); $myClassObject = new MyClass(); $container->unpackWith([$myClassObject, 'unpacker']);
Tests
To execute the test suite, you'll need Codeception.
vendor\bin\codecept run
统计信息
- 总下载量: 96
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: GPL-2.0-or-later
- 更新时间: 2019-03-26