1 | <?php |
||
36 | class AcceptHandler |
||
37 | { |
||
38 | use AcceptRequestAwareTrait; |
||
39 | |||
40 | /** |
||
41 | * Accept Factory Factory |
||
42 | * |
||
43 | * @var callable |
||
44 | * |
||
45 | * @access protected |
||
46 | */ |
||
47 | protected $acceptFactoryFactory; |
||
48 | |||
49 | /** |
||
50 | * Media types |
||
51 | * A map of file .extensions to media types |
||
52 | * |
||
53 | * @var array |
||
54 | * |
||
55 | * @access protected |
||
56 | */ |
||
57 | protected $mediaTypes = []; |
||
58 | |||
59 | /** |
||
60 | * Create an AcceptHandler |
||
61 | * |
||
62 | * @param callable $acceptFactoryFactory factory to create an AcceptFactory |
||
63 | * |
||
64 | * @access public |
||
65 | */ |
||
66 | 2 | public function __construct(callable $acceptFactoryFactory = null) |
|
71 | |||
72 | /** |
||
73 | * Adds Accept object to request |
||
74 | * |
||
75 | * @param Request $request PSR7 HTTP Request |
||
76 | * @param Response $response PSR7 HTTP Response |
||
77 | * @param callable $next Next callable middleware |
||
78 | * |
||
79 | * @return Response |
||
80 | * |
||
81 | * @access public |
||
82 | */ |
||
83 | 2 | public function __invoke(Request $request, Response $response, callable $next) |
|
84 | { |
||
85 | 2 | $request = $request->withAttribute( |
|
86 | 2 | $this->acceptAttribute, |
|
87 | 2 | $this->newAccept($request) |
|
88 | ); |
||
89 | 2 | return $next($request, $response); |
|
90 | } |
||
91 | |||
92 | /** |
||
93 | * Set media types |
||
94 | * |
||
95 | * @param array $types A map of file .extensions to media types |
||
96 | * |
||
97 | * @return $this |
||
98 | * |
||
99 | * @access public |
||
100 | */ |
||
101 | 1 | public function setMediaTypes(array $types) |
|
106 | |||
107 | /** |
||
108 | * Create a new AcceptFactory |
||
109 | * |
||
110 | * @param array $server representing $_SERVER |
||
111 | * @param array $types Media Types array |
||
112 | * |
||
113 | * @return AcceptFactory |
||
114 | * |
||
115 | * @access protected |
||
116 | */ |
||
117 | 1 | protected function newAcceptFactory(array $server, array $types) |
|
121 | |||
122 | /** |
||
123 | * Create a new Accept |
||
124 | * |
||
125 | * @param Request $request PSR7 Request |
||
126 | * |
||
127 | * @return Accept |
||
128 | * |
||
129 | * @access protected |
||
130 | */ |
||
131 | 2 | protected function newAccept(Request $request) |
|
137 | } |
||
138 |