parse() public static method

Parse header.
public static parse ( string $header, string $name ) : Neomerx\JsonApi\Contracts\Http\Headers\HeaderInterface
$header string
$name string
return Neomerx\JsonApi\Contracts\Http\Headers\HeaderInterface
 /**
  * @inheritdoc
  */
 public function parse(ServerRequestInterface $request)
 {
     $acceptHeader = null;
     $contentTypeHeader = null;
     $method = $request->getMethod();
     try {
         $header = $this->getHeader($request, HeaderInterface::HEADER_CONTENT_TYPE);
         $contentTypeHeader = Header::parse($header, HeaderInterface::HEADER_CONTENT_TYPE);
     } catch (InvalidArgumentException $exception) {
         E::throwException(new E([], E::HTTP_CODE_BAD_REQUEST, $exception));
     }
     try {
         $header = $this->getHeader($request, HeaderInterface::HEADER_ACCEPT);
         $acceptHeader = AcceptHeader::parse($header);
     } catch (InvalidArgumentException $exception) {
         E::throwException(new E([], E::HTTP_CODE_BAD_REQUEST, $exception));
     }
     return $this->factory->createHeaderParameters($method, $acceptHeader, $contentTypeHeader);
 }
Esempio n. 2
0
 /**
  * @inheritdoc
  *
  * @return AcceptHeaderInterface
  */
 public static function parse($header, $accept = self::HEADER_ACCEPT)
 {
     return parent::parse($header, self::HEADER_ACCEPT);
 }
 /**
  * @depends testCodecMatcher
  */
 public function testDecoderC()
 {
     $codecMatcher = $this->repository->getCodecMatcher();
     $codecMatcher->matchDecoder(Header::parse(static::C, Header::HEADER_CONTENT_TYPE));
     $this->assertNull($codecMatcher->getDecoder());
     $this->assertNull($codecMatcher->getDecoderHeaderMatchedType());
     $this->assertNull($codecMatcher->getDecoderRegisteredMatchedType());
 }