innmind/stack

Helper to build stacks

1.2.0 2021-02-15 16:02 UTC

This package is auto-updated.

Last update: 2024-11-15 23:55:44 UTC


README

codecov Build Status Type Coverage

Simple function to stack elements on top of each others. Useful to create object stacks.

Installation

composer require innmind/stack

Usage

use function Innmind\Stack\stack;

$decorate = stack(
    static function(RequestHandler $handler) {
        return new ValidateRequest($handler);
    },
    static function(RequestHandler $handler) {
        return new Security($handler);
    }
);
$handler = $decorate(new MyRequestHandler);

The above example is equivalent to:

$handler = new ValidateRequest(
    new Security(
        new MyRequestHandler
    )
);

Note: the classes uses do not exist, they're only meant as an example.