1 | <?php |
||
27 | abstract class AbstractAdapter implements ServiceInterface |
||
28 | { |
||
29 | /** @var Throwable */ |
||
30 | public $error; |
||
31 | /** @var DependencyInjectionInterface */ |
||
32 | protected $container; |
||
33 | /** @var ServerRequestInterface */ |
||
34 | protected $request; |
||
35 | /** @var ResponseInterface */ |
||
36 | protected $response; |
||
37 | /** @var I18nInterface */ |
||
38 | protected $i18n; |
||
39 | |||
40 | /** |
||
41 | * ServiceAdapter constructor. |
||
42 | * |
||
43 | * @param DependencyInjectionInterface $container |
||
44 | */ |
||
45 | 11 | public function __construct(DependencyInjectionInterface $container) |
|
55 | |||
56 | /** |
||
57 | * Starts the session. |
||
58 | * |
||
59 | * @return ServiceInterface |
||
60 | */ |
||
61 | abstract public function initSession() : ServiceInterface; |
||
62 | |||
63 | /** |
||
64 | * Initializes the I18n Service. |
||
65 | * |
||
66 | * @return ServiceInterface |
||
67 | */ |
||
68 | public function initInternationalization() : ServiceInterface |
||
74 | |||
75 | /** |
||
76 | * Runs the application. This is where the magic happens. |
||
77 | * According tho the environment settings this must build up the middleware pipeline and execute it. |
||
78 | * |
||
79 | * a Pre-Routing Middleware can be; priority < 0: |
||
80 | * - LockCheck - check if the client IP is banned > S102|S403 |
||
81 | * - Auth - if the user is not logged in, but there's a "Remember me" cookie, then logs in > S102 |
||
82 | * |
||
83 | * Routing Middleware is fixed (RoutingMiddleware::class); priority = 0: |
||
84 | * - A middleware that routes the incoming Request and delegates to the matched middleware. > S102|S404|S405 |
||
85 | * The RouteResult should be attached to the Request. |
||
86 | * If the Routing is not defined explicitly in the pipeline, then it will be injected with priority 0. |
||
87 | * |
||
88 | * a Post-Routing Middleware can be; priority between 0 and 100: |
||
89 | * - Acl - checks if the given route is available for the client. Also checks the auth > S102|S401|S403 |
||
90 | * - CacheReader - checks if a suitable response body is cached. > S102|S200 |
||
91 | * |
||
92 | * Dispatcher Middleware is fixed (DispatcherMiddleware::class); priority = 100: |
||
93 | * - A middleware which gets the corresponding Action middleware and applies it > S102 |
||
94 | * If the Dispatcher is not defined explicitly in the pipeline, then it will be injected with priority 100. |
||
95 | * The Dispatcher should not set the response Status Code to 200 to let Post-Dispatchers to be called. |
||
96 | * |
||
97 | * a Post-Dispatch Middleware can be; priority > 100: |
||
98 | * - CacheWriter - writes response body into DataStorage (DB, File etc.) > S102 |
||
99 | * |
||
100 | * Final Middleware is fixed (FinalMiddleware:class): |
||
101 | * - This middleware behaves a bit differently. It cannot be ordered, it's always the last called middleware: |
||
102 | * - when the middleware pipeline reached its end (typically when the Status Code is still 102) |
||
103 | * - when one item of the middleware pipeline returns with return response (status code is set to 200|40*|500) |
||
104 | * - when during the pipeline process an Exception is thrown. |
||
105 | * |
||
106 | * When the middleware pipeline is finished the application prints the header and the output. |
||
107 | * |
||
108 | * If a middleware other than the Routing, Dispatcher and Final Middleware has no priority set, it will be |
||
109 | * considered to have priority = 50. |
||
110 | * |
||
111 | * @return ServiceInterface |
||
112 | */ |
||
113 | abstract public function run() : ServiceInterface; |
||
114 | |||
115 | /** |
||
116 | * Renders the response body and sends it to the client. |
||
117 | * |
||
118 | * @return void |
||
119 | * |
||
120 | * @codeCoverageIgnore - no output for tests |
||
121 | */ |
||
122 | abstract public function renderOutput() : void; |
||
123 | |||
124 | /** |
||
125 | * Sends the response body to the client. |
||
126 | * |
||
127 | * @return void |
||
128 | * |
||
129 | * @codeCoverageIgnore - no output for tests |
||
130 | */ |
||
131 | abstract public function sendOutput() : void; |
||
132 | } |
||
133 |