Esempio n. 1
0
 /**
  * @test
  * @dataProvider mediaRangesAndMatchingOrNonMatchingMediaTypes
  */
 public function mediaRangeMatchesChecksIfTheGivenMediaRangeMatchesTheGivenMediaType($mediaRange, $mediaType, $expectedResult)
 {
     $actualResult = MediaTypes::mediaRangeMatches($mediaRange, $mediaType);
     $this->assertSame($expectedResult, $actualResult);
 }
Esempio n. 2
0
 /**
  * Returns the best fitting IANA media type after applying the content negotiation
  * rules on a possible Accept header.
  *
  * @param array $supportedMediaTypes A list of media types which are supported by the application / controller
  * @param boolean $trim If TRUE, only the type/subtype of the media type is returned. If FALSE, the full original media type string is returned.
  * @return string The media type and sub type which matched, NULL if none matched
  * @api
  */
 public function getNegotiatedMediaType(array $supportedMediaTypes, $trim = true)
 {
     $negotiatedMediaType = null;
     $acceptedMediaTypes = $this->getAcceptedMediaTypes();
     foreach ($acceptedMediaTypes as $acceptedMediaType) {
         foreach ($supportedMediaTypes as $supportedMediaType) {
             if (MediaTypes::mediaRangeMatches($acceptedMediaType, $supportedMediaType)) {
                 $negotiatedMediaType = $supportedMediaType;
                 break 2;
             }
         }
     }
     return $trim ? MediaTypes::trimMediaType($negotiatedMediaType) : $negotiatedMediaType;
 }
 /**
  * Checks if the given media range and the media type match.
  * @see MediaTypes::mediaRangeMatches()
  *
  * @param string $mediaRange The media range, for example "text/*"
  * @param string $mediaType The media type to match against, for example "text/html"
  * @return boolean TRUE if both match, FALSE if they don't match or either of them is invalid
  * @deprecated since Flow 2.1. Use \Neos\Utility\MediaTypes::mediaRangeMatches() instead
  */
 public static function mediaRangeMatches($mediaRange, $mediaType)
 {
     return MediaTypes::mediaRangeMatches($mediaRange, $mediaType);
 }