[FEATURE] Add support for PSR-15 HTTP middlewares
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Documentation / Changelog / master / Feature-83725-SupportForPSR-15HTTPMiddlewares.rst
1 .. include:: ../../Includes.txt
2
3 =====================================================
4 Feature: #83725 - Support for PSR-15 HTTP middlewares
5 =====================================================
6
7 See :issue:`83725`
8
9 Description
10 ===========
11
12 Support for PSR-15 style HTTP middlewares has been added for frontend and backend requests.
13
14 PSR-15 implements middlewares (any kind of PHP functionality) which act as layers before the actual
15 request handlers do their work. Any layer can be added at any point of the request to enrich / exchange a
16 HTTP request or response object (PSR-7), to add functionality or do early returns of a different Response object
17 (Access denied to a specific request).
18
19 Basic examples of middleware are layers for authentication or security, or handling of Exceptions (like
20 TYPO3's `PageNotFoundException`) to produce HTTP response objects.
21
22 Adding PSR-15 to TYPO3 allows to restructure TYPO3's existing PHP classes into smaller chunks, while giving
23 Site developers the possibility to add a layer at a specific place (via TYPO3's dependency ordering).
24
25 Middlewares in TYPO3 are added into Middleware stacks as not every middleware needs to be called for every HTTP request.
26 Currently TYPO3 supports a generic "frontend" stack and a "backend" stack, for any TYPO3 Frontend requests or
27 TYPO3 Backend requests. These stacks are then processed before the actual Request Handler
28 (implementing PSR-15 RequestHandlerInterface) handles the actual logic. The Request Handler produces a PSR-7 Response
29 object which is then sent back through all middlewares of a stack.
30
31 Impact
32 ======
33
34 To add a middleware to the "frontend" or backend middleware stack, create the
35 :file:`Configuration/RequestMiddlewares.php` in the respective extension:
36
37 .. code-block:: php
38
39 return [
40 // stack name: currently 'frontend' or 'backend'
41 'frontend' => [
42 'middleware-identifier' => [
43 'target' => \ACME\Ext\Middleware::class,
44 'description' => '',
45 'before' => [
46 'another-middleware-identifier',
47 ],
48 'after' => [
49 'yet-another-middleware-identifier',
50 ],
51 ]
52 ]
53 ];
54
55
56 .. index:: Backend, Frontend, PHP-API, NotScanned