ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
AbstractHandler.php
Go to the documentation of this file.
1<?php
9namespace Slim\Handlers;
10
12
16abstract class AbstractHandler
17{
23 protected $knownContentTypes = [
24 'application/json',
25 'application/xml',
26 'text/xml',
27 'text/html',
28 ];
29
40 protected function determineContentType(ServerRequestInterface $request)
41 {
42 $acceptHeader = $request->getHeaderLine('Accept');
43 $selectedContentTypes = array_intersect(explode(',', $acceptHeader), $this->knownContentTypes);
44
45 if (count($selectedContentTypes)) {
46 return current($selectedContentTypes);
47 }
48
49 // handle +json and +xml specially
50 if (preg_match('/\+(json|xml)/', $acceptHeader, $matches)) {
51 $mediaType = 'application/' . $matches[1];
52 if (in_array($mediaType, $this->knownContentTypes)) {
53 return $mediaType;
54 }
55 }
56
57 return 'text/html';
58 }
59}
An exception for terminatinating execution or to throw for unit testing.
Abstract Slim application handler.
determineContentType(ServerRequestInterface $request)
Determine which content type we know about is wanted using Accept header.
getHeaderLine($name)
Retrieves a comma-separated string of the values for a single header.
Representation of an incoming, server-side HTTP request.
Slim Framework (https://slimframework.com)