harbinger / iterator
Harbinger库用于将对象集合作为迭代器处理
3.0.0
2017-05-09 03:59 UTC
Requires
- php: >=7.0.0
Requires (Dev)
- phpdocumentor/phpdocumentor: @stable
- phpmd/phpmd: @stable
- phpunit/phpunit: 6.*
- squizlabs/php_codesniffer: @stable
README
Harbinger\Iterator
是一个集合控制库。它基于强类型语言中的类型列表(例如Java、C#等),但结构较为松散。
要求
- PHP 7.0+(版本
2.0.0
或更早版本) - PHP 5.6+(版本
1.x.x
)
安装
包可在 Packgist 上找到
composer.json
#!json
{
"require": {
"harbinger/iterator": "@stable",
}
}
用法
作为简单的对象类型列表(例如:连接列表)
#!php
$collection = new \Harbinger\Iterator\Collection\Object(\Connection::class);
$collection->add(new \Connection('pgsql'));
$collection->add(new \Connection('mysql'));
foreach($collection AS $connection) {
}
此类实现不需要其他实现,但不能为特定的集合列表进行类型提示。
必须使用 \Harbinger\Iterator\Collection::getTargetClass()
进行验证。
#!php
$collection->getTargetClass() === \Connection::class;
作为模式化的对象类型列表(例如:连接列表)
#!php
namespace Collection;
class Connection extends \Harbinger\Iterator\Collection {
/**
* {@inheritdoc}
**/
public function getTargetClass() {
return \Contato::class;
}
}
#!php
$collection = new \Collection\Connection();
$collection->add(new \Connection('pgsql'));
$collection->add(new \Connection('mysql'));
foreach($collection AS $connection) {
}
必须针对指定的对象进行实现。可以使用类型提示。
#!php
public function setCollection(\Collection\Connection $collection) {
}
变更日志
3.0.0
- 添加了
last
方法,用于查找和检索集合中的最后一个元素
3.0.0-RC
- 删除了
\Harbinger\Iterator\Filter\Custom
。建议使用SPL中的CallbackFilterIterator
2.0.0
- 为PHP 7提供支持的实施方案;
- 为
\Harbinger\Iterator\Filter\Custom
添加了新的测试。
1.0.7
- 添加了
last
方法,用于查找和检索集合中的最后一个元素
1.0.6
- 为
\Harbinger\Iterator\Filter\Custom
添加了新的测试。
1.0.5
- 更新了编码风格,以符合PSR-1和PSR-2(除了逗号前的空格:接口和函数参数);
- 删除了phpDocumentor版本标签。
1.0.4
- 从
\Harbinger\Iterator\Collection\Object
构造时,如果给定的参数不是字符串或空字符串,将抛出UnexceptedValueException异常; - 重构了一些phpdoc版本块。
1.0.3
- 修正了许可信息。
1.0.2
- 修正了许可信息;
- 修正了
composer.json
。
1.0.1
- 修正了
composer.json
; - 重构了一些phpdoc块。
1.0.0
- 项目开始。