/** * Returns a file extension fitting to the media type of this asset * * @return string */ public function getFileExtension() { return MediaTypes::getFilenameExtensionFromMediaType($this->resource->getMediaType()); }
/** * Initializes the controller * * This method should be called by the concrete processRequest() method. * * @param RequestInterface $request * @param ResponseInterface $response * @throws UnsupportedRequestTypeException */ protected function initializeController(RequestInterface $request, ResponseInterface $response) { if (!$request instanceof ActionRequest) { throw new UnsupportedRequestTypeException(get_class($this) . ' only supports action requests – requests of type "' . get_class($request) . '" given.', 1187701131); } $this->request = $request; $this->request->setDispatched(true); $this->response = $response; $this->uriBuilder = new UriBuilder(); $this->uriBuilder->setRequest($this->request); $this->arguments = new Arguments([]); $this->controllerContext = new ControllerContext($this->request, $this->response, $this->arguments, $this->uriBuilder); $mediaType = $request->getHttpRequest()->getNegotiatedMediaType($this->supportedMediaTypes); if ($mediaType === null) { $this->throwStatus(406); } if ($request->getFormat() === null) { $this->request->setFormat(MediaTypes::getFilenameExtensionFromMediaType($mediaType)); } }
/** * @test * @dataProvider mediaTypesAndFilenames */ public function getFilenameExtensionFromMediaTypeReturnsFirstFileExtensionFoundForThatMediaType($mediaType, $filenameExtensions) { $this->assertSame($filenameExtensions === [] ? '' : $filenameExtensions[0], MediaTypes::getFilenameExtensionFromMediaType($mediaType)); }