Code Monkey home page Code Monkey logo

pipeline's Introduction

pipeline

简体中文 | ENGLISH

An elegant PHP middleware pipeline. - 一个优雅的 PHP 中间件管道。

Tests Check & fix styling codecov Latest Stable Version Total Downloads License

Requirement

  • PHP >= 7.2

Installation

$ composer require guanguans/pipeline --prefer-dist -vvv

Usage

Code

<?php
require __DIR__.'/vendor/autoload.php';

use Guanguans\Pipeline\Pipeline;

(new Pipeline())
    ->send('passable')
    ->through(
        function ($passable, Closure $next){
            echo '1. Before apply first middleware.'.PHP_EOL;
            $next($passable);
            echo '7. After apply first middleware.'.PHP_EOL;
        },
        function ($passable, Closure $next){
            echo '2. Before apply second middleware.'.PHP_EOL;
            $next($passable);
            echo '6. After apply second middleware.'.PHP_EOL;
        },
        function ($passable, Closure $next){
            echo '3. Before apply third middleware.'.PHP_EOL;
            $next($passable);
            echo '5. After apply third middleware.'.PHP_EOL;
        }
    )
    // ->via('differentMethod')
    // ->thenReturn()
    ->then(function ($passable){
        echo '4. Middleware is finished.'.PHP_EOL;

        return $passable;
    });

Output

1. Before apply first middleware.
2. Before apply second middleware.
3. Before apply third middleware.
4. Middleware is finished.
5. After apply third middleware.
6. After apply second middleware.
7. After apply first middleware.

Testing

$ composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

pipeline's People

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

vartruexuan

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.