diff --git a/bundle/Controller/Callback/Cloudinary/Notify.php b/bundle/Controller/Callback/Cloudinary/Notify.php index 556ccb1c..5fd720f6 100644 --- a/bundle/Controller/Callback/Cloudinary/Notify.php +++ b/bundle/Controller/Callback/Cloudinary/Notify.php @@ -290,7 +290,7 @@ private function handleContextChanged(array $requestContent): void continue; } - $filenameFromUrl = basename($publicId); + $filenameFromUrl = basename((string) $publicId); try { $apiResource = Uploader::explicit( diff --git a/bundle/Controller/Resource/AbstractController.php b/bundle/Controller/Resource/AbstractController.php index 1d68b52f..3f4689ef 100644 --- a/bundle/Controller/Resource/AbstractController.php +++ b/bundle/Controller/Resource/AbstractController.php @@ -39,8 +39,8 @@ protected function formatResource(RemoteResource $resource): array 'size' => $resource->getSize(), 'width' => $resource->getMetadataProperty('width'), 'height' => $resource->getMetadataProperty('height'), - 'filename' => $resource->getName(), - 'originalFilename' => $resource->getOriginalFilename(), + 'filename' => (string) $resource->getName(), + 'originalFilename' => (string) $resource->getOriginalFilename(), 'format' => $resource->getMetadataProperty('format'), 'browseUrl' => $this->resolveImageUrl($resource, 'browse'), 'previewUrl' => $this->resolveImageUrl($resource, 'preview'), diff --git a/lib/API/Values/RemoteResource.php b/lib/API/Values/RemoteResource.php index 4e9593c7..89d0ee68 100644 --- a/lib/API/Values/RemoteResource.php +++ b/lib/API/Values/RemoteResource.php @@ -106,24 +106,24 @@ public function setUrl(string $url): self return $this; } - public function getName(): string + public function getName(): ?string { return $this->name; } - public function setName(string $name): self + public function setName(?string $name): self { $this->name = $name; return $this; } - public function getOriginalFilename(): string + public function getOriginalFilename(): ?string { return $this->originalFilename; } - public function setOriginalFilename(string $originalFilename): self + public function setOriginalFilename(?string $originalFilename): self { $this->originalFilename = $originalFilename; diff --git a/lib/Core/Provider/Cloudinary/CloudinaryProvider.php b/lib/Core/Provider/Cloudinary/CloudinaryProvider.php index 013c7576..ce2b2d8b 100644 --- a/lib/Core/Provider/Cloudinary/CloudinaryProvider.php +++ b/lib/Core/Provider/Cloudinary/CloudinaryProvider.php @@ -151,7 +151,7 @@ public function updateOnRemote(RemoteResource $resource): void [ 'alt' => $resource->getAltText(), 'caption' => $resource->getCaption(), - 'original_filename' => $resource->getOriginalFilename(), + 'original_filename' => (string) $resource->getOriginalFilename(), ], ), 'tags' => $resource->getTags(), diff --git a/lib/Core/Provider/Cloudinary/Factory/RemoteResource.php b/lib/Core/Provider/Cloudinary/Factory/RemoteResource.php index 04b551b1..1b56418b 100644 --- a/lib/Core/Provider/Cloudinary/Factory/RemoteResource.php +++ b/lib/Core/Provider/Cloudinary/Factory/RemoteResource.php @@ -133,7 +133,7 @@ private function resolveOriginalFilename(array $data): string return $data['context']['custom']['original_filename']; } - return $data['context']['original_filename'] ?? basename($data['secure_url']); + return $data['context']['original_filename'] ?? basename((string) $data['secure_url']); } /** diff --git a/tests/bundle/Controller/Resource/BrowseTest.php b/tests/bundle/Controller/Resource/BrowseTest.php index 5c3f99fe..99c939a7 100644 --- a/tests/bundle/Controller/Resource/BrowseTest.php +++ b/tests/bundle/Controller/Resource/BrowseTest.php @@ -176,6 +176,7 @@ public function test(): void 'width' => null, 'height' => null, 'filename' => 'image.jpg', + 'originalFilename' => '', 'format' => null, 'browseUrl' => 'https://cloudinary.com/test/c_fit_160_120/upload/images/image.jpg', 'previewUrl' => 'https://cloudinary.com/test/c_fit_800_600/upload/images/image.jpg', @@ -193,6 +194,7 @@ public function test(): void 'width' => null, 'height' => null, 'filename' => 'image2.jpg', + 'originalFilename' => '', 'format' => null, 'browseUrl' => 'https://cloudinary.com/test/c_fit_160_120/upload/images/image2.jpg', 'previewUrl' => 'https://cloudinary.com/test/c_fit_800_600/upload/images/image2.jpg', @@ -210,6 +212,7 @@ public function test(): void 'width' => null, 'height' => null, 'filename' => 'example.mp4', + 'originalFilename' => '', 'format' => null, 'browseUrl' => 'https://cloudinary.com/test/c_fit_160_120/upload/videos/example.mp4.jpg', 'previewUrl' => 'https://cloudinary.com/test/c_fit_800_600/upload/videos/example.mp4.jpg', diff --git a/tests/bundle/Controller/Resource/UploadTest.php b/tests/bundle/Controller/Resource/UploadTest.php index 6d7c386c..7de0eb7e 100644 --- a/tests/bundle/Controller/Resource/UploadTest.php +++ b/tests/bundle/Controller/Resource/UploadTest.php @@ -107,7 +107,7 @@ public function testUpload(): void type: 'image', url: 'https://cloudinary.com/test/upload/image/media/image/sample_image.jpg', md5: 'a522f23sf81aa0afd03387c37e2b6eax', - name: 'https://cloudinary.com/test/upload/image/media/image/sample_image.jpg', + name: 'sample_image.jpg', folder: Folder::fromPath('media/image'), size: 123, ); @@ -152,6 +152,7 @@ public function testUpload(): void 'width' => null, 'height' => null, 'filename' => 'sample_image.jpg', + 'originalFilename' => '', 'format' => null, 'browseUrl' => 'https://cloudinary.com/test/c_fit_160_120/upload/image/media/image/sample_image.jpg', 'previewUrl' => 'https://cloudinary.com/test/c_fit_800_600/upload/image/media/image/sample_image.jpg', @@ -304,6 +305,7 @@ public function testUploadProtectedWithContext(): void 'width' => null, 'height' => null, 'filename' => 'sample_image.jpg', + 'originalFilename' => '', 'format' => null, 'browseUrl' => 'https://cloudinary.com/test/c_fit_160_120/authenticated/image/media/image/sample_image.jpg', 'previewUrl' => 'https://cloudinary.com/test/c_fit_800_600/authenticated/image/media/image/sample_image.jpg', @@ -468,6 +470,7 @@ public function testUploadExistingFile(): void 'width' => null, 'height' => null, 'filename' => 'sample_image.jpg', + 'originalFilename' => '', 'format' => null, 'browseUrl' => 'https://cloudinary.com/test/c_fit_160_120/upload/image/sample_image.jpg', 'previewUrl' => 'https://cloudinary.com/test/c_fit_800_600/upload/image/sample_image.jpg', @@ -628,6 +631,7 @@ public function testUploadExistingFileName(): void 'width' => null, 'height' => null, 'filename' => 'sample_image.jpg', + 'originalFilename' => '', 'format' => null, 'browseUrl' => 'https://cloudinary.com/test/c_fit_160_120/upload/image/media/image/sample_image.jpg', 'previewUrl' => 'https://cloudinary.com/test/c_fit_800_600/upload/image/media/image/sample_image.jpg', diff --git a/tests/lib/Core/Provider/Cloudinary/CloudinaryProviderTest.php b/tests/lib/Core/Provider/Cloudinary/CloudinaryProviderTest.php index ea2103f1..ba9a24c8 100644 --- a/tests/lib/Core/Provider/Cloudinary/CloudinaryProviderTest.php +++ b/tests/lib/Core/Provider/Cloudinary/CloudinaryProviderTest.php @@ -367,6 +367,7 @@ public function testUpdateOnRemote(): void 'caption' => $resource->getCaption(), 'source' => 'user_upload', 'type' => 'product_image', + 'original_filename' => $resource->getOriginalFilename(), ], 'tags' => $resource->getTags(), ]; @@ -396,6 +397,7 @@ public function testUpdateOnRemoteWithEmptyTags(): void 'context' => [ 'alt' => $resource->getAltText(), 'caption' => $resource->getCaption(), + 'original_filename' => $resource->getOriginalFilename(), ], 'tags' => $resource->getTags(), ]; @@ -431,6 +433,7 @@ public function testUpdateOnRemoteNotFound(): void 'context' => [ 'alt' => $resource->getAltText(), 'caption' => $resource->getCaption(), + 'original_filename' => $resource->getOriginalFilename(), ], 'tags' => $resource->getTags(), ]; diff --git a/tests/lib/Core/Provider/Cloudinary/Factory/RemoteResourceTest.php b/tests/lib/Core/Provider/Cloudinary/Factory/RemoteResourceTest.php index bfc44ecf..a55db71d 100644 --- a/tests/lib/Core/Provider/Cloudinary/Factory/RemoteResourceTest.php +++ b/tests/lib/Core/Provider/Cloudinary/Factory/RemoteResourceTest.php @@ -113,6 +113,7 @@ public static function createDataProvider(): array url: 'https://res.cloudinary.com/myCloud/image/upload/c87hg9xfxrd4itiim3t0', md5: 'e522f43cf89aa0afd03387c37e2b6e12', name: 'c87hg9xfxrd4itiim3t0', + originalFilename: 'c87hg9xfxrd4itiim3t0.jpg', version: '1371995958', size: 120253, altText: 'alt text', @@ -151,6 +152,7 @@ public static function createDataProvider(): array url: 'https://res.cloudinary.com/myCloud/image/upload/other/c87hg9xfxrd4itiim3t0', md5: 'e522f43cf89aa0afd03387c37e2b6e29', name: 'c87hg9xfxrd4itiim3t0', + originalFilename: 'c87hg9xfxrd4itiim3t0', visibility: 'public', folder: Folder::fromPath('other'), size: 120253, @@ -176,6 +178,7 @@ public static function createDataProvider(): array 'created_at' => '2013-06-23T13:59:18Z', 'bytes' => 120253, 'url' => 'http://res.cloudinary.com/myCloud/video/upload/v1371995958/c87hg9xfxrd4itiim3t0.mp4', + 'secure_url' => 'http://res.cloudinary.com/myCloud/video/upload/v1371995958/c87hg9xfxrd4itiim3t0.mp4', 'tags' => ['tag1', 'tag2'], 'overwritten' => 'false', 'context' => [ @@ -194,6 +197,7 @@ public static function createDataProvider(): array url: 'https://res.cloudinary.com/myCloud/video/upload/c87hg9xfxrd4itiim3t0', md5: 'a522f23sf81aa0afd03387c37e2b6eax', name: 'c87hg9xfxrd4itiim3t0', + originalFilename: 'c87hg9xfxrd4itiim3t0.mp4', version: '13711295958', size: 120253, altText: 'alt text', @@ -237,6 +241,7 @@ public static function createDataProvider(): array url: 'https://res.cloudinary.com/myCloud/video/authenticated/c87hg9xfxrd4itiim3t0', md5: 'a522f23sf81aa0afd03387c37e2b6eax', name: 'c87hg9xfxrd4itiim3t0', + originalFilename: 'c87hg9xfxrd4itiim3t0.mp4', version: '1371995958', visibility: 'protected', size: 120253, @@ -278,6 +283,7 @@ public static function createDataProvider(): array url: 'https://res.cloudinary.com/myCloud/video/authenticated/c87hg9xfxrd4itiim3t0', md5: 'e522f43cf89aa0afd03387c37e2b6e29', name: 'c87hg9xfxrd4itiim3t0', + originalFilename: 'c87hg9xfxrd4itiim3t0.mp3', version: '1371995958', visibility: 'protected', size: 12025, @@ -318,6 +324,7 @@ public static function createDataProvider(): array url: 'https://res.cloudinary.com/myCloud/raw/test/media/raw/new/c87hg9xfxrd4itiim3t0', md5: 'e522f43cf89aa0afd03387c38e2b6e29', name: 'c87hg9xfxrd4itiim3t0', + originalFilename: 'c87hg9xfxrd4itiim3t0', version: '1371995958', visibility: 'public', folder: Folder::fromPath('media/raw/new'),