コード例 #1
0
 public function getDeserializedRequestContent($rawContent, HeaderCollectionInterface $headerCollection)
 {
     if (!empty($rawContent)) {
         $contentType = $headerCollection->getHeaderValue(HeaderName::CONTENT_TYPE);
         if ($this->stringUtility->contains($contentType, ContentType::APPLICATION_JSON)) {
             $deserializedContent = $this->serializer->deserialize($rawContent, 'array', 'json');
         } else {
             throw new UnsupportedMediaTypeException('Submitted media type not supported');
         }
     } else {
         $deserializedContent = [];
     }
     return $deserializedContent;
 }
 public function parseAuthorizationHeaderString($authorizationHeader)
 {
     if (!$this->stringUtility->startsWith($authorizationHeader, self::BASIC_PREFIX)) {
         throw new InvalidAuthorizationHeaderException('Authorization-Header-Value does not start with \'' . self::BASIC_PREFIX . '\'.');
     }
     $baseEncodedCredentials = $this->stringUtility->substringAfter($authorizationHeader, self::BASIC_PREFIX);
     $decodedCredentials = $this->base64Service->decode($baseEncodedCredentials);
     if ($decodedCredentials === '') {
         list($userIdentifier, $password) = ['', ''];
     } else {
         if (!$this->stringUtility->contains($decodedCredentials, self::CREDENTIALS_DELIMITER)) {
             throw new InvalidAuthorizationHeaderException('Decoded credentials are not delimited by \'' . self::CREDENTIALS_DELIMITER . '\'.');
         } else {
             list($userIdentifier, $password) = $this->stringUtility->split($decodedCredentials, self::CREDENTIALS_DELIMITER);
         }
     }
     return new Credentials($userIdentifier, $password);
 }
 /**
  * @param string $string
  * @param string $needle
  * @param bool $wantedResult
  *
  * @dataProvider containsDataProvider
  */
 public function testContains($string, $needle, $wantedResult)
 {
     $result = $this->stringUtility->contains($string, $needle);
     $this->assertEquals($wantedResult, $result);
 }