/** * Set the response formats accepted by the requesting agents. * * @param string $accept HTTP Accept header */ public function setAcceptType($accept) { // HTTP/1.1 Accept Header Definition: // ---------------------------------- // // Accept = "Accept" ":" // #( media-range [ accept-params ] ) // // media-range = ( "*/*" // | ( type "/" "*" ) // | ( type "/" subtype ) // ) *( ";" parameter ) // accept-params = ";" "q" "=" qvalue *( accept-extension ) // accept-extension = ";" token [ "=" ( token | quoted-string ) ] // $this->acceptType = explode(', ', $accept); $re = '/(\\*|[^\\/,;=\\s]+)\\/(\\*|[^\\/,;=\\s]+)(?:;\\s*q\\s*=\\s*(1|0\\.\\d+))?,?/'; if (preg_match_all($re, $accept, $matches, PREG_SET_ORDER)) { $this->acceptType = array(); foreach ($matches as $match) { $accept = new AcceptType($match[1], $match[2]); if (isset($match[3])) { $accept->setQValue((double) $match[3]); } $this->acceptType[] = $accept; } usort($this->acceptType, function ($a, $b) { $aq = $a->getQValue(); $bq = $b->getQValue(); // If q-values are equal, preserve their order if ($aq == $bq) { return 1; } // We are sorting by descending q-value if ($aq > $bq) { return -1; } else { return 1; } }); } }
public function supports(AcceptType $type) { return $type->matches('text/*'); }
public function supports(AcceptType $type) { return $type->matches('application/pdf'); }