Neos\Flow\ResourceManagement\PersistentResource::setFilename PHP Метод

setFilename() публичный Метод

Sets the filename which is used when this resource is downloaded or saved as a file
public setFilename ( string $filename ) : void
$filename string
Результат void
    public function setFilename($filename)
    {
        $this->throwExceptionIfProtected();
        $pathInfo = UnicodeFunctions::pathinfo($filename);
        $extension = isset($pathInfo['extension']) ? '.' . strtolower($pathInfo['extension']) : '';
        $this->filename = $pathInfo['filename'] . $extension;
        $this->mediaType = Utility\MediaTypes::getMediaTypeFromFilename($this->filename);
    }

Usage Example

 /**
  * @test
  */
 public function getMediaTypeReturnsMediaTypeBasedOnFileExtension()
 {
     $resource = new PersistentResource();
     $resource->setFilename('file.jpg');
     $this->assertSame('image/jpeg', $resource->getMediaType());
     $resource = new PersistentResource();
     $resource->setFilename('file.zip');
     $this->assertSame('application/zip', $resource->getMediaType());
     $resource = new PersistentResource();
     $resource->setFilename('file.someunknownextension');
     $this->assertSame('application/octet-stream', $resource->getMediaType());
 }