1 | <?php |
||
14 | class CacheRouter implements MiddlewareInterface |
||
15 | { |
||
16 | /** |
||
17 | * @var CacheInterface |
||
18 | */ |
||
19 | private $cache; |
||
20 | |||
21 | /** |
||
22 | * @var ConditionInterface |
||
23 | */ |
||
24 | private $cacheCondition; |
||
25 | |||
26 | /** |
||
27 | * @var LoggerInterface |
||
28 | */ |
||
29 | private $log; |
||
30 | |||
31 | public function __construct(CacheInterface $cache, LoggerInterface $log, ConditionInterface $cacheCondition) |
||
37 | |||
38 | /** |
||
39 | * Process an incoming request and/or response. |
||
40 | * |
||
41 | * Accepts a server-side request and a response instance, and does |
||
42 | * something with them. |
||
43 | * |
||
44 | * If the response is not complete and/or further processing would not |
||
45 | * interfere with the work done in the middleware, or if the middleware |
||
46 | * wants to delegate to another process, it can use the `$out` callable |
||
47 | * if present. |
||
48 | * |
||
49 | * If the middleware does not return a value, execution of the current |
||
50 | * request is considered complete, and the response instance provided will |
||
51 | * be considered the response to return. |
||
52 | * |
||
53 | * Alternately, the middleware may return a response instance. |
||
54 | * |
||
55 | * Often, middleware will `return $out();`, with the assumption that a |
||
56 | * later middleware will return a response. |
||
57 | * |
||
58 | * @param ServerRequestInterface $request |
||
59 | * @param ResponseInterface $response |
||
60 | * @param null|callable $out |
||
61 | * |
||
62 | * @return null|ResponseInterface |
||
63 | */ |
||
64 | public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $out = null) |
||
131 | } |
||
132 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: