1 | <?php |
||
11 | class Middleware |
||
12 | { |
||
13 | const KEY = 'Psr7Middlewares\\Middleware'; |
||
14 | |||
15 | private static $streamFactory; |
||
16 | |||
17 | /** |
||
18 | * Set the stream factory used by some middlewares. |
||
19 | * |
||
20 | * @param callable $streamFactory |
||
21 | */ |
||
22 | public static function setStreamFactory(callable $streamFactory) |
||
26 | |||
27 | /** |
||
28 | * Get the stream factory. |
||
29 | * |
||
30 | * @return StreamInterface |
||
31 | */ |
||
32 | public static function createStream($file = 'php://temp', $mode = 'r+') |
||
44 | |||
45 | /** |
||
46 | * Create instances of the middlewares. |
||
47 | * |
||
48 | * @param string $name |
||
49 | * @param array $args |
||
50 | */ |
||
51 | public static function __callStatic($name, $args) |
||
70 | |||
71 | /** |
||
72 | * Create a middleware callable that acts as a "proxy" to a real middleware that must be returned by the given callback. |
||
73 | * |
||
74 | * @param callable $factory Takes no argument and MUST return a middleware callable or false |
||
75 | * |
||
76 | * @return callable |
||
77 | */ |
||
78 | public static function create(callable $factory) |
||
94 | |||
95 | /** |
||
96 | * Store an attribute in the request. |
||
97 | * |
||
98 | * @param ServerRequestInterface $request |
||
99 | * @param string $name |
||
100 | * @param mixed $value |
||
101 | * |
||
102 | * @return ServerRequestInterface |
||
103 | */ |
||
104 | public static function setAttribute(ServerRequestInterface $request, $name, $value) |
||
111 | |||
112 | /** |
||
113 | * Retrieves an attribute from the request. |
||
114 | * |
||
115 | * @param ServerRequestInterface $request |
||
116 | * @param string $name |
||
117 | * |
||
118 | * @return mixed |
||
119 | */ |
||
120 | public static function getAttribute(ServerRequestInterface $request, $name) |
||
128 | |||
129 | /** |
||
130 | * Check whether an attribute exists. |
||
131 | * |
||
132 | * @param ServerRequestInterface $request |
||
133 | * @param string $name |
||
134 | * |
||
135 | * @return bool |
||
136 | */ |
||
137 | public static function hasAttribute(ServerRequestInterface $request, $name) |
||
147 | } |
||
148 |