Пример #1
0
 /**
  * Perform negotiation on the provided request, return a request instance with attributes containing the preferred
  * types for each field handled.
  *
  * @param ServerRequestInterface $request
  * @return ServerRequestInterface
  */
 public function negotiate(ServerRequestInterface $request)
 {
     if ($this->charsetNeg) {
         $request = $request->withAttribute(self::CHARSET_BEST, $this->negotiator->charsetBest($request->getHeaderLine('Accept'), $this->charsetAppTypes)->getType());
     }
     if ($this->encodingNeg) {
         $request = $request->withAttribute(self::ENCODING_BEST, $this->negotiator->encodingBest($request->getHeaderLine('Accept-Encoding'), $this->encodingAppTypes)->getType());
     }
     if ($this->languageNeg) {
         $request = $request->withAttribute(self::LANGUAGE_BEST, $this->negotiator->languageBest($request->getHeaderLine('Accept-Language'), $this->languageAppTypes)->getType());
     }
     if ($this->mimeNeg) {
         $request = $request->withAttribute(self::MIME_BEST, $this->negotiator->mimeBest($request->getHeaderLine('Accept'), $this->mimeAppTypes)->getType());
     }
     return $request;
 }
Пример #2
0
 /**
  * Return the best matching mime type.
  *
  * @param $appTypes
  *
  * @return TypePairInterface
  */
 public function mimeBest($appTypes)
 {
     $request = $this->requestStack->getCurrentRequest();
     $uaField = $request->server->get('HTTP_ACCEPT', '');
     return $this->negotiate->mimeBest($uaField, $appTypes);
 }