1 | <?php |
||
16 | class PreviewAction implements MiddlewareInterface |
||
17 | { |
||
18 | use ResponseUtilsTrait; |
||
19 | |||
20 | /** |
||
21 | * @var PreviewGeneratorInterface |
||
22 | */ |
||
23 | private $previewGenerator; |
||
24 | /** |
||
25 | * @var UrlShortenerInterface |
||
26 | */ |
||
27 | private $urlShortener; |
||
28 | |||
29 | /** |
||
30 | * PreviewAction constructor. |
||
31 | * @param PreviewGeneratorInterface $previewGenerator |
||
32 | * @param UrlShortenerInterface $urlShortener |
||
33 | * |
||
34 | * @Inject({PreviewGenerator::class, UrlShortener::class}) |
||
35 | */ |
||
36 | public function __construct(PreviewGeneratorInterface $previewGenerator, UrlShortenerInterface $urlShortener) |
||
41 | |||
42 | /** |
||
43 | * Process an incoming request and/or response. |
||
44 | * |
||
45 | * Accepts a server-side request and a response instance, and does |
||
46 | * something with them. |
||
47 | * |
||
48 | * If the response is not complete and/or further processing would not |
||
49 | * interfere with the work done in the middleware, or if the middleware |
||
50 | * wants to delegate to another process, it can use the `$out` callable |
||
51 | * if present. |
||
52 | * |
||
53 | * If the middleware does not return a value, execution of the current |
||
54 | * request is considered complete, and the response instance provided will |
||
55 | * be considered the response to return. |
||
56 | * |
||
57 | * Alternately, the middleware may return a response instance. |
||
58 | * |
||
59 | * Often, middleware will `return $out();`, with the assumption that a |
||
60 | * later middleware will return a response. |
||
61 | * |
||
62 | * @param Request $request |
||
63 | * @param Response $response |
||
64 | * @param null|callable $out |
||
65 | * @return null|Response |
||
66 | */ |
||
67 | public function __invoke(Request $request, Response $response, callable $out = null) |
||
85 | } |
||
86 |