1 | <?php |
||
38 | abstract class AbstractResponderLocator |
||
39 | { |
||
40 | |||
41 | /** |
||
42 | * Responder factories |
||
43 | * |
||
44 | * @var array |
||
45 | * |
||
46 | * @access protected |
||
47 | */ |
||
48 | protected $factories = []; |
||
49 | |||
50 | /** |
||
51 | * Request |
||
52 | * |
||
53 | * @var Request |
||
54 | * |
||
55 | * @access protected |
||
56 | */ |
||
57 | protected $request; |
||
58 | |||
59 | /** |
||
60 | * Response |
||
61 | * |
||
62 | * @var Response |
||
63 | * |
||
64 | * @access protected |
||
65 | */ |
||
66 | protected $response; |
||
67 | |||
68 | /** |
||
69 | * Payload |
||
70 | * |
||
71 | * @var mixed |
||
72 | * |
||
73 | * @access protected |
||
74 | */ |
||
75 | protected $payload; |
||
76 | |||
77 | /** |
||
78 | * Create a responder locator |
||
79 | * |
||
80 | * @param array $factories factories to create responders |
||
81 | * |
||
82 | * @access public |
||
83 | */ |
||
84 | 5 | public function __construct(array $factories) |
|
88 | |||
89 | /** |
||
90 | * Negotiate and respond |
||
91 | * |
||
92 | * @param Request $request PSR7 Request |
||
93 | * @param Response $response PSR7 Response |
||
94 | * @param PayloadInterface $payload Domain Payload |
||
95 | * |
||
96 | * @return Response |
||
97 | * |
||
98 | * @access public |
||
99 | */ |
||
100 | 4 | public function __invoke( |
|
119 | |||
120 | /** |
||
121 | * Accepts |
||
122 | * |
||
123 | * @return array |
||
124 | * |
||
125 | * @access public |
||
126 | */ |
||
127 | 2 | public function accepts() |
|
131 | |||
132 | /** |
||
133 | * Unavailable |
||
134 | * |
||
135 | * @return Response |
||
136 | * |
||
137 | * @access protected |
||
138 | */ |
||
139 | 1 | protected function notAcceptable() |
|
146 | |||
147 | /** |
||
148 | * Set |
||
149 | * |
||
150 | * @param string $name name/type of responder |
||
151 | * @param calable $callable factory |
||
152 | * |
||
153 | * @return $this |
||
154 | * |
||
155 | * @access public |
||
156 | */ |
||
157 | 1 | public function set($name, callable $callable) |
|
162 | /** |
||
163 | * Does a named helper exist? |
||
164 | * |
||
165 | * @param string $name The responder name. |
||
166 | * |
||
167 | * @return bool |
||
168 | */ |
||
169 | 5 | public function has($name) |
|
173 | |||
174 | /** |
||
175 | * Get a responder |
||
176 | * |
||
177 | * @param string $name The responder to retrieve. |
||
178 | * |
||
179 | * @return object |
||
180 | */ |
||
181 | 4 | public function get($name) |
|
192 | |||
193 | /** |
||
194 | * Negotiate |
||
195 | * |
||
196 | * @param Request $request PSR7 Request |
||
197 | * |
||
198 | * @return string | false |
||
199 | * |
||
200 | * @access protected |
||
201 | */ |
||
202 | abstract protected function negotiate(Request $request); |
||
203 | } |
||
204 |