germania-kg/filteriterators
Composer 安装命令:
composer require germania-kg/filteriterators
包简介
FilterIterators for two-dimensional Traversables
README 文档
README
Germania KG · FilterIterators
FilterIterators for two-dimensional Traversables.
Installation with Composer
$ composer require germania-kg/filteriterators
Alternatively, add this package directly to your composer.json:
"require": { "germania-kg/filteriterators": "^2.0" }
BlankSplitFilterIterator
Lets all items pass of which the given field, splitted by blank sign into an array, contains a word.
The Constructor accepts anything that is Traversable.
The Traversable may contain both arrays or (StdClass) objects.
<?php use Germania\FilterIterators\BlankSplitFilterIterator; $items = array( [ 'foo' => 'bar john doe'], [ 'foo' => 'john bar doe'], [ 'foo' => 'john doe bar'], [ 'foo' => ['john', 'doe', 'bar']], ); // Convert above arrays to StdClasses $objects = array_map(function ($a) { return (object) $a; }, $items); $filter = new BlankSplitFilterIterator( $items, "foo", "bar" ); echo iterator_count( $filter ); // 4 $filter = new BlankSplitFilterIterator( $objects, "foo", "bar" ); echo iterator_count( $filter ); // 4
WordRegexFilterIterator
Lets all items pass of which the given field matches a word.
The Constructor accepts anything that is Traversable.
The Traversable may contain both arrays or (StdClass) objects.
<?php use Germania\FilterIterators\WordRegexFilterIterator; $items = array( [ 'foo' => 'bar john doe'], [ 'foo' => 'john bar doe'], [ 'foo' => 'john doe bar'], [ 'foo' => 'bar,john,doe'], [ 'foo' => 'john,bar,doe'], [ 'foo' => 'john,doe,bar'], [ 'foo' => 'john,doe,white-bar'], [ 'foo' => 'john,doe,bar-black'] ); // Convert above arrays to StdClasses $objects = array_map(function ($a) { return (object) $a; }, $items); $filter = new WordRegexFilterIterator( $items, "foo", "bar" ); echo iterator_count( $filter ); // 8 $filter = new WordRegexFilterIterator( $objects, "foo", "bar" ); echo iterator_count( $filter ); // 8
KeyNotFalseFilterIterator
Lets all items pass that are not explicitely excluded with active=false or active=0.
The Constructor accepts anything that is Traversable.
The Traversable may contain both arrays or (StdClass) objects.
<?php use Germania\FilterIterators\KeyNotFalseFilterIterator; // Items may be Arrays or StdClass objects $data = [ // These are not "inactive" [ 'name' => 'John', 'active' => true ], [ 'name' => 'George' ], // but these are: [ 'name' => 'Paul', 'active' => false ], [ 'name' => 'Ringo', 'active' => 0 ], ]; $filter = new KeyNotFalseFilterIterator( $data, "active" ); foreach( $filter as $item ): // John // George echo $item['name']; endforeach;
NotEmptyFieldFilterIterator
Lets all items pass that have a field whose value is not empty.
The Constructor accepts anything that is Traversable.
The Traversable may contain both arrays or (StdClass) objects.
<?php use Germania\FilterIterators\NotEmptyFieldFilterIterator; // Items may be Arrays or StdClass objects $data = [ // These are not "inactive" [ 'name' => 'John', 'active' => true ], [ 'name' => 'George' ], // but these are: [ 'name' => 'Paul', 'active' => false ], [ 'name' => 'Ringo', 'active' => 0 ], ]; $filter = new NotEmptyFieldFilterIterator( $data, "active" ); foreach( $filter as $item ): // John echo $item['name']; endforeach;
Issues
See issues list.
Development
$ git clone https://github.com/GermaniaKG/FilterIterators.git
$ cd FilterIterators
$ composer install
Unit tests
Either copy phpunit.xml.dist to phpunit.xml and adapt to your needs, or leave as is. Run PhpUnit test or composer scripts like this:
$ composer test # or $ vendor/bin/phpunit
统计信息
- 总下载量: 156
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-09-28