Skip to content

Commit cdc26e4

Browse files
authored
Merge pull request #15 from MaxGoryunov/feature/13
Feature/13
2 parents 8e18a54 + f8951c0 commit cdc26e4

File tree

1 file changed

+82
-2
lines changed

1 file changed

+82
-2
lines changed

README.md

Lines changed: 82 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,82 @@
1-
# saving-iterator
2-
True Caching Iterator for PHP.
1+
[![EO principles respected here](https://www.elegantobjects.org/badge.svg)](https://www.elegantobjects.org)
2+
3+
![PHP-Composer-Build](https://github.com/MaxGoryunov/saving-iterator/actions/workflows/php.yml/badge.svg)
4+
[![Latest Stable Version](http://poser.pugx.org/maxgoryunov/saving-iterator/v)](https://packagist.org/packages/maxgoryunov/saving-iterator)
5+
[![Maintainability](https://api.codeclimate.com/v1/badges/d721a5fca4901010520e/maintainability)](https://codeclimate.com/github/MaxGoryunov/saving-iterator/maintainability)
6+
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/MaxGoryunov/saving-iterator/badges/quality-score.png?b=main)](https://scrutinizer-ci.com/g/MaxGoryunov/saving-iterator/?branch=main)
7+
[![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://github.com/MaxGoryunov/saving-iterator/blob/main/LICENSE)
8+
9+
[![Hits-of-Code](https://hitsofcode.com/github/MaxGoryunov/saving-iterator?branch=main)](https://hitsofcode.com/github/MaxGoryunov/saving-iterator/view)
10+
![Lines-of-Code](https://tokei.rs/b1/github/MaxGoryunov/saving-iterator?branch=main)
11+
12+
**Saving Iterator** is a true caching iterator for PHP. It aims to solve the same problems as PHP's [Caching Iterator](https://www.php.net/manual/ru/class.cachingiterator.php) but with a [better encapsulation of data](https://www.yegor256.com/2016/11/21/naked-data.html) in mind. It has properties of both `Iterator` and `array`.
13+
14+
## How to use
15+
16+
Require it with Composer:
17+
18+
```bash
19+
composer require maxgoryunov/saving-iterator
20+
```
21+
22+
Then include this in your `index.php` or any other main file:
23+
24+
```PHP
25+
require __DIR__ . "./vendor/autoload.php";
26+
```
27+
28+
If you have any questions, ask them at [Discussions](https://github.com/MaxGoryunov/saving-iterator/discussions).
29+
30+
## Decorating Iterators
31+
32+
Any object with `Iterator` interface is suitable:
33+
34+
```PHP
35+
$squares = new SavingIterator(
36+
new SquaringIterator(
37+
[1, 2, 3, 4, 5, 6]
38+
)
39+
);
40+
```
41+
42+
If the origin object is not an `Iterator` then wrap it in `TransparentIterator`:
43+
44+
```PHP
45+
$wrapped = new SavingIterator(
46+
new TransparentIterator($origin)
47+
);
48+
```
49+
50+
## Decorating Generators
51+
52+
You can also use it with `Generators`. If the iterator is called twice, rewind exception will **not** be thrown.
53+
54+
**Attention**: it is not (currently) possible to pass callable as a parameter. You have to manually invoke `Generator` function:
55+
56+
```PHP
57+
function numerals(): Generator {
58+
for ($i = 0; $i < 10; $i++) {
59+
yield $i;
60+
}
61+
}
62+
63+
$numerals = new SavingIterator(numerals());
64+
```
65+
66+
## How to contribute
67+
68+
[Fork this repository](https://docs.github.com/en/get-started/quickstart/fork-a-repo), then create a folder for it and install [Composer](https://getcomposer.org/download/) if you do not have it.
69+
70+
Clone this repository:
71+
72+
```git
73+
git clone https://github.com/MaxGoryunov/saving-iterator
74+
```
75+
76+
Then run:
77+
78+
```bash
79+
composer install
80+
```
81+
82+
This command will install all dependencies required for development. Make changes and [open a pull request](https://github.com/MaxGoryunov/saving-iterator/pulls). Your PR will be reviewed and accepted if it does not fail our build.

0 commit comments

Comments
 (0)