1 | <?php |
||
21 | class Accepts implements RuleInterface |
||
22 | { |
||
23 | /** |
||
24 | * |
||
25 | * Check that the request Accept headers match one Route accept value. |
||
26 | * |
||
27 | * @param ServerRequestInterface $request The HTTP request. |
||
28 | * |
||
29 | * @param Route $route The route. |
||
30 | * |
||
31 | * @return bool True on success, false on failure. |
||
32 | * |
||
33 | */ |
||
34 | 4 | public function __invoke(ServerRequestInterface $request, Route $route) |
|
35 | { |
||
36 | 4 | if (! $route->accepts) { |
|
37 | 3 | return true; |
|
38 | } |
||
39 | |||
40 | 1 | $requestAccepts = $request->getHeader('Accept'); |
|
41 | 1 | if (! $requestAccepts) { |
|
42 | 1 | return true; |
|
43 | } |
||
44 | |||
45 | 1 | return $this->matches($route->accepts, $requestAccepts); |
|
46 | } |
||
47 | |||
48 | /** |
||
49 | * |
||
50 | * Does what the route accepts match what the request accepts? |
||
51 | * |
||
52 | * @param array $routeAccepts What the route accepts. |
||
53 | * |
||
54 | * @param array $requestAccepts What the request accepts. |
||
55 | * |
||
56 | * @return bool |
||
57 | * |
||
58 | */ |
||
59 | 1 | protected function matches($routeAccepts, $requestAccepts) |
|
74 | |||
75 | /** |
||
76 | * |
||
77 | * Is the Accept header a match? |
||
78 | * |
||
79 | * @param string $type The Route accept type. |
||
80 | * |
||
81 | * @param string $header The Request accept header. |
||
82 | * |
||
83 | * @return bool True on a match, false if not. |
||
84 | * |
||
85 | */ |
||
86 | 1 | protected function match($type, $header) |
|
104 | } |
||
105 |
Since your code implements the magic setter
_set
, this function will be called for any write access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.Since the property has write access only, you can use the @property-write annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.