From 9391b63ee8340b93eee50cad69e6023871af74d0 Mon Sep 17 00:00:00 2001 From: Michael Bessolov Date: Mon, 13 Apr 2015 16:30:11 -0700 Subject: [PATCH] Syntax highlighting in code samples (GFM) --- README.md | 69 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 36 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index 02db9e7..037bdc7 100644 --- a/README.md +++ b/README.md @@ -10,39 +10,40 @@ Enables the usage of callables as stack middlewares. Here is a contrived example showing how a callable can be used to easily act as a stack middleware for a silex application: - use Symfony\Component\HttpFoundation\Request; - use Symfony\Component\HttpFoundation\Response; - use Symfony\Component\HttpKernel\HttpKernelInterface; +```php +use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\HttpKernel\HttpKernelInterface; - $app = new Silex\Application(); +$app = new Silex\Application(); - $app->get('/', function (Request $request) { - if ('success' === $request->attributes->get('callable_middleware')) { - return new Response('SUCCESS'); - } +$app->get('/', function (Request $request) { + if ('success' === $request->attributes->get('callable_middleware')) { + return new Response('SUCCESS'); + } - return new Response('FAILED', 500); - }); + return new Response('FAILED', 500); +}); - $inlineMiddleware = function( - HttpKernelInterface $app, - Request $request, - $type = HttpKernelInterface::MASTER_REQUEST, - $catch = true - ) { - $request->attributes->set('callable_middleware', 'success'); +$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().']'); + $response = $app->handle($request, $type, $catch); + $response->setContent('['.$response->getContent().']'); - return $response; - }; + return $response; +}; - $stack = (new Stack\Builder()) - ->push('Stack\Inline', $inlineMiddleware); - - $app = $stack->resolve($app); +$stack = (new Stack\Builder()) + ->push('Stack\Inline', $inlineMiddleware); +$app = $stack->resolve($app); +``` ## Usage @@ -50,11 +51,13 @@ 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: - $app = new Stack\Inline($app, function( - HttpKernelInterface $app, - Request $request, - $type = HttpKernelInterface::MASTER_REQUEST, - $catch = true - ) { - return $app->handle($request, $type, $catch); - }); +```php +$app = new Stack\Inline($app, function( + HttpKernelInterface $app, + Request $request, + $type = HttpKernelInterface::MASTER_REQUEST, + $catch = true +) { + return $app->handle($request, $type, $catch); +}); +```