mead-steve/spl-fix

This package is abandoned and no longer maintained. No replacement package was suggested.

The spl has some really cool features but some odd naming conventions and some real GOTCHAs. This library is intended to make the spl code easier to use

v0.2.0 2014-02-25 11:00 UTC

This package is auto-updated.

Last update: 2021-03-29 06:14:49 UTC


README

Build Status Latest Stable Version License

The php spl has some really cool feaures but also some bugs/gotchas. This is a library to wrap and hopefully reduce the pain caused by the spl.

Installation

The easiest way to install this library is using composer. In your project's composer.json file add:

    {
        "require": {
            "mead-steve/spl-fix": "dev-master"
        }
    }

Then run composer update.

Fixes

LimitIterator

The limit iterator is very useful if you want to grab a subset of an iterator. Good right? Pass it to count() however and you'll always get a value of 1. This package provides an updated LimitIterator class that correctly implements countable.

EmptyIterator

Fixed so that passing it to count() returns zero. It's empty after all.

FilterIterator

The spl FilterIterator can only be passed an iterator. This is now wrapped so that any traversable can be passed in. This is handled by wrapping the traversable in an IteratorIterator. The following child Iterators have also been wrapped:

  • RegexIterator

Additions

RecursingArrayIterator

This is a short hand for wrapping an array in a RecursiveIterator then wrapping that in a RecursiveIteratorIterator.

Helpers/IteratorWalker

The IteratorWalker allows iterators to be used in the same way arrays are used in array_walk. So that the two snippets will behave in the same way:

    array_walk($array, function($value, $key) {
        echo $key . "=>" . $value;
    });
    $walker = new IteratorWalker($iterator);
    $walker->walk(function($value, $key) {
        echo $key . "=>" . $value;
    });