PHPackages                             cansozeri/iterators-magic - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. cansozeri/iterators-magic

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

cansozeri/iterators-magic
=========================

OOP structure extends the PHP \\Iterator class

06PHP

Since Mar 26Pushed 8y ago1 watchersCompare

[ Source](https://github.com/cansozeri/iterators-magic)[ Packagist](https://packagist.org/packages/cansozeri/iterators-magic)[ RSS](/packages/cansozeri-iterators-magic/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Iterators Magic
===============

[](#iterators-magic)

Iterators magic is a way to iterate everything (folder - files - pdo vs.) with OOP structure.

Gives you, the separation of concerns and extendable class structure while you have an iterator with a renderer class.

Please don't hesitate to contribute if you have different opinion that you want to share.

Usage
-----

[](#usage)

You can use any **renderer** class to render result of the Iteration class ( SPL class )

There is an example in project that called HtmlDirectoryRenderer to print the results to a page with html design.

```
$data = new HtmlDirectoryRenderer(
    new LocalDirectoryIterator('/var/www')
);

$data->render();
```

**Iterator Class use IteratorAggregate interface and getIterator() method for iteration.**

You can change easily DirectoryIterator and Renderer Type.

For example if you want to iterate a remote directory folder with a ftp connection,

You can create a class FtpDirectoryIterator :

You can pass configuration with AbstractDirectoryIterator to your main Iterator class.

```
$data = new HtmlDirectoryRenderer(
    new FtpDirectoryIterator('/var/www',$config)
);

$data->render();
```

**TreeIterator**

TreeIterator example of view folder structure as tree view.

```
$data = new TreeDirectoryRenderer(
    new TreeDirectoryIterator('/var/www/playground')
);

$data->render();

//Output
[tree]
├ /var/www/playground/app
├ /var/www/playground/package.json
├ /var/www/playground/gulpfile.js
├ /var/www/playground/.git
├ /var/www/playground/config.js
├ /var/www/playground/.babelrc
├ /var/www/playground/readme.md
├ /var/www/playground/.gitignore
├ /var/www/playground/merger
├ /var/www/playground/public
└ /var/www/playground/.idea
```

Filters
-------

[](#filters)

You can define filters to filter your iteration. You can create custom filter easily in your Filter class and you can just define with an array. ```
$filters = [
    [
        'filter'=>'extension',
        'extensions'=>['php', 'html', 'js', 'tpl']
    ],
    [
        'filter'=>'search_in_file',
        'needle'=>'youtube'
    ]
];

$data = new HtmlDirectoryRenderer(
    new LocalDirectoryIterator('/var/www/playground'),
    $filters
);

$data->render();
```

**Filters must return SPL directory File Info ( $this-&gt;directory ) or false (break out filter queue)**

```
protected function ExtensionFilter($filter)
{
    $extensions = $filter['extensions'];

    return in_array($this->directory->getExtension(), $extensions) === true?$this->directory:false;
}
```

###  Health Score

19

—

LowBetter than 10% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/1e9bbe4a0a593616961ad5df2edbaa86e1677a166a87735f1f97dbb1d05f4824?d=identicon)[cansozeri](/maintainers/cansozeri)

### Embed Badge

![Health badge](/badges/cansozeri-iterators-magic/health.svg)

```
[![Health](https://phpackages.com/badges/cansozeri-iterators-magic/health.svg)](https://phpackages.com/packages/cansozeri-iterators-magic)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
