Skip to content

Latest commit

 

History

History
85 lines (79 loc) · 1.64 KB

pipeline.md

File metadata and controls

85 lines (79 loc) · 1.64 KB

Pipeline

Introduction

The pipeline pattern is perfect to execute security concepts or modifiers before a core logic.

Examples

Example 1

Source Code:

use TinyFramework\Core\Pipeline;

/** @var mixed $parameter */
$parameter = null;
$p = new Pipeline();
$p->layers(function($parameter, Closure $next) {
    echo "Layer1:start\n";
    $response = $next($parameter);
    echo "Layer1:end\n";
    return $response;
});
$p->layers(function($parameter, Closure $next) {
    echo "Layer2:start\n";
    $response = $next($parameter);
    echo "Layer2:end\n";
    return $response;
});
$p->layers(function($parameter, Closure $next) {
    echo "Layer3:start\n";
    $response = $next($parameter);
    echo "Layer3:end\n";
    return $response;
});
$p->call(function($parameter) {
    echo "Core\n";
}, $parameter);

Output:

Layer1:start
Layer1:start
Layer1:start
Core
Layer3:end
Layer2:end
Layer1:end

Example 2

Source Code:

use TinyFramework\Core\Pipeline;

/** @var mixed $parameter */
$parameter = null;
$p = new Pipeline();
$p->layers(function($parameter, Closure $next) {
    echo "Layer1:start\n";
    $response = $next($parameter);
    echo "Layer1:end\n";
    return $response;
});
$p->layers(function($parameter, Closure $next) {
    echo "Layer2:start\n";
    echo "Layer2:end\n";
    return null;
});
$p->layers(function($parameter, Closure $next) {
    echo "Layer3:start\n";
    $response = $next($parameter);
    echo "Layer3:end\n";
    return $response;
});
$p->call(function($parameter) {
    echo "Core\n";
}, $parameter);

Output:

Layer1:start
Layer1:start
Layer2:end
Layer1:end