Drest\Manager\Representation::searchAndValidateRepresentations PHP Method

searchAndValidateRepresentations() protected method

Iterate through an array of representations and return a match
protected searchAndValidateRepresentations ( array $representations ) : DrestCommon\Representation\AbstractRepresentation | null
$representations array
return DrestCommon\Representation\AbstractRepresentation | null
    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;
    }