1 | <?php |
||
15 | abstract class AbstractAccept extends AbstractCallbackMediator implements |
||
16 | ProxyableBy, |
||
17 | ProxyableThrough, |
||
18 | Unique, |
||
19 | IgnorableFileExtension |
||
20 | { |
||
21 | protected $negotiated = null; |
||
22 | protected $request_uri; |
||
23 | |||
24 | 27 | protected function identifyRequested(Request $request, $params) |
|
|
|||
25 | { |
||
26 | 27 | $this->request_uri = $request->uri; |
|
27 | |||
28 | 27 | if (!isset($_SERVER[static::ACCEPT_HEADER])) { |
|
29 | return array(); |
||
30 | } |
||
31 | 27 | $acceptHeader = $_SERVER[static::ACCEPT_HEADER]; |
|
32 | 27 | $acceptParts = explode(',', $acceptHeader); |
|
33 | 27 | $acceptList = array(); |
|
34 | 27 | foreach ($acceptParts as $k => &$acceptPart) { |
|
35 | 27 | $parts = explode(';q=', trim($acceptPart)); |
|
36 | 27 | $provided = array_shift($parts); |
|
37 | 27 | $quality = array_shift($parts) ?: (10000 - $k) / 10000; |
|
38 | 27 | $acceptList[$provided] = $quality; |
|
39 | 27 | } |
|
40 | 27 | arsort($acceptList); |
|
41 | |||
42 | 27 | return array_keys($acceptList); |
|
43 | } |
||
44 | 27 | protected function considerProvisions($requested) |
|
48 | 26 | protected function notifyApproved($requested, $provided, Request $request, $params) |
|
49 | { |
||
80 | |||
81 | 10 | protected function authorize($requested, $provided) |
|
93 | |||
94 | 23 | public function by(Request $request, $params) |
|
110 | |||
111 | 23 | public function through(Request $request, $params) |
|
120 | } |
||
121 |
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: