Phly\Conduit\MiddlewarePipe::pipe PHP Méthode

pipe() public méthode

Each middleware can be associated with a particular path; if that path is matched when that middleware is invoked, it will be processed; otherwise it is skipped. No path means it should be executed every request cycle. A handler CAN implement MiddlewareInterface, but MUST be callable. Handlers with arity >= 4 or those implementing ErrorMiddlewareInterface are considered error handlers, and will be executed when a handler calls $next with an error or raises an exception.
See also: MiddlewareInterface
See also: ErrorMiddlewareInterface
See also: Next
public pipe ( string | callable | object $path, null | callable | object $middleware = null ) : self
$path string | callable | object Either a URI path prefix, or middleware.
$middleware null | callable | object Middleware
Résultat self
    public function pipe($path, $middleware = null)
    {
        if (null === $middleware && is_callable($path)) {
            $middleware = $path;
            $path = '/';
        }
        // Ensure we have a valid handler
        if (!is_callable($middleware)) {
            throw new InvalidArgumentException('Middleware must be callable');
        }
        $this->pipeline->enqueue(new Route($this->normalizePipePath($path), $middleware));
        // @todo Trigger event here with route details?
        return $this;
    }

Usage Example

<?php

use Phly\Conduit\MiddlewarePipe;
use Application\NotFound;
return call_user_func(function () {
    $services = (include 'config/services.php');
    $app = new MiddlewarePipe();
    // basics eg.redirect
    // site 1
    $app->pipe($services->get('Sample\\Module'));
    // errors
    $app->pipe(new NotFound());
    // authentication
    // error handler
    $app->pipe($services->get('ErrorHandler'));
    return $app;
});
All Usage Examples Of Phly\Conduit\MiddlewarePipe::pipe