protected function searchAndValidateRepresentations(array $representations)
{
$representationObjects = [];
foreach ($representations as $representation) {
if (($representationObj = $this->matchRepresentation($representation, $representationObjects)) instanceof AbstractRepresentation) {
return $representationObj;
}
}
// For get requests with "415 for no media match" set on, throw an exception
if ($this->request->getHttpMethod() == Request::METHOD_GET && $this->config->get415ForNoMediaMatchSetting()) {
throw UnableToMatchRepresentationException::noMatch();
}
// Return the first instantiated representation instance
if (isset($representationObjects[0])) {
return $representationObjects[0];
}
return null;
}