maxgoryunov/saving-iterator 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

maxgoryunov/saving-iterator

Composer 安装命令:

composer require maxgoryunov/saving-iterator

包简介

True Caching Iterator for PHP

README 文档

README

EO principles respected here DevOps By Rultor.com

PHP-Composer-Build Build Status Build Status Build status MaxGoryunov

PDD status codecov Mutation testing badge Latest Stable Version License: MIT

Maintainability Codacy Badge Scrutinizer Code Quality CodeFactor

Quality Gate Status Bugs Code Smells Reliability Rating

Duplicated Lines (%) Technical Debt Maintainability Rating

Hits-of-Code Lines-of-Code PHP Version

Saving Iterator is a true caching iterator for PHP. It aims to solve the same problems as PHP's Caching Iterator but with a better encapsulation of data in mind. It has properties of both Iterator and array.

How to use

Require it with Composer:

composer require maxgoryunov/saving-iterator

Then include this in your index.php or any other main file:

require __DIR__ . "./vendor/autoload.php";

If you have any questions, ask them at Discussions.

Decorating Iterators

In order to use SavingIterator you need to provide a source and a target. Any object with Iterator interface is a suitable source. Target needs to be an AddingIterator(usually ArrayAddingIterator is enough):

$squares = new SavingIterator(
    new SquaringIterator(
        [1, 2, 3, 4, 5, 6]
    ),
    new ArrayAddingIterator()
);

It is also possible to use SavingIterator without providing a target. In this case, it will use a default AddingIterator storage:

$squares = new SavingIterator(
    new SquaringIterator(
        [1, 2, 3, 4, 5, 6]
    )
);

If the origin object is not an Iterator then wrap it in TransparentIterator:

$wrapped = new SavingIterator(
    new TransparentIterator($origin),
    new ArrayAddingIterator()
);

If you do not want to store nulls in your AddingIterator then use ValidAddingIterator:

$valid = new ValidAddingIterator(
    new ArrayAddingIterator()
);

Decorating Generators

You can also use it with Generators. If the iterator is called twice, rewind exception will not be thrown. Just pass a function which returns a Generator to the constructor:

$numerals = function (): Generator {
    for ($i = 0; $i < 10; $i++) {
        yield $i;
    }
};

$iter = new SavingIterator(
    $numerals,
    new ArrayAddingIterator()
);

How to run tests

First, install Docker. After that, run:

docker-compose build

docker-compose run --rm php bash

After you start the container, install dependencies and run tests:

composer install

vendor/bin/phpunit tests

How to contribute

Fork this repository, then create a folder for it and install Composer if you do not have it.

Clone this repository:

git clone https://github.com/MaxGoryunov/saving-iterator

Then run:

composer install

This command will install all dependencies required for development. Make changes and open a pull request. Your PR will be reviewed and accepted if it does not fail our build.

统计信息

  • 总下载量: 3
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 5
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 5
  • Watchers: 3
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2021-07-11

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固