ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Slim\Handlers\AbstractHandler Class Reference

Abstract Slim application handler. More...

+ Inheritance diagram for Slim\Handlers\AbstractHandler:
+ Collaboration diagram for Slim\Handlers\AbstractHandler:

Protected Member Functions

 determineContentType (ServerRequestInterface $request)
 Determine which content type we know about is wanted using Accept header. More...
 

Protected Attributes

 $knownContentTypes
 

Detailed Description

Abstract Slim application handler.

Definition at line 16 of file AbstractHandler.php.

Member Function Documentation

◆ determineContentType()

Slim\Handlers\AbstractHandler::determineContentType ( ServerRequestInterface  $request)
protected

Determine which content type we know about is wanted using Accept header.

Note: This method is a bare-bones implementation designed specifically for Slim's error handling requirements. Consider a fully-feature solution such as willdurand/negotiation for any other situation.

Parameters
ServerRequestInterface$request
Returns
string

Definition at line 40 of file AbstractHandler.php.

References Psr\Http\Message\MessageInterface\getHeaderLine().

Referenced by Slim\Handlers\NotFound\__invoke(), Slim\Handlers\PhpError\__invoke(), Slim\Handlers\NotAllowed\__invoke(), and Slim\Handlers\Error\__invoke().

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  }
foreach($paths as $path) $request
Definition: asyncclient.php:32
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $knownContentTypes

Slim\Handlers\AbstractHandler::$knownContentTypes
protected
Initial value:
= [
'application/json',
'application/xml',
'text/xml',
'text/html',
]

Definition at line 23 of file AbstractHandler.php.


The documentation for this class was generated from the following file: