gacek85 / collection-iterator
该软件包最新版本(1.0.1)没有可用的许可信息。
帮助迭代大量数据集
1.0.1
2016-09-29 07:31 UTC
Requires
- php: >=5.5
- doctrine/orm: ^2.5
- filp/whoops: ~2.1
Requires (Dev)
- fzaninotto/faker: ~1.6.0
- phpunit/phpunit: ~4.8.0
This package is not auto-updated.
Last update: 2024-09-18 20:15:31 UTC
README
#Collection Iterator
这是SPL的Iterator
的一个实现,用于遍历大量数据集,以最小化内存限制耗尽的风险。它由一个迭代器服务类Gacek85\Collection\CollectionIterator
和一个接口Gacek85\Collection\IterableDataProvider
组成,该接口将由提供者使用,以向迭代器服务提供数据块。
##工作原理
迭代器使用提供者以块
的方式加载数据,之前加载的数据将通过垃圾收集器从内存中清除。
##公共API
###CollectionIterator
setPerPage(int $perPage): CollectionIterator // Sets the number of items loaded at once count(): int // Returns the total count of the elements that will be traversed
其他公共方法为Iterator
特定的API。
###IterableDataProvider
getTotal(): int // Returns the total count of available elements getChunk(int $offset, int $limit): array|Iterator //Returns the chunk of data from given offset limited with given limit
##用法
<?php $provider = new \My\Provider(); // An implementation of Gacek85\Collection\IterableDataProvider $iterator = new \Gacek85\Collection\CollectionIterator($provider); foreach ($iterator as $k => $item) { // Do your stuff here with the item }