2017 © Pedro Peláez
 

library inline

Inline stack middleware.

image

stack/inline

Inline stack middleware.

  • Tuesday, April 9, 2013
  • by igorw
  • Repository
  • 4 Watchers
  • 5 Stars
  • 209 Installations
  • PHP
  • 5 Dependents
  • 0 Suggesters
  • 2 Forks
  • 3 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Stack/Inline

Inline stack middleware., (*1)

Enables the usage of callables as stack middlewares., (*2)

Example

Here is a contrived example showing how a callable can be used to easily act as a stack middleware for a silex application:, (*3)

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\HttpKernelInterface;

$app = new Silex\Application();

$app->get('/', function (Request $request) {
    if ('success' === $request->attributes->get('callable_middleware')) {
        return new Response('SUCCESS');
    }

    return new Response('FAILED', 500);
});

$inlineMiddleware = function(
    HttpKernelInterface $app,
    Request $request,
    $type = HttpKernelInterface::MASTER_REQUEST,
    $catch = true
) {
    $request->attributes->set('callable_middleware', 'success');

    $response = $app->handle($request, $type, $catch);
    $response->setContent('['.$response->getContent().']');

    return $response;
};

$stack = (new Stack\Builder())
    ->push('Stack\Inline', $inlineMiddleware);

$app = $stack->resolve($app);

Usage

The method signature for the callable is similar to HttpKernelInterface::handle except that it requires an HttpKernelInterface instance as its first argument. A simple passthru inline middleware would look like this:, (*4)

$app = new Stack\Inline($app, function(
    HttpKernelInterface $app,
    Request $request,
    $type = HttpKernelInterface::MASTER_REQUEST,
    $catch = true
) {
    return $app->handle($request, $type, $catch);
});

The Versions

09/04 2013

dev-master

9999999-dev

Inline stack middleware.

  Sources   Download

MIT

The Requires

 

The Development Requires

inline stack callable