diff --git a/source/_views/default.html b/source/_views/default.html index f1977ef..0b1d849 100644 --- a/source/_views/default.html +++ b/source/_views/default.html @@ -21,12 +21,12 @@
  • Home
  • +
  • + Example +
  • Middlewares
  • -
  • - Toolbox -
  • Conventions
  • diff --git a/source/example.html b/source/example.html new file mode 100644 index 0000000..467c7b4 --- /dev/null +++ b/source/example.html @@ -0,0 +1,44 @@ +--- +layout: default +title: Example +nav_name: example +--- +{% block content %} +
    +

    Middlewares

    +

    Creating a new middleware is generally quite easy. The hardest part is grasping the decorator pattern.

    +

    A decorator is simply an object that wraps around an other object. In this case a middleware is a decorator for HttpKernelInterface. The decorator wraps around a kernel, and exposes the same interface.

    +

    Let's take a look at an PoweredByStack middleware, that adds a `X-Powered-By` header to all responses.

    +
    {%- filter escape -%}use Symfony\Component\HttpFoundation\Request;
    +use Symfony\Component\HttpKernel\HttpKernelInterface;
    +
    +class PoweredByStack implements HttpKernelInterface
    +{
    +    private $app;
    +
    +    public function __construct(HttpKernelInterface $app)
    +    {
    +        $this->app = $app;
    +    }
    +
    +    public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true)
    +    {
    +        $response = $this->app->handle($request, $type, $catch);
    +        $response->headers->set('X-Powered-By', 'Stack');
    +        return $response;
    +    }
    +}{%- endfilter -%}
    +

    This middleware takes a kernel in the constructor and delegates to this kernel from within handle. Then it augments the response. It decorates the handle call.

    +

    Here is an example of how you could use this middleware with Silex. Note that you can replace Silex with any kernel implementation.

    +
    {%- filter escape -%}$app = new Silex\Application();
    +
    +$app->get('/', function () {
    +    return 'Hello World!';
    +});
    +
    +$app = new PoweredByStack($app);
    +
    +Stack\run($app);{%- endfilter -%}
    +

    This will return a "Hello World" body, but have the extra `X-Powered-By: Stack` header.

    +
    +{% endblock %} diff --git a/source/middlewares.html b/source/middlewares.html index dbb5f48..98c64dc 100644 --- a/source/middlewares.html +++ b/source/middlewares.html @@ -1,11 +1,35 @@ --- layout: default -title: Community Middlewares +title: Middlewares nav_name: middlewares --- {% block content %}
    -

    Community Middlewares

    +

    Middlewares

    +
    +
    +

    Session

    +

    + by stack +

    +

    Provides a request session for subsequent middlewares. Based on the Silex SessionServiceProvider.

    + +
    +
    +

    UrlMap

    +

    + by stack +

    +

    Provides the ability to map paths to specific HttpKernelInterface applications and dispatches accordingly.

    + +
    +

    HttpCache

    @@ -103,4 +127,38 @@

    + +
    + +
    +

    Toolbox

    +
    +
    +

    Builder

    +

    Builder constructs a nested HttpKernelInterface decorator tree. It models it as a stack of middlewares.

    + +
    +
    +

    Run

    +

    Shortcut function for handling HttpKernel front-controller boilerplate.

    + +
    +
    +
    +
    +

    Lazy Kernel

    +

    A lazy proxy for HttpKernelInterface, allows an app to be loaded on demand when combined with URL Map.

    + +
    +
    +
    {% endblock %} diff --git a/source/toolbox.html b/source/toolbox.html deleted file mode 100644 index 276d650..0000000 --- a/source/toolbox.html +++ /dev/null @@ -1,46 +0,0 @@ ---- -layout: default -title: The Toolbox -nav_name: toolbox ---- -{% block content %} -
    -

    The Toolbox

    -
    -
    -

    Builder

    -

    Builder constructs a nested HttpKernelInterface decorator tree. It models it as a stack of middlewares.

    - -
    -
    -

    Session

    -

    Provides a request session for subsequent middlewares. Based on the Silex SessionServiceProvider.

    - -
    -
    -
    -
    -

    URL Map

    -

    Provides the ability to map paths to specific HttpKernelInterface applications and dispatches accordingly.

    - -
    -
    -

    Lazy Kernel

    -

    A lazy proxy for HttpKernelInterface, allows an app to be loaded on demand when combined with URL Map.

    - -
    -
    -
    -{% endblock %}