Skip to content

Commit ed4e681

Browse files
committed
Use simpler Powered-By header
1 parent 0df5599 commit ed4e681

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

source/example.html

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,27 @@
44
nav_name: example
55
---
66
{% block content %}
7-
<div class="examples">
8-
<h2>Creating middlewares</h2>
7+
<div class="example">
8+
<h2>Middlewares</h2>
99
<p>Creating a new middleware is generally quite easy. The hardest part is grasping the decorator pattern.</p>
1010
<p>A decorator is simply an object that wraps around an other object. In this case a middleware is a decorator for <code>HttpKernelInterface</code>. The decorator wraps around a kernel, and exposes the same interface.</p>
11-
<p>Let's take a look at an <code>Append</code> middleware, that appends a pre-configured string to all response bodies.</p>
11+
<p>Let's take a look at an <code>PoweredByStack</code> middleware, that adds a `X-Powered-By` header to all responses.</p>
1212
<pre><code class="php">{%- filter escape -%}use Symfony\Component\HttpFoundation\Request;
1313
use Symfony\Component\HttpKernel\HttpKernelInterface;
1414

15-
class Append implements HttpKernelInterface
15+
class PoweredByStack implements HttpKernelInterface
1616
{
17-
protected $app;
18-
protected $append;
17+
private $app;
1918

20-
public function __construct(HttpKernelInterface $app, $append)
19+
public function __construct(HttpKernelInterface $app)
2120
{
2221
$this->app = $app;
23-
$this->append = $append;
2422
}
2523

2624
public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true)
2725
{
2826
$response = $this->app->handle($request, $type, $catch);
29-
$response->setContent($response->getContent().$this->append);
27+
$response->headers->set('X-Powered-By', 'Stack');
3028
return $response;
3129
}
3230
}{%- endfilter -%}</code></pre>
@@ -38,9 +36,9 @@ <h2>Creating middlewares</h2>
3836
return 'Hello World!';
3937
});
4038

41-
$app = new Append($app, ' FOO');
39+
$app = new PoweredByStack($app);
4240

4341
Stack\run($app);{%- endfilter -%}</code></pre>
44-
<p>This will return a response body of "Hello World! FOO" when accessing the <code>/</code> resource.</p>
42+
<p>This will return a "Hello World" body, but have the extra `X-Powered-By: Stack` header.</p>
4543
</div>
4644
{% endblock %}

0 commit comments

Comments
 (0)