diff --git a/bundle/Command/ShowApiUsageCommand.php b/bundle/Command/ShowApiUsageCommand.php
index 0d7a5c32..1b4ab11e 100644
--- a/bundle/Command/ShowApiUsageCommand.php
+++ b/bundle/Command/ShowApiUsageCommand.php
@@ -39,7 +39,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$output->writeln($this->getPrettyKey($key) . ': ' . $value . '');
}
- return 0;
+ return Command::SUCCESS;
}
private function getPrettyKey(string $key): string
diff --git a/bundle/Controller/Callback/Cloudinary/Notify.php b/bundle/Controller/Callback/Cloudinary/Notify.php
index 0825ff59..ec75b015 100644
--- a/bundle/Controller/Callback/Cloudinary/Notify.php
+++ b/bundle/Controller/Callback/Cloudinary/Notify.php
@@ -4,8 +4,8 @@
namespace Netgen\Bundle\RemoteMediaBundle\Controller\Callback\Cloudinary;
-use Cloudinary\Api\NotFound;
-use Cloudinary\Uploader;
+use Cloudinary\Api\Exception\NotFound as CloudinaryNotFound;
+use Cloudinary\Api\Upload\UploadApi;
use Doctrine\ORM\EntityManagerInterface;
use Netgen\RemoteMedia\API\ProviderInterface;
use Netgen\RemoteMedia\API\Values\RemoteResource;
@@ -197,14 +197,14 @@ private function handleResourceRenamed(array $requestContent): void
/** @var RemoteResource $resource */
foreach ($result as $resource) {
try {
- $apiResource = Uploader::explicit(
+ $apiResource = (new UploadApi())->explicit(
$requestContent['to_public_id'],
[
'type' => CloudinaryRemoteId::fromRemoteId($resource->getRemoteId())->getType(),
'resource_type' => CloudinaryRemoteId::fromRemoteId($resource->getRemoteId())->getResourceType(),
],
);
- } catch (NotFound $e) {
+ } catch (CloudinaryNotFound $e) {
continue;
}
@@ -293,7 +293,7 @@ private function handleContextChanged(array $requestContent): void
$filenameFromUrl = basename((string) $publicId);
try {
- $apiResource = Uploader::explicit(
+ $apiResource = (new UploadApi())->explicit(
CloudinaryRemoteId::fromRemoteId($resource->getRemoteId())->getResourceId(),
[
'type' => CloudinaryRemoteId::fromRemoteId($resource->getRemoteId())->getType(),
@@ -302,7 +302,7 @@ private function handleContextChanged(array $requestContent): void
);
basename($apiResource['secure_url']);
- } catch (NotFound $e) {
+ } catch (CloudinaryNotFound $e) {
continue;
}
diff --git a/bundle/Resources/config/services/core.yaml b/bundle/Resources/config/services/core.yaml
index 0e4b1ba3..c111bd6c 100644
--- a/bundle/Resources/config/services/core.yaml
+++ b/bundle/Resources/config/services/core.yaml
@@ -15,7 +15,7 @@ services:
class: Netgen\RemoteMedia\Core\Provider\Cloudinary\Gateway\CloudinaryApiGateway
public: false
arguments:
- - '@netgen_remote_media.provider.cloudinary.cloudinary_instance'
+ - '@netgen_remote_media.provider.cloudinary.cloudinary_configuration'
- '@netgen_remote_media.provider.cloudinary.factory.remote_resource'
- '@netgen_remote_media.provider.cloudinary.factory.search_result'
- '@netgen_remote_media.provider.cloudinary.resolver.search_expression'
@@ -58,8 +58,8 @@ services:
class: Netgen\RemoteMedia\Core\Provider\Cloudinary\Converter\VisibilityType
public: false
- netgen_remote_media.provider.cloudinary.factory.cloudinary_instance:
- class: Netgen\RemoteMedia\Core\Provider\Cloudinary\Factory\CloudinaryInstance
+ netgen_remote_media.provider.cloudinary.factory.cloudinary_configuration:
+ class: Netgen\RemoteMedia\Core\Provider\Cloudinary\Factory\CloudinaryConfiguration
public: false
arguments:
- '%netgen_remote_media.parameters.cloudinary.account_name%'
@@ -68,9 +68,9 @@ services:
- "%netgen_remote_media.parameters.cloudinary.upload_prefix%"
- "%netgen_remote_media.parameters.use_subdomains%"
- netgen_remote_media.provider.cloudinary.cloudinary_instance:
- class: Cloudinary
- factory: ['@netgen_remote_media.provider.cloudinary.factory.cloudinary_instance', 'create']
+ netgen_remote_media.provider.cloudinary.cloudinary_configuration:
+ class: Configuration
+ factory: ['@netgen_remote_media.provider.cloudinary.factory.cloudinary_configuration', 'create']
netgen_remote_media.provider.cloudinary.factory.remote_resource:
class: Netgen\RemoteMedia\Core\Provider\Cloudinary\Factory\RemoteResource
diff --git a/composer.json b/composer.json
index 4f8fc547..4a0e19b1 100644
--- a/composer.json
+++ b/composer.json
@@ -27,7 +27,7 @@
],
"require": {
"php": "^8.1",
- "cloudinary/cloudinary_php": "^1.20",
+ "cloudinary/cloudinary_php": "^2.1",
"symfony/mime": "^5.4 || ^6.2",
"symfony/twig-bundle": "^5.4 || ^6.2",
"symfony/framework-bundle": "^5.4 || ^6.2",
diff --git a/docs/UPGRADE.md b/docs/UPGRADE.md
index 2f22fc8c..0512ffbd 100644
--- a/docs/UPGRADE.md
+++ b/docs/UPGRADE.md
@@ -4,13 +4,14 @@ Netgen Remote Media Bundle upgrade instructions
Upgrade from 2.0 to 3.0
-----------------------
-Version 3.0 is a major release where the whole bundle has been decoupled from eZ and now contains only core features and doesn't depend on eZ anymore. In order to retain all the eZ functionalities (field type, NG admin UI and eZ admin UI), you have to install the new bundle which serves as a connector between Remote Media and eZ (currently WIP).
+Version 3.0 is a major release where the whole bundle has been decoupled from eZ and now contains only core features and doesn't depend on eZ anymore. In order to retain all the eZ functionalities (field type, NG admin UI and eZ admin UI), you have to install the [Netgen Remote Media & Ibexa CMS integration](https://github.com/netgen/remote-media-ibexa) bundle which serves as a connector between Remote Media and eZ.
Also, there were a lot of changes during the decoupling from eZ to make things cleaner so there is a lot of breaking changes.
* This bundle doesn't depend on eZ anymore and does not contain any eZ related integration
* This bundle doesn't depend on Netgen Open Graph bundle anymore and does not contain any related integration
-* Minimum supported version of PHP is now PHP 7.4
+* Minimum supported version of PHP is now PHP 8.1
+* This bundle now uses Cloudinary PHP SDK v2 instead of v1
* Most of the classes in the codebase are now `final` - if you have any overrides in your project, refactor them to use the Decorator pattern instead
* The main value object `Netgen\Bundle\RemoteMediaBundle\Core\FieldType\RemoteMedia\Value` which was extending eZ field type value has now been renamed to `Netgen\RemoteMedia\API\Values\RemoteResource` and all methods use or return this new one; methods and properties remained the same; now it's a standalone value object
* The variation object `Netgen\Bundle\RemoteMediaBundle\Core\FieldType\RemoteMedia\Variation` has been renamed to `Netgen\RemoteMedia\API\Values\Variation` and all methods use or return this new one; methods and properties remained the same
@@ -34,7 +35,7 @@ Also, there were a lot of changes during the decoupling from eZ to make things c
* `public static function createFromParameters(array $parameters): self`
* `public static function createFromCloudinaryResponse(array $response): self`
* The bundle was using eZ's `ezpublish.cache_pool` cache pool for caching while it was depending on eZ. Now it requires cache pool to be provided in order to work. See [Install instructions](INSTALL.md) for more info.
-* Paramter for cache TTL `netgen_remote_media.cloudinary.cache_ttl` has been removed in favour of semantic configuration for cache. See [Install instructions](INSTALL.md) for more info.
+* Parameter for cache TTL `netgen_remote_media.cloudinary.cache_ttl` has been removed in favour of semantic configuration for cache. See [Install instructions](INSTALL.md) for more info.
### Code changes
@@ -46,7 +47,7 @@ Old object `Netgen\Bundle\RemoteMediaBundle\Core\FieldType\RemoteMedia` has been
* all properties are now private and there are corresponding getters as well as some helper methods to manipulate with the object
* static constructors have been removed from the value object -> they've been replaced with factory
* now it contains `id` which represents the ID of the stored resource in the database (via Doctrine) -> can be `null` if the resource has been fetched from remote
-* now it contains `remoteId` which is used to uniquely identify the resource on the cloud -> in case when cloud providers require multiple parameters to uniquely identify the resource (eg. Cloudinary requires `resourceId`, `resourceType` and `type`), each provider is responsible to merge this info into single array which will be used as `remoteId`
+* now it contains `remoteId` which is used to uniquely identify the resource on the cloud -> in case when cloud providers require multiple parameters to uniquely identify the resource (eg. Cloudinary requires `resourceId`, `resourceType` and `type`), each provider is responsible to merge this info into single string which will be used as `remoteId`
* `mediaType` property has been removed; now we have a single `type` and it's up to the provider to convert this to the appropriate type for cloud provider
* now it contains two new types: `audio` and `document`
* now it contains only single `url` property instead of both URL and secure URL - it's up to provider to decide whether it will provide secure or not secure URLs
diff --git a/lib/Core/Provider/Cloudinary/CloudinaryProvider.php b/lib/Core/Provider/Cloudinary/CloudinaryProvider.php
index 4fd3d625..544f8d82 100644
--- a/lib/Core/Provider/Cloudinary/CloudinaryProvider.php
+++ b/lib/Core/Provider/Cloudinary/CloudinaryProvider.php
@@ -4,6 +4,7 @@
namespace Netgen\RemoteMedia\Core\Provider\Cloudinary;
+use Cloudinary\Configuration\TagConfig;
use Doctrine\ORM\EntityManagerInterface;
use Netgen\RemoteMedia\API\Factory\DateTime as DateTimeFactoryInterface;
use Netgen\RemoteMedia\API\Search\Query;
@@ -28,7 +29,6 @@
use function array_merge;
use function basename;
use function count;
-use function default_poster_options;
use function preg_match;
use function sprintf;
use function str_replace;
@@ -280,7 +280,12 @@ protected function internalBuildVideoThumbnail(RemoteResource $resource, array $
$resource instanceof AuthenticatedRemoteResource ? $resource->getToken() : null,
);
- return new RemoteResourceVariation($resource, $thumbnailUrl, array_merge(default_poster_options(), $options));
+ $defaultPosterOptions = [
+ 'format' => TagConfig::VIDEO_POSTER_FORMAT,
+ 'resource_type' => 'video',
+ ];
+
+ return new RemoteResourceVariation($resource, $thumbnailUrl, array_merge($defaultPosterOptions, $options));
}
protected function generatePictureTag(RemoteResource $resource, array $transformations = [], array $htmlAttributes = []): string
diff --git a/lib/Core/Provider/Cloudinary/Converter/VisibilityType.php b/lib/Core/Provider/Cloudinary/Converter/VisibilityType.php
index 6f08a573..0d0ec056 100644
--- a/lib/Core/Provider/Cloudinary/Converter/VisibilityType.php
+++ b/lib/Core/Provider/Cloudinary/Converter/VisibilityType.php
@@ -50,13 +50,13 @@ public function toCloudinaryAccessControl(string $visibility): array
switch ($visibility) {
case RemoteResource::VISIBILITY_PROTECTED:
return [
- 'access_type' => 'token',
+ ['access_type' => 'token'],
];
case RemoteResource::VISIBILITY_PUBLIC:
default:
return [
- 'access_type' => 'anonymous',
+ ['access_type' => 'anonymous'],
];
}
}
diff --git a/lib/Core/Provider/Cloudinary/Factory/CloudinaryConfiguration.php b/lib/Core/Provider/Cloudinary/Factory/CloudinaryConfiguration.php
new file mode 100644
index 00000000..3dba5808
--- /dev/null
+++ b/lib/Core/Provider/Cloudinary/Factory/CloudinaryConfiguration.php
@@ -0,0 +1,30 @@
+ $this->cloudName,
+ 'api_key' => $this->apiKey,
+ 'api_secret' => $this->apiSecret,
+ 'upload_prefix' => $this->uploadPrefix,
+ 'cdn_subdomain' => $this->useSubdomains,
+ 'force_version' => false,
+ ]);
+ }
+}
diff --git a/lib/Core/Provider/Cloudinary/Factory/CloudinaryInstance.php b/lib/Core/Provider/Cloudinary/Factory/CloudinaryInstance.php
deleted file mode 100644
index e44c41b2..00000000
--- a/lib/Core/Provider/Cloudinary/Factory/CloudinaryInstance.php
+++ /dev/null
@@ -1,39 +0,0 @@
-cloudinary instanceof Cloudinary) {
- $this->cloudinary = new Cloudinary();
- $this->cloudinary->config(
- [
- 'cloud_name' => $this->cloudName,
- 'api_key' => $this->apiKey,
- 'api_secret' => $this->apiSecret,
- 'upload_prefix' => $this->uploadPrefix,
- 'cdn_subdomain' => $this->useSubdomains,
- 'force_version' => false,
- ],
- );
- }
-
- return $this->cloudinary;
- }
-}
diff --git a/lib/Core/Provider/Cloudinary/Factory/RemoteResource.php b/lib/Core/Provider/Cloudinary/Factory/RemoteResource.php
index 8e9da9e5..6472acf4 100644
--- a/lib/Core/Provider/Cloudinary/Factory/RemoteResource.php
+++ b/lib/Core/Provider/Cloudinary/Factory/RemoteResource.php
@@ -4,6 +4,7 @@
namespace Netgen\RemoteMedia\Core\Provider\Cloudinary\Factory;
+use Cloudinary\Asset\Media;
use Netgen\RemoteMedia\API\Factory\FileHash as FileHashFactoryInterface;
use Netgen\RemoteMedia\API\Factory\RemoteResource as RemoteResourceFactoryInterface;
use Netgen\RemoteMedia\API\Values\RemoteResource as RemoteResourceValue;
@@ -13,7 +14,6 @@
use Netgen\RemoteMedia\Exception\Factory\InvalidDataException;
use function basename;
-use function cloudinary_url_internal;
use function in_array;
use function is_array;
use function pathinfo;
@@ -79,7 +79,7 @@ private function resolveCorrectUrl(array $data): string
'secure' => true,
];
- return cloudinary_url_internal($data['public_id'], $options);
+ return (string) Media::fromParams($data['public_id'], $options)->toUrl();
}
private function resolveResourceType(array $data): string
diff --git a/lib/Core/Provider/Cloudinary/Gateway/CloudinaryApiGateway.php b/lib/Core/Provider/Cloudinary/Gateway/CloudinaryApiGateway.php
index 18ca950f..c22c78c0 100644
--- a/lib/Core/Provider/Cloudinary/Gateway/CloudinaryApiGateway.php
+++ b/lib/Core/Provider/Cloudinary/Gateway/CloudinaryApiGateway.php
@@ -4,10 +4,15 @@
namespace Netgen\RemoteMedia\Core\Provider\Cloudinary\Gateway;
-use Cloudinary;
-use Cloudinary\Api as CloudinaryApi;
-use Cloudinary\Search as CloudinarySearch;
-use Cloudinary\Uploader as CloudinaryUploader;
+use Cloudinary\Api\Admin\AdminApi;
+use Cloudinary\Api\Exception\NotFound as CloudinaryNotFound;
+use Cloudinary\Api\Search\SearchApi;
+use Cloudinary\Api\Upload\UploadApi;
+use Cloudinary\Asset\Image;
+use Cloudinary\Asset\Media;
+use Cloudinary\Configuration\Configuration;
+use Cloudinary\Tag\ImageTag;
+use Cloudinary\Tag\VideoTag;
use Netgen\RemoteMedia\API\Factory\RemoteResource as RemoteResourceFactoryInterface;
use Netgen\RemoteMedia\API\Factory\SearchResult as SearchResultFactoryInterface;
use Netgen\RemoteMedia\API\Search\Query;
@@ -26,10 +31,6 @@
use function array_map;
use function array_merge;
-use function cl_image_tag;
-use function cl_video_tag;
-use function cl_video_thumbnail_path;
-use function cloudinary_url_internal;
use function count;
use function date;
use function floor;
@@ -41,45 +42,43 @@
final class CloudinaryApiGateway implements GatewayInterface
{
- private CloudinaryApi $cloudinaryApi;
+ private AdminApi $adminApi;
- private CloudinaryUploader $cloudinaryUploader;
+ private UploadApi $uploadApi;
- private CloudinarySearch $cloudinarySearch;
+ private SearchApi $searchApi;
public function __construct(
- private Cloudinary $cloudinary,
+ private Configuration $configuration,
private RemoteResourceFactoryInterface $remoteResourceFactory,
private SearchResultFactoryInterface $searchResultFactory,
private SearchExpressionResolver $searchExpressionResolver,
private AuthTokenResolver $authTokenResolver
) {
- $this->cloudinaryUploader = new CloudinaryUploader();
- $this->cloudinaryApi = new CloudinaryApi();
- $this->cloudinarySearch = new CloudinarySearch();
+ $this->adminApi = new AdminApi();
+ $this->uploadApi = new UploadApi();
+ $this->searchApi = new SearchApi();
}
public function setServices(
- Cloudinary $cloudinary,
- CloudinaryUploader $cloudinaryUploader,
- CloudinaryApi $cloudinaryApi,
- CloudinarySearch $cloudinarySearch
+ AdminApi $adminApi,
+ UploadApi $uploadApi,
+ SearchApi $searchApi,
): void {
- $this->cloudinary = $cloudinary;
- $this->cloudinaryUploader = $cloudinaryUploader;
- $this->cloudinaryApi = $cloudinaryApi;
- $this->cloudinarySearch = $cloudinarySearch;
+ $this->adminApi = $adminApi;
+ $this->uploadApi = $uploadApi;
+ $this->searchApi = $searchApi;
}
public function usage(): StatusData
{
- $usage = $this->cloudinaryApi->usage();
+ $usage = $this->adminApi->usage();
return new StatusData([
'plan' => $usage['plan'],
- 'rate_limit_allowed' => $usage->rate_limit_allowed,
- 'rate_limit_remaining' => $usage->rate_limit_remaining,
- 'rate_limit_reset_at' => date('d.m.Y H:i:s', $usage->rate_limit_reset_at),
+ 'rate_limit_allowed' => $usage->rateLimitAllowed,
+ 'rate_limit_remaining' => $usage->rateLimitRemaining,
+ 'rate_limit_reset_at' => date('d.m.Y H:i:s', $usage->rateLimitResetAt),
'objects' => $usage['objects']['usage'],
'resources' => $usage['resources'],
'derived_resources' => $usage['derived_resources'],
@@ -102,7 +101,7 @@ public function isEncryptionEnabled(): bool
public function countResources(): int
{
- $usage = $this->cloudinaryApi->usage();
+ $usage = $this->adminApi->usage();
return (int) $usage['resources'];
}
@@ -111,9 +110,9 @@ public function countResourcesInFolder(string $folder): int
{
$expression = sprintf('folder:%s/*', $folder);
- $search = $this->cloudinarySearch
+ $search = $this->searchApi
->expression($expression)
- ->max_results(0);
+ ->maxResults(0);
$response = $search->execute();
@@ -124,8 +123,8 @@ public function listFolders(): array
{
return array_map(
static fn ($value) => $value['path'],
- $this->cloudinaryApi
- ->root_folders()
+ $this->adminApi
+ ->rootFolders()
->getArrayCopy()['folders'],
);
}
@@ -135,24 +134,24 @@ public function listSubFolders(string $parentFolder): array
try {
return array_map(
static fn ($value) => $value['path'],
- $this->cloudinaryApi
- ->subfolders($parentFolder)
+ $this->adminApi
+ ->subFolders($parentFolder)
->getArrayCopy()['folders'],
);
- } catch (CloudinaryApi\NotFound $e) {
+ } catch (CloudinaryNotFound $e) {
throw new FolderNotFoundException(Folder::fromPath($parentFolder));
}
}
public function createFolder(string $path): void
{
- $this->cloudinaryApi->create_folder($path);
+ $this->adminApi->createFolder($path);
}
public function get(CloudinaryRemoteId $remoteId): RemoteResource
{
try {
- $response = $this->cloudinaryApi->resource(
+ $response = $this->adminApi->asset(
$remoteId->getResourceId(),
[
'type' => $remoteId->getType(),
@@ -164,17 +163,17 @@ public function get(CloudinaryRemoteId $remoteId): RemoteResource
);
return $this->remoteResourceFactory->create((array) $response);
- } catch (CloudinaryApi\NotFound $e) {
+ } catch (CloudinaryNotFound $e) {
throw new RemoteResourceNotFoundException($remoteId->getRemoteId());
}
}
public function upload(string $fileUri, array $options): RemoteResource
{
- $response = $this->cloudinaryUploader->upload($fileUri, $options);
+ $response = $this->uploadApi->upload($fileUri, $options);
$resource = $this->remoteResourceFactory->create((array) $response);
- if ($response['existing'] ?? false) {
+ if (($response['existing'] ?? false) !== false) {
throw new RemoteResourceExistsException($resource);
}
@@ -187,8 +186,8 @@ public function update(CloudinaryRemoteId $remoteId, array $options): void
$options['resource_type'] = $remoteId->getResourceType();
try {
- $this->cloudinaryUploader->explicit($remoteId->getResourceId(), $options);
- } catch (CloudinaryApi\NotFound $e) {
+ $this->uploadApi->explicit($remoteId->getResourceId(), $options);
+ } catch (CloudinaryNotFound $e) {
throw new RemoteResourceNotFoundException($remoteId->getRemoteId());
}
}
@@ -201,8 +200,8 @@ public function removeAllTagsFromResource(CloudinaryRemoteId $remoteId): void
];
try {
- $this->cloudinaryUploader->remove_all_tags([$remoteId->getResourceId()], $options);
- } catch (CloudinaryApi\NotFound $e) {
+ $this->uploadApi->removeAllTags([$remoteId->getResourceId()], $options);
+ } catch (CloudinaryNotFound $e) {
throw new RemoteResourceNotFoundException($remoteId->getRemoteId());
}
}
@@ -215,7 +214,7 @@ public function delete(CloudinaryRemoteId $remoteId): void
'resource_type' => $remoteId->getResourceType(),
];
- $this->cloudinaryUploader->destroy($remoteId->getResourceId(), $options);
+ $this->uploadApi->destroy($remoteId->getResourceId(), $options);
}
public function getAuthenticatedUrl(CloudinaryRemoteId $remoteId, AuthToken $token): string
@@ -229,7 +228,7 @@ public function getAuthenticatedUrl(CloudinaryRemoteId $remoteId, AuthToken $tok
$this->authTokenResolver->resolve($token),
);
- return cloudinary_url_internal($remoteId->getResourceId(), $options);
+ return (string) Media::fromParams($remoteId->getResourceId(), $options)->toUrl();
}
public function getVariationUrl(CloudinaryRemoteId $remoteId, array $transformations, ?AuthToken $token = null): string
@@ -248,19 +247,19 @@ public function getVariationUrl(CloudinaryRemoteId $remoteId, array $transformat
);
}
- return cloudinary_url_internal($remoteId->getResourceId(), $options);
+ return (string) Media::fromParams($remoteId->getResourceId(), $options)->toUrl();
}
public function search(Query $query): Result
{
- $search = $this->cloudinarySearch
+ $search = $this->searchApi
->expression($this->searchExpressionResolver->resolve($query))
- ->max_results($query->getLimit())
- ->with_field('context')
- ->with_field('tags');
+ ->maxResults($query->getLimit())
+ ->withField('context')
+ ->withField('tags');
if ($query->getNextCursor() !== null) {
- $search->next_cursor($query->getNextCursor());
+ $search->nextCursor($query->getNextCursor());
}
$response = $search->execute();
@@ -270,9 +269,9 @@ public function search(Query $query): Result
public function searchCount(Query $query): int
{
- $search = $this->cloudinarySearch
+ $search = $this->searchApi
->expression($this->searchExpressionResolver->resolve($query))
- ->max_results(0);
+ ->maxResults(0);
$response = $search->execute();
@@ -287,7 +286,7 @@ public function listTags(): array
$tags = [];
do {
- $result = $this->cloudinaryApi->tags($options);
+ $result = $this->adminApi->tags($options);
$tags = array_merge($tags, $result['tags']);
$nextCursor = $result['next_cursor'] ?? null;
@@ -312,7 +311,7 @@ public function getVideoThumbnail(CloudinaryRemoteId $remoteId, array $options =
);
}
- return cl_video_thumbnail_path($remoteId->getResourceId(), $options);
+ return (string) Image::fromParams($remoteId->getResourceId(), $options)->toUrl();
}
public function getImageTag(CloudinaryRemoteId $remoteId, array $options = [], ?AuthToken $token = null): string
@@ -328,7 +327,7 @@ public function getImageTag(CloudinaryRemoteId $remoteId, array $options = [], ?
);
}
- return cl_image_tag($remoteId->getResourceId(), $options);
+ return ImageTag::fromParams($remoteId->getResourceId(), $options)->toTag();
}
public function getVideoTag(CloudinaryRemoteId $remoteId, array $options = [], ?AuthToken $token = null): string
@@ -344,7 +343,7 @@ public function getVideoTag(CloudinaryRemoteId $remoteId, array $options = [], ?
);
}
- return cl_video_tag($remoteId->getResourceId(), $options);
+ return VideoTag::fromParams($remoteId->getResourceId(), $options)->toTag();
}
public function getDownloadLink(CloudinaryRemoteId $remoteId, array $options = [], ?AuthToken $token = null): string
@@ -360,7 +359,7 @@ public function getDownloadLink(CloudinaryRemoteId $remoteId, array $options = [
);
}
- return $this->cloudinary->cloudinary_url($remoteId->getResourceId(), $options);
+ return (string) Media::fromParams($remoteId->getResourceId(), $options)->toUrl();
}
private function formatBytes(int $bytes, int $precision = 2): string
diff --git a/lib/Core/Provider/Cloudinary/Gateway/Log/MonologLoggedGateway.php b/lib/Core/Provider/Cloudinary/Gateway/Log/MonologLoggedGateway.php
index 4caa85f1..63cdd818 100644
--- a/lib/Core/Provider/Cloudinary/Gateway/Log/MonologLoggedGateway.php
+++ b/lib/Core/Provider/Cloudinary/Gateway/Log/MonologLoggedGateway.php
@@ -109,14 +109,14 @@ public function delete(CloudinaryRemoteId $remoteId): void
public function getAuthenticatedUrl(CloudinaryRemoteId $remoteId, AuthToken $token): string
{
- $this->logger->info("[INTERNAL][FREE] getAuthenticatedUrl(\"{$remoteId->getRemoteId()}\") -> cloudinary_url_internal(\"{$remoteId->getRemoteId()}\")");
+ $this->logger->info("[INTERNAL][FREE] getAuthenticatedUrl(\"{$remoteId->getRemoteId()}\") -> Media::fromParams(\"{$remoteId->getRemoteId()}\")");
return $this->gateway->getAuthenticatedUrl($remoteId, $token);
}
public function getVariationUrl(CloudinaryRemoteId $remoteId, array $transformations, ?AuthToken $token = null): string
{
- $this->logger->info("[INTERNAL][FREE] getVariationUrl(\"{$remoteId->getRemoteId()}\") -> cloudinary_url_internal(\"{$remoteId->getRemoteId()}\")");
+ $this->logger->info("[INTERNAL][FREE] getVariationUrl(\"{$remoteId->getRemoteId()}\") -> Media::fromParams(\"{$remoteId->getRemoteId()}\")");
return $this->gateway->getVariationUrl($remoteId, $transformations, $token);
}
@@ -144,28 +144,28 @@ public function listTags(): array
public function getVideoThumbnail(CloudinaryRemoteId $remoteId, array $options = [], ?AuthToken $token = null): string
{
- $this->logger->info("[INTERNAL][FREE] getVideoThumbnail(\"{$remoteId->getRemoteId()}\") -> cl_video_thumbnail_path(\"{$remoteId->getRemoteId()}\")");
+ $this->logger->info("[INTERNAL][FREE] getVideoThumbnail(\"{$remoteId->getRemoteId()}\") -> Image::fromParams(\"{$remoteId->getRemoteId()}\")");
return $this->gateway->getVideoThumbnail($remoteId, $options, $token);
}
public function getImageTag(CloudinaryRemoteId $remoteId, array $options = [], ?AuthToken $token = null): string
{
- $this->logger->info("[INTERNAL][FREE] getImageTag(\"{$remoteId->getRemoteId()}\") -> cl_image_tag(\"{$remoteId->getRemoteId()}\")");
+ $this->logger->info("[INTERNAL][FREE] getImageTag(\"{$remoteId->getRemoteId()}\") -> ImageTag::fromParams(\"{$remoteId->getRemoteId()}\")");
return $this->gateway->getImageTag($remoteId, $options, $token);
}
public function getVideoTag(CloudinaryRemoteId $remoteId, array $options = [], ?AuthToken $token = null): string
{
- $this->logger->info("[INTERNAL][FREE] getVideoTag(\"{$remoteId->getRemoteId()}\") -> cl_video_tag(\"{$remoteId->getRemoteId()}\")");
+ $this->logger->info("[INTERNAL][FREE] getVideoTag(\"{$remoteId->getRemoteId()}\") -> VideoTag::fromParams(\"{$remoteId->getRemoteId()}\")");
return $this->gateway->getVideoTag($remoteId, $options, $token);
}
public function getDownloadLink(CloudinaryRemoteId $remoteId, array $options = [], ?AuthToken $token = null): string
{
- $this->logger->info("[INTERNAL][FREE] getDownloadLink(\"{$remoteId->getRemoteId()}\") -> Cloudinary::cloudinary_url(\"{$remoteId->getRemoteId()}\")");
+ $this->logger->info("[INTERNAL][FREE] getDownloadLink(\"{$remoteId->getRemoteId()}\") -> Media::fromParams(\"{$remoteId->getRemoteId()}\")");
return $this->gateway->getDownloadLink($remoteId, $options, $token);
}
diff --git a/lib/Core/Provider/Cloudinary/Verifier/Request/Signature.php b/lib/Core/Provider/Cloudinary/Verifier/Request/Signature.php
index dfac4b0b..5365c6fa 100644
--- a/lib/Core/Provider/Cloudinary/Verifier/Request/Signature.php
+++ b/lib/Core/Provider/Cloudinary/Verifier/Request/Signature.php
@@ -4,7 +4,7 @@
namespace Netgen\RemoteMedia\Core\Provider\Cloudinary\Verifier\Request;
-use Cloudinary\SignatureVerifier;
+use Cloudinary\Utils\SignatureVerifier;
use InvalidArgumentException;
use Netgen\RemoteMedia\Core\RequestVerifierInterface;
use Symfony\Component\HttpFoundation\Request;
diff --git a/tests/lib/Core/Provider/Cloudinary/CloudinaryConfigurationInitializer.php b/tests/lib/Core/Provider/Cloudinary/CloudinaryConfigurationInitializer.php
new file mode 100644
index 00000000..f4826d65
--- /dev/null
+++ b/tests/lib/Core/Provider/Cloudinary/CloudinaryConfigurationInitializer.php
@@ -0,0 +1,32 @@
+ self::CLOUD_NAME,
+ 'api_key' => self::API_KEY,
+ 'api_secret' => self::API_SECRET,
+ 'upload_prefix' => self::UPLOAD_PREFIX,
+ 'cdn_subdomain' => false,
+ 'force_version' => false,
+ ]);
+ }
+}
diff --git a/tests/lib/Core/Provider/Cloudinary/CloudinaryProviderTest.php b/tests/lib/Core/Provider/Cloudinary/CloudinaryProviderTest.php
index c8865f67..404854cf 100644
--- a/tests/lib/Core/Provider/Cloudinary/CloudinaryProviderTest.php
+++ b/tests/lib/Core/Provider/Cloudinary/CloudinaryProviderTest.php
@@ -764,7 +764,7 @@ public function testInternalUpload(): void
'type' => 'upload',
'resource_type' => 'image',
'access_mode' => 'public',
- 'access_control' => ['access_type' => 'anonymous'],
+ 'access_control' => [['access_type' => 'anonymous']],
'tags' => [],
];
diff --git a/tests/lib/Core/Provider/Cloudinary/Converter/VisibilityTypeTest.php b/tests/lib/Core/Provider/Cloudinary/Converter/VisibilityTypeTest.php
index 374447ed..8226ce0a 100644
--- a/tests/lib/Core/Provider/Cloudinary/Converter/VisibilityTypeTest.php
+++ b/tests/lib/Core/Provider/Cloudinary/Converter/VisibilityTypeTest.php
@@ -83,8 +83,8 @@ public static function toCloudinaryAccessModeProvider(): array
public static function toCloudinaryAccessControlProvider(): array
{
return [
- [RemoteResource::VISIBILITY_PUBLIC, ['access_type' => 'anonymous']],
- [RemoteResource::VISIBILITY_PROTECTED, ['access_type' => 'token']],
+ [RemoteResource::VISIBILITY_PUBLIC, [['access_type' => 'anonymous']]],
+ [RemoteResource::VISIBILITY_PROTECTED, [['access_type' => 'token']]],
];
}
}
diff --git a/tests/lib/Core/Provider/Cloudinary/Factory/CloudinaryConfigurationTest.php b/tests/lib/Core/Provider/Cloudinary/Factory/CloudinaryConfigurationTest.php
new file mode 100644
index 00000000..22a48840
--- /dev/null
+++ b/tests/lib/Core/Provider/Cloudinary/Factory/CloudinaryConfigurationTest.php
@@ -0,0 +1,35 @@
+cloudinaryConfigurationFactory = new CloudinaryConfigurationFactory(
+ CloudinaryConfigurationInitializer::CLOUD_NAME,
+ CloudinaryConfigurationInitializer::API_KEY,
+ CloudinaryConfigurationInitializer::API_SECRET,
+ CloudinaryConfigurationInitializer::UPLOAD_PREFIX,
+ false,
+ );
+ }
+
+ public function testCreate(): void
+ {
+ self::assertSame(
+ CloudinaryConfigurationInitializer::getConfiguration(),
+ $this->cloudinaryConfigurationFactory->create(),
+ );
+ }
+}
diff --git a/tests/lib/Core/Provider/Cloudinary/Factory/CloudinaryInstanceTest.php b/tests/lib/Core/Provider/Cloudinary/Factory/CloudinaryInstanceTest.php
deleted file mode 100644
index 068f567d..00000000
--- a/tests/lib/Core/Provider/Cloudinary/Factory/CloudinaryInstanceTest.php
+++ /dev/null
@@ -1,35 +0,0 @@
-cloudinaryInstanceFactory = new CloudinaryInstanceFactory('myCloud', 'myKey', 'mySecret', 'myprefix');
- }
-
- public function testCreate(): void
- {
- $cloudinaryInstance = $this->cloudinaryInstanceFactory->create();
-
- self::assertInstanceOf(Cloudinary::class, $cloudinaryInstance);
-
- $newCloudinaryInstance = $this->cloudinaryInstanceFactory->create();
-
- self::assertSame(
- $cloudinaryInstance,
- $newCloudinaryInstance,
- );
- }
-}
diff --git a/tests/lib/Core/Provider/Cloudinary/Factory/RemoteResourceTest.php b/tests/lib/Core/Provider/Cloudinary/Factory/RemoteResourceTest.php
index 8d30ba75..898ba441 100644
--- a/tests/lib/Core/Provider/Cloudinary/Factory/RemoteResourceTest.php
+++ b/tests/lib/Core/Provider/Cloudinary/Factory/RemoteResourceTest.php
@@ -9,7 +9,7 @@
use Netgen\RemoteMedia\API\Values\RemoteResource;
use Netgen\RemoteMedia\Core\Provider\Cloudinary\Converter\ResourceType as ResourceTypeConverter;
use Netgen\RemoteMedia\Core\Provider\Cloudinary\Converter\VisibilityType as VisibilityTypeConverter;
-use Netgen\RemoteMedia\Core\Provider\Cloudinary\Factory\CloudinaryInstance;
+use Netgen\RemoteMedia\Core\Provider\Cloudinary\Factory\CloudinaryConfiguration;
use Netgen\RemoteMedia\Core\Provider\Cloudinary\Factory\RemoteResource as RemoteResourceFactory;
use Netgen\RemoteMedia\Exception\Factory\InvalidDataException;
use Netgen\RemoteMedia\Tests\AbstractTestCase;
@@ -28,8 +28,15 @@ protected function setUp(): void
{
$this->fileHashFactoryMock = $this->createMock(FileHashFactoryInterface::class);
- $cloudinaryInstanceFactory = new CloudinaryInstance('myCloud', 'myKey', 'mySecret', 'https://api.cloudinary.com');
- $cloudinaryInstanceFactory->create();
+ $cloudinaryConfigurationFactory = new CloudinaryConfiguration(
+ 'testcloud',
+ 'apikey',
+ 'apisecret',
+ 'https://api.cloudinary.com',
+ false,
+ );
+
+ $cloudinaryConfigurationFactory->create();
$this->remoteResourceFactory = new RemoteResourceFactory(
new ResourceTypeConverter(),
@@ -88,8 +95,8 @@ public static function createDataProvider(): array
'created_at' => '2013-06-23T13:59:18Z',
'bytes' => 120253,
'type' => 'upload',
- 'url' => 'http://res.cloudinary.com/myCloud/image/upload/v1371995958/c87hg9xfxrd4itiim3t0.jpg',
- 'secure_url' => 'https://res.cloudinary.com/myCloud/image/upload/v1371995958/c87hg9xfxrd4itiim3t0.jpg',
+ 'url' => 'http://res.cloudinary.com/testcloud/image/upload/v1371995958/c87hg9xfxrd4itiim3t0.jpg',
+ 'secure_url' => 'https://res.cloudinary.com/testcloud/image/upload/v1371995958/c87hg9xfxrd4itiim3t0.jpg',
'etag' => 'e522f43cf89aa0afd03387c37e2b6e12',
'tags' => ['tag1'],
'overwritten' => 'true',
@@ -110,7 +117,7 @@ public static function createDataProvider(): array
new RemoteResource(
remoteId: 'upload|image|c87hg9xfxrd4itiim3t0',
type: 'image',
- url: 'https://res.cloudinary.com/myCloud/image/upload/c87hg9xfxrd4itiim3t0',
+ url: 'https://res.cloudinary.com/testcloud/image/upload/c87hg9xfxrd4itiim3t0',
md5: 'e522f43cf89aa0afd03387c37e2b6e12',
name: 'c87hg9xfxrd4itiim3t0',
originalFilename: 'c87hg9xfxrd4itiim3t0.jpg',
@@ -142,8 +149,8 @@ public static function createDataProvider(): array
'created_at' => '2013-06-23T13:59:18Z',
'bytes' => 120253,
'type' => 'upload',
- 'url' => 'http://res.cloudinary.com/myCloud/image/upload/v1371995958/other/c87hg9xfxrd4itiim3t0',
- 'secure_url' => 'https://res.cloudinary.com/myCloud/image/upload/v1371995958/other/c87hg9xfxrd4itiim3t0',
+ 'url' => 'http://res.cloudinary.com/testcloud/image/upload/v1371995958/other/c87hg9xfxrd4itiim3t0',
+ 'secure_url' => 'https://res.cloudinary.com/testcloud/image/upload/v1371995958/other/c87hg9xfxrd4itiim3t0',
'etag' => 'e522f43cf89aa0afd03387c37e2b6e29',
'context' => [
'custom' => [
@@ -154,7 +161,7 @@ public static function createDataProvider(): array
new RemoteResource(
remoteId: 'upload|image|other/c87hg9xfxrd4itiim3t0',
type: 'document',
- url: 'https://res.cloudinary.com/myCloud/image/upload/other/c87hg9xfxrd4itiim3t0',
+ url: 'https://res.cloudinary.com/testcloud/image/upload/other/c87hg9xfxrd4itiim3t0',
md5: 'e522f43cf89aa0afd03387c37e2b6e29',
name: 'c87hg9xfxrd4itiim3t0',
originalFilename: 'my_original_image.jpg',
@@ -182,8 +189,8 @@ public static function createDataProvider(): array
'resource_type' => 'video',
'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',
+ 'url' => 'http://res.cloudinary.com/testcloud/video/upload/v1371995958/c87hg9xfxrd4itiim3t0.mp4',
+ 'secure_url' => 'http://res.cloudinary.com/testcloud/video/upload/v1371995958/c87hg9xfxrd4itiim3t0.mp4',
'tags' => ['tag1', 'tag2'],
'overwritten' => 'false',
'context' => [
@@ -199,7 +206,7 @@ public static function createDataProvider(): array
new RemoteResource(
remoteId: 'upload|video|c87hg9xfxrd4itiim3t0',
type: 'video',
- url: 'https://res.cloudinary.com/myCloud/video/upload/c87hg9xfxrd4itiim3t0',
+ url: 'https://res.cloudinary.com/testcloud/video/upload/c87hg9xfxrd4itiim3t0',
md5: 'a522f23sf81aa0afd03387c37e2b6eax',
name: 'c87hg9xfxrd4itiim3t0',
originalFilename: 'c87hg9xfxrd4itiim3t0.mp4',
@@ -230,8 +237,8 @@ public static function createDataProvider(): array
'created_at' => '2013-06-23T13:59:18Z',
'bytes' => 120253,
'type' => 'authenticated',
- 'url' => 'http://res.cloudinary.com/myCloud/video/authenticated/v1371995958/c87hg9xfxrd4itiim3t0.mp4',
- 'secure_url' => 'https://res.cloudinary.com/myCloud/video/authenticated/v1371995958/c87hg9xfxrd4itiim3t0.mp4',
+ 'url' => 'http://res.cloudinary.com/testcloud/video/authenticated/v1371995958/c87hg9xfxrd4itiim3t0.mp4',
+ 'secure_url' => 'https://res.cloudinary.com/testcloud/video/authenticated/v1371995958/c87hg9xfxrd4itiim3t0.mp4',
'tags' => ['tag1', 'tag2'],
'overwritten' => 'false',
'context' => [],
@@ -243,7 +250,7 @@ public static function createDataProvider(): array
new RemoteResource(
remoteId: 'authenticated|video|c87hg9xfxrd4itiim3t0',
type: 'video',
- url: 'https://res.cloudinary.com/myCloud/video/authenticated/c87hg9xfxrd4itiim3t0',
+ url: 'https://res.cloudinary.com/testcloud/video/authenticated/c87hg9xfxrd4itiim3t0',
md5: 'a522f23sf81aa0afd03387c37e2b6eax',
name: 'c87hg9xfxrd4itiim3t0',
originalFilename: 'c87hg9xfxrd4itiim3t0.mp4',
@@ -271,7 +278,7 @@ public static function createDataProvider(): array
'created_at' => '2013-06-23T13:59:18Z',
'bytes' => 12025,
'type' => 'authenticated',
- 'secure_url' => 'https://res.cloudinary.com/myCloud/authenticated/video/v1371995958/c87hg9xfxrd4itiim3t0.mp3',
+ 'secure_url' => 'https://res.cloudinary.com/testcloud/authenticated/video/v1371995958/c87hg9xfxrd4itiim3t0.mp3',
'etag' => 'e522f43cf89aa0afd03387c37e2b6e29',
'overwritten' => 'false',
'context' => [
@@ -285,7 +292,7 @@ public static function createDataProvider(): array
new RemoteResource(
remoteId: 'authenticated|video|c87hg9xfxrd4itiim3t0',
type: 'audio',
- url: 'https://res.cloudinary.com/myCloud/video/authenticated/c87hg9xfxrd4itiim3t0',
+ url: 'https://res.cloudinary.com/testcloud/video/authenticated/c87hg9xfxrd4itiim3t0',
md5: 'e522f43cf89aa0afd03387c37e2b6e29',
name: 'c87hg9xfxrd4itiim3t0',
originalFilename: 'c87hg9xfxrd4itiim3t0.mp3',
@@ -314,7 +321,7 @@ public static function createDataProvider(): array
'created_at' => '2011-06-23T13:59:18Z',
'bytes' => 12025,
'type' => 'test',
- 'secure_url' => 'https://res.cloudinary.com/myCloud/v1371995958/raw/media/raw/new/c87hg9xfxrd4itiim3t0',
+ 'secure_url' => 'https://res.cloudinary.com/testcloud/v1371995958/raw/media/raw/new/c87hg9xfxrd4itiim3t0',
'etag' => 'e522f43cf89aa0afd03387c38e2b6e29',
'context' => [
'test' => 'test',
@@ -327,7 +334,7 @@ public static function createDataProvider(): array
new RemoteResource(
remoteId: 'test|raw|media/raw/new/c87hg9xfxrd4itiim3t0',
type: 'other',
- url: 'https://res.cloudinary.com/myCloud/raw/test/media/raw/new/c87hg9xfxrd4itiim3t0',
+ url: 'https://res.cloudinary.com/testcloud/raw/test/media/raw/new/c87hg9xfxrd4itiim3t0',
md5: 'e522f43cf89aa0afd03387c38e2b6e29',
name: 'c87hg9xfxrd4itiim3t0',
originalFilename: 'test.mp4',
diff --git a/tests/lib/Core/Provider/Cloudinary/Gateway/CloudinaryApiGatewayTest.php b/tests/lib/Core/Provider/Cloudinary/Gateway/CloudinaryApiGatewayTest.php
index cd765169..80359447 100644
--- a/tests/lib/Core/Provider/Cloudinary/Gateway/CloudinaryApiGatewayTest.php
+++ b/tests/lib/Core/Provider/Cloudinary/Gateway/CloudinaryApiGatewayTest.php
@@ -5,11 +5,11 @@
namespace Netgen\RemoteMedia\Tests\Core\Provider\Cloudinary\Gateway;
use ArrayObject;
-use Cloudinary;
-use Cloudinary\Api;
-use Cloudinary\Api\Response as CloudinaryApiResponse;
-use Cloudinary\Search;
-use Cloudinary\Uploader as CloudinaryUploader;
+use Cloudinary\Api\Admin\AdminApi;
+use Cloudinary\Api\ApiResponse;
+use Cloudinary\Api\Exception\NotFound;
+use Cloudinary\Api\Search\SearchApi;
+use Cloudinary\Api\Upload\UploadApi;
use DateTimeImmutable;
use Netgen\RemoteMedia\API\Factory\RemoteResource as RemoteResourceFactoryInterface;
use Netgen\RemoteMedia\API\Factory\SearchResult as SearchResultFactoryInterface;
@@ -21,39 +21,26 @@
use Netgen\RemoteMedia\Core\Provider\Cloudinary\CloudinaryRemoteId;
use Netgen\RemoteMedia\Core\Provider\Cloudinary\Converter\ResourceType as ResourceTypeConverter;
use Netgen\RemoteMedia\Core\Provider\Cloudinary\Converter\VisibilityType as VisibilityTypeConverter;
-use Netgen\RemoteMedia\Core\Provider\Cloudinary\Factory\CloudinaryInstance;
use Netgen\RemoteMedia\Core\Provider\Cloudinary\Gateway\CloudinaryApiGateway;
use Netgen\RemoteMedia\Core\Provider\Cloudinary\Resolver\AuthToken as AuthTokenResolver;
use Netgen\RemoteMedia\Core\Provider\Cloudinary\Resolver\SearchExpression as SearchExpressionResolver;
use Netgen\RemoteMedia\Exception\FolderNotFoundException;
use Netgen\RemoteMedia\Exception\RemoteResourceNotFoundException;
use Netgen\RemoteMedia\Tests\AbstractTestCase;
+use Netgen\RemoteMedia\Tests\Core\Provider\Cloudinary\CloudinaryConfigurationInitializer;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\MockObject\MockObject;
-use stdClass;
-
-use function json_encode;
#[CoversClass(CloudinaryApiGateway::class)]
class CloudinaryApiGatewayTest extends AbstractTestCase
{
- protected const CLOUD_NAME = 'testcloud';
-
- protected const API_KEY = 'apikey';
-
- protected const API_SECRET = 'secret';
-
- protected const UPLOAD_PREFIX = 'https://api.cloudinary.com';
-
- protected const ENCRYPTION_KEY = '38128319a3a49e1d589a31a217e1a3f8';
-
protected CloudinaryApiGateway $apiGateway;
- protected Cloudinary|MockObject $cloudinaryMock;
+ protected AdminApi|MockObject $adminApiMock;
- protected Api|MockObject $cloudinaryApiMock;
+ protected MockObject|UploadApi $uploadApiMock;
- protected MockObject|Search $cloudinarySearchMock;
+ protected MockObject|SearchApi $searchApiMock;
protected MockObject|RemoteResourceFactoryInterface $remoteResourceFactoryMock;
@@ -61,35 +48,27 @@ class CloudinaryApiGatewayTest extends AbstractTestCase
protected function setUp(): void
{
- $this->cloudinaryMock = $this->createMock(Cloudinary::class);
- $this->cloudinaryApiMock = $this->createMock(Api::class);
- $this->cloudinarySearchMock = $this->createMock(Search::class);
+ $this->adminApiMock = $this->createMock(AdminApi::class);
+ $this->uploadApiMock = $this->createMock(UploadApi::class);
+ $this->searchApiMock = $this->createMock(SearchApi::class);
$this->remoteResourceFactoryMock = $this->createMock(RemoteResourceFactoryInterface::class);
$this->searchResultFactoryMock = $this->createMock(SearchResultFactoryInterface::class);
- $cloudinaryInstanceFactory = new CloudinaryInstance(
- self::CLOUD_NAME,
- self::API_KEY,
- self::API_SECRET,
- self::UPLOAD_PREFIX,
- );
-
$this->apiGateway = new CloudinaryApiGateway(
- $cloudinaryInstanceFactory->create(),
+ CloudinaryConfigurationInitializer::getConfiguration(),
$this->remoteResourceFactoryMock,
$this->searchResultFactoryMock,
new SearchExpressionResolver(
new ResourceTypeConverter(),
new VisibilityTypeConverter(),
),
- new AuthTokenResolver(self::ENCRYPTION_KEY),
+ new AuthTokenResolver(CloudinaryConfigurationInitializer::ENCRYPTION_KEY),
);
$this->apiGateway->setServices(
- $this->cloudinaryMock,
- new CloudinaryUploader(),
- $this->cloudinaryApiMock,
- $this->cloudinarySearchMock,
+ $this->adminApiMock,
+ $this->uploadApiMock,
+ $this->searchApiMock,
);
}
@@ -130,17 +109,15 @@ public function testUsage(): void
],
];
- $response = new stdClass();
- $response->body = json_encode($data);
- $response->headers = [
- 'X-FeatureRateLimit-Reset' => '12.11.2021 17:00:00',
- 'X-FeatureRateLimit-Limit' => 1567654320,
- 'X-FeatureRateLimit-Remaining' => 1965,
+ $headers = [
+ 'X-FeatureRateLimit-Reset' => ['12.11.2021 17:00:00'],
+ 'X-FeatureRateLimit-Limit' => ['1567654320'],
+ 'X-FeatureRateLimit-Remaining' => ['1965'],
];
- $response = new CloudinaryApiResponse($response);
+ $response = new ApiResponse($data, $headers);
- $this->cloudinaryApiMock
+ $this->adminApiMock
->expects(self::once())
->method('usage')
->willReturn($response);
@@ -243,7 +220,7 @@ public function testUsage(): void
self::assertTrue($usage->has('credits_limit'));
self::assertSame(
- 135,
+ 135.0,
$usage->get('credits_limit'),
);
@@ -255,15 +232,8 @@ public function testIsEncryptionEnabled(): void
{
self::assertTrue($this->apiGateway->isEncryptionEnabled());
- $cloudinaryInstanceFactory = new CloudinaryInstance(
- self::CLOUD_NAME,
- self::API_KEY,
- self::API_SECRET,
- self::UPLOAD_PREFIX,
- );
-
$apiGateway = new CloudinaryApiGateway(
- $cloudinaryInstanceFactory->create(),
+ CloudinaryConfigurationInitializer::getConfiguration(),
$this->remoteResourceFactoryMock,
$this->searchResultFactoryMock,
new SearchExpressionResolver(
@@ -278,7 +248,7 @@ public function testIsEncryptionEnabled(): void
public function testCountResources(): void
{
- $this->cloudinaryApiMock
+ $this->adminApiMock
->expects(self::once())
->method('usage')
->willReturn(['resources' => 1200]);
@@ -293,19 +263,19 @@ public function testCountResourcesInFolder(): void
{
$expression = 'folder:folderName/*';
- $this->cloudinarySearchMock
+ $this->searchApiMock
->expects(self::once())
->method('expression')
->with($expression)
- ->willReturn($this->cloudinarySearchMock);
+ ->willReturn($this->searchApiMock);
- $this->cloudinarySearchMock
+ $this->searchApiMock
->expects(self::once())
- ->method('max_results')
+ ->method('maxResults')
->with(0)
- ->willReturn($this->cloudinarySearchMock);
+ ->willReturn($this->searchApiMock);
- $this->cloudinarySearchMock
+ $this->searchApiMock
->expects(self::once())
->method('execute')
->willReturn($this->getSearchResponse());
@@ -329,9 +299,9 @@ public function testListFolders(): void
],
];
- $this->cloudinaryApiMock
+ $this->adminApiMock
->expects(self::once())
- ->method('root_folders')
+ ->method('rootFolders')
->willReturn(
new ArrayObject(
['folders' => $folders],
@@ -360,7 +330,7 @@ public function testListSubFolders(): void
],
];
- $this->cloudinaryApiMock
+ $this->adminApiMock
->expects(self::once())
->method('subfolders')
->with('folder_1')
@@ -381,11 +351,11 @@ public function testListSubFolders(): void
public function testListSubFoldersInNonExistingParent(): void
{
- $this->cloudinaryApiMock
+ $this->adminApiMock
->expects(self::once())
->method('subfolders')
->with('non_existing_folder/non_existing_subfolder')
- ->willThrowException(new Api\NotFound());
+ ->willThrowException(new NotFound());
self::expectException(FolderNotFoundException::class);
self::expectExceptionMessage('Folder with path "non_existing_folder/non_existing_subfolder" was not found on remote.');
@@ -397,9 +367,9 @@ public function testCreateFolder(): void
{
$path = 'folder/subfolder/my_new_folder';
- $this->cloudinaryApiMock
+ $this->adminApiMock
->expects(self::once())
- ->method('create_folder')
+ ->method('createFolder')
->with($path);
$this->apiGateway->createFolder($path);
@@ -417,9 +387,9 @@ public function testGet(): void
'secure_url' => 'https://res.cloudinary.com/demo/image/upload/folder/test_image.jpg',
];
- $this->cloudinaryApiMock
+ $this->adminApiMock
->expects(self::once())
- ->method('resource')
+ ->method('asset')
->with(
$remoteId->getResourceId(),
[
@@ -457,9 +427,9 @@ public function testGetNotExisting(): void
{
$remoteId = CloudinaryRemoteId::fromRemoteId('upload|image|folder/test_image.jpg');
- $this->cloudinaryApiMock
+ $this->adminApiMock
->expects(self::once())
- ->method('resource')
+ ->method('asset')
->with(
$remoteId->getResourceId(),
[
@@ -470,7 +440,7 @@ public function testGetNotExisting(): void
'exif' => true,
],
)
- ->willThrowException(new Api\NotFound());
+ ->willThrowException(new NotFound());
self::expectException(RemoteResourceNotFoundException::class);
self::expectExceptionMessage('Remote resource with ID "upload|image|folder/test_image.jpg" not found.');
@@ -534,31 +504,31 @@ public function testSearch(): void
. ' AND test* AND (folder:"test_folder") AND (tags:"tag1")';
$limit = 25;
- $this->cloudinarySearchMock
+ $this->searchApiMock
->expects(self::once())
->method('expression')
->with($expression)
- ->willReturn($this->cloudinarySearchMock);
+ ->willReturn($this->searchApiMock);
- $this->cloudinarySearchMock
+ $this->searchApiMock
->expects(self::once())
- ->method('max_results')
+ ->method('maxResults')
->with($limit)
- ->willReturn($this->cloudinarySearchMock);
+ ->willReturn($this->searchApiMock);
- $this->cloudinarySearchMock
+ $this->searchApiMock
->expects(self::exactly(2))
- ->method('with_field')
+ ->method('withField')
->willReturnMap(
[
- ['context', $this->cloudinarySearchMock],
- ['tags', $this->cloudinarySearchMock],
+ ['context', $this->searchApiMock],
+ ['tags', $this->searchApiMock],
],
);
$apiResponse = $this->getSearchResponse();
- $this->cloudinarySearchMock
+ $this->searchApiMock
->expects(self::once())
->method('execute')
->willReturn($apiResponse);
@@ -606,37 +576,37 @@ public function testSearchWithNextCursor(): void
$limit = 25;
$nextCursor = 'gfr566455fdg';
- $this->cloudinarySearchMock
+ $this->searchApiMock
->expects(self::once())
->method('expression')
->with($expression)
- ->willReturn($this->cloudinarySearchMock);
+ ->willReturn($this->searchApiMock);
- $this->cloudinarySearchMock
+ $this->searchApiMock
->expects(self::once())
- ->method('max_results')
+ ->method('maxResults')
->with($limit)
- ->willReturn($this->cloudinarySearchMock);
+ ->willReturn($this->searchApiMock);
- $this->cloudinarySearchMock
+ $this->searchApiMock
->expects(self::exactly(2))
- ->method('with_field')
+ ->method('withField')
->willReturnMap(
[
- ['context', $this->cloudinarySearchMock],
- ['tags', $this->cloudinarySearchMock],
+ ['context', $this->searchApiMock],
+ ['tags', $this->searchApiMock],
],
);
$apiResponse = $this->getSearchResponse();
- $this->cloudinarySearchMock
+ $this->searchApiMock
->expects(self::once())
- ->method('next_cursor')
+ ->method('nextCursor')
->willReturn($nextCursor)
- ->willReturn($this->cloudinarySearchMock);
+ ->willReturn($this->searchApiMock);
- $this->cloudinarySearchMock
+ $this->searchApiMock
->expects(self::once())
->method('execute')
->willReturn($apiResponse);
@@ -683,21 +653,21 @@ public function testSearchCount(): void
. ' AND (!format="m4a") AND (!format="mp3") AND (!format="ogg") AND (!format="opus") AND (!format="wav")))'
. ' AND test* AND (folder:"test_folder") AND (tags:"tag1")';
- $this->cloudinarySearchMock
+ $this->searchApiMock
->expects(self::once())
->method('expression')
->with($expression)
- ->willReturn($this->cloudinarySearchMock);
+ ->willReturn($this->searchApiMock);
- $this->cloudinarySearchMock
+ $this->searchApiMock
->expects(self::once())
- ->method('max_results')
+ ->method('maxResults')
->with(0)
- ->willReturn($this->cloudinarySearchMock);
+ ->willReturn($this->searchApiMock);
$apiResponse = $this->getSearchResponse();
- $this->cloudinarySearchMock
+ $this->searchApiMock
->expects(self::once())
->method('execute')
->willReturn($apiResponse);
@@ -717,7 +687,7 @@ public function testSearchCount(): void
public function testListTags(): void
{
- $this->cloudinaryApiMock
+ $this->adminApiMock
->expects(self::exactly(3))
->method('tags')
->willReturnMap(
@@ -786,31 +756,31 @@ public function testSearchResourceByHash(): void
. ' AND test* AND (folder:"test_folder") AND (etag="e522f43cf89aa0afd03387c37e2b6e29")';
$limit = 1;
- $this->cloudinarySearchMock
+ $this->searchApiMock
->expects(self::once())
->method('expression')
->with($expression)
- ->willReturn($this->cloudinarySearchMock);
+ ->willReturn($this->searchApiMock);
- $this->cloudinarySearchMock
+ $this->searchApiMock
->expects(self::once())
- ->method('max_results')
+ ->method('maxResults')
->with($limit)
- ->willReturn($this->cloudinarySearchMock);
+ ->willReturn($this->searchApiMock);
- $this->cloudinarySearchMock
+ $this->searchApiMock
->expects(self::exactly(2))
- ->method('with_field')
+ ->method('withField')
->willReturnMap(
[
- ['context', $this->cloudinarySearchMock],
- ['tags', $this->cloudinarySearchMock],
+ ['context', $this->searchApiMock],
+ ['tags', $this->searchApiMock],
],
);
$apiResponse = $this->getSearchResponse();
- $this->cloudinarySearchMock
+ $this->searchApiMock
->expects(self::once())
->method('execute')
->willReturn($apiResponse);
@@ -854,7 +824,7 @@ public function testGetVideoThumbnail(): void
$cloudinaryRemoteId = CloudinaryRemoteId::fromRemoteId('upload|video|media/example');
self::assertSame(
- 'https://res.cloudinary.com/testcloud/video/upload/media/example.jpg',
+ 'https://res.cloudinary.com/testcloud/video/upload/media/example',
$this->apiGateway->getVideoThumbnail($cloudinaryRemoteId),
);
}
@@ -865,7 +835,7 @@ public function testGetVideoThumbnailAuthenticated(): void
$token = AuthToken::fromExpiresAt(new DateTimeImmutable('2023/1/1'));
self::assertSame(
- 'https://res.cloudinary.com/testcloud/video/upload/media/example.jpg?__cld_token__=exp=1672531200~hmac=62ddaa466e7acbd07699201e33c8c1865b78b91365bd727f7b88ac524f02095b',
+ 'https://res.cloudinary.com/testcloud/video/upload/media/example?__cld_token__=exp=1672531200~hmac=91194b19360a54349173e96f49135838cdabd3cdb07d97eb2f12b60d8168e5cc',
$this->apiGateway->getVideoThumbnail($cloudinaryRemoteId, [], $token),
);
}
@@ -875,7 +845,7 @@ public function testGetImageTag(): void
$cloudinaryRemoteId = CloudinaryRemoteId::fromRemoteId('upload|image|media/example');
self::assertSame(
- "",
+ "",
$this->apiGateway->getImageTag($cloudinaryRemoteId),
);
}
@@ -886,7 +856,7 @@ public function testGetImageTagAuthenticated(): void
$token = AuthToken::fromExpiresAt(new DateTimeImmutable('2023/1/1'));
self::assertSame(
- "",
+ "",
$this->apiGateway->getImageTag($cloudinaryRemoteId, [], $token),
);
}
@@ -918,21 +888,18 @@ public function testGetVideoTagAuthenticated(): void
);
}
- private function getCloudinaryResponse(array $data): CloudinaryApiResponse
+ private function getCloudinaryResponse(array $data): ApiResponse
{
- $response = new stdClass();
- $response->body = json_encode($data);
- $response->responseCode = 200;
- $response->headers = [
+ $headers = [
'X-FeatureRateLimit-Reset' => 'test',
'X-FeatureRateLimit-Limit' => 'test',
'X-FeatureRateLimit-Remaining' => 'test',
];
- return new CloudinaryApiResponse($response);
+ return new ApiResponse($data, $headers);
}
- private function getSearchResponse(): CloudinaryApiResponse
+ private function getSearchResponse(): ApiResponse
{
return $this->getCloudinaryResponse([
'total_count' => 200,
diff --git a/tests/lib/Core/Provider/Cloudinary/Gateway/Log/MonologLoggedGatewayTest.php b/tests/lib/Core/Provider/Cloudinary/Gateway/Log/MonologLoggedGatewayTest.php
index 4f4173ea..43841ca1 100644
--- a/tests/lib/Core/Provider/Cloudinary/Gateway/Log/MonologLoggedGatewayTest.php
+++ b/tests/lib/Core/Provider/Cloudinary/Gateway/Log/MonologLoggedGatewayTest.php
@@ -325,7 +325,7 @@ public function testGetAuthenticatedUrl(): void
$this->loggerMock
->expects(self::once())
->method('info')
- ->with('[INTERNAL][FREE] getAuthenticatedUrl("upload|image|folder/test_image.jpg") -> cloudinary_url_internal("upload|image|folder/test_image.jpg")');
+ ->with('[INTERNAL][FREE] getAuthenticatedUrl("upload|image|folder/test_image.jpg") -> Media::fromParams("upload|image|folder/test_image.jpg")');
self::assertSame(
$url,
@@ -353,7 +353,7 @@ public function testGetVariationUrl(): void
$this->loggerMock
->expects(self::once())
->method('info')
- ->with("[INTERNAL][FREE] getVariationUrl(\"{$remoteId->getRemoteId()}\") -> cloudinary_url_internal(\"{$remoteId->getRemoteId()}\")");
+ ->with("[INTERNAL][FREE] getVariationUrl(\"{$remoteId->getRemoteId()}\") -> Media::fromParams(\"{$remoteId->getRemoteId()}\")");
self::assertSame(
'https://res.cloudinary.com/testcloud/image/upload/c_crop,h_200,w_300,x_50,y_50/folder/test_image.jpg',
@@ -456,7 +456,7 @@ public function testGetVideoThumbnail(): void
$this->loggerMock
->expects(self::once())
->method('info')
- ->with("[INTERNAL][FREE] getVideoThumbnail(\"{$remoteId->getRemoteId()}\") -> cl_video_thumbnail_path(\"{$remoteId->getRemoteId()}\")");
+ ->with("[INTERNAL][FREE] getVideoThumbnail(\"{$remoteId->getRemoteId()}\") -> Image::fromParams(\"{$remoteId->getRemoteId()}\")");
self::assertSame(
'video_thumbnail.jpg',
@@ -477,7 +477,7 @@ public function testGetImageTag(): void
$this->loggerMock
->expects(self::once())
->method('info')
- ->with("[INTERNAL][FREE] getImageTag(\"{$remoteId->getRemoteId()}\") -> cl_image_tag(\"{$remoteId->getRemoteId()}\")");
+ ->with("[INTERNAL][FREE] getImageTag(\"{$remoteId->getRemoteId()}\") -> ImageTag::fromParams(\"{$remoteId->getRemoteId()}\")");
self::assertSame(
'',
@@ -498,7 +498,7 @@ public function testGetVideoTag(): void
$this->loggerMock
->expects(self::once())
->method('info')
- ->with("[INTERNAL][FREE] getVideoTag(\"{$remoteId->getRemoteId()}\") -> cl_video_tag(\"{$remoteId->getRemoteId()}\")");
+ ->with("[INTERNAL][FREE] getVideoTag(\"{$remoteId->getRemoteId()}\") -> VideoTag::fromParams(\"{$remoteId->getRemoteId()}\")");
self::assertSame(
'',
@@ -523,7 +523,7 @@ public function testGetDownloadLink(): void
$this->loggerMock
->expects(self::once())
->method('info')
- ->with("[INTERNAL][FREE] getDownloadLink(\"{$remoteId->getRemoteId()}\") -> Cloudinary::cloudinary_url(\"{$remoteId->getRemoteId()}\")");
+ ->with("[INTERNAL][FREE] getDownloadLink(\"{$remoteId->getRemoteId()}\") -> Media::fromParams(\"{$remoteId->getRemoteId()}\")");
self::assertSame(
'https://cloudinary.com/test.zip',
diff --git a/tests/lib/Core/Provider/Cloudinary/Resolver/UploadOptionsTest.php b/tests/lib/Core/Provider/Cloudinary/Resolver/UploadOptionsTest.php
index 17a538eb..d075d82e 100644
--- a/tests/lib/Core/Provider/Cloudinary/Resolver/UploadOptionsTest.php
+++ b/tests/lib/Core/Provider/Cloudinary/Resolver/UploadOptionsTest.php
@@ -70,7 +70,7 @@ public static function dataProvider(): array
'type' => 'upload',
'resource_type' => 'auto',
'access_mode' => 'public',
- 'access_control' => ['access_type' => 'anonymous'],
+ 'access_control' => [['access_type' => 'anonymous']],
'tags' => [],
],
],
@@ -92,7 +92,7 @@ public static function dataProvider(): array
'type' => 'upload',
'resource_type' => 'auto',
'access_mode' => 'public',
- 'access_control' => ['access_type' => 'anonymous'],
+ 'access_control' => [['access_type' => 'anonymous']],
'tags' => [],
],
],
@@ -131,7 +131,7 @@ public static function dataProvider(): array
'type' => 'authenticated',
'resource_type' => 'raw',
'access_mode' => 'authenticated',
- 'access_control' => ['access_type' => 'token'],
+ 'access_control' => [['access_type' => 'token']],
'tags' => ['backup'],
],
],
@@ -163,7 +163,7 @@ public static function dataProvider(): array
'type' => 'authenticated',
'resource_type' => 'raw',
'access_mode' => 'authenticated',
- 'access_control' => ['access_type' => 'token'],
+ 'access_control' => [['access_type' => 'token']],
'tags' => ['backup', 'archive'],
],
],
@@ -184,7 +184,7 @@ public static function dataProvider(): array
'type' => 'upload',
'resource_type' => 'auto',
'access_mode' => 'public',
- 'access_control' => ['access_type' => 'anonymous'],
+ 'access_control' => [['access_type' => 'anonymous']],
'tags' => [],
],
],
@@ -214,7 +214,7 @@ public static function dataProvider(): array
'type' => 'upload',
'resource_type' => 'video',
'access_mode' => 'public',
- 'access_control' => ['access_type' => 'anonymous'],
+ 'access_control' => [['access_type' => 'anonymous']],
'tags' => [],
],
],
@@ -242,7 +242,7 @@ public static function dataProvider(): array
'type' => 'authenticated',
'resource_type' => 'auto',
'access_mode' => 'authenticated',
- 'access_control' => ['access_type' => 'token'],
+ 'access_control' => [['access_type' => 'token']],
'tags' => [],
],
],
@@ -266,7 +266,7 @@ public static function dataProvider(): array
'type' => 'upload',
'resource_type' => 'auto',
'access_mode' => 'public',
- 'access_control' => ['access_type' => 'anonymous'],
+ 'access_control' => [['access_type' => 'anonymous']],
'tags' => [],
],
false,
diff --git a/tests/lib/Core/Provider/Cloudinary/Verifier/Request/SignatureTest.php b/tests/lib/Core/Provider/Cloudinary/Verifier/Request/SignatureTest.php
index cf889c4f..fc6ed0e9 100644
--- a/tests/lib/Core/Provider/Cloudinary/Verifier/Request/SignatureTest.php
+++ b/tests/lib/Core/Provider/Cloudinary/Verifier/Request/SignatureTest.php
@@ -4,9 +4,9 @@
namespace Netgen\RemoteMedia\Tests\Core\Provider\Cloudinary\Verifier\Request;
-use Cloudinary;
-use Cloudinary\SignatureVerifier as CloudinarySignatureVerifier;
+use Cloudinary\Utils\SignatureVerifier as CloudinarySignatureVerifier;
use Netgen\RemoteMedia\Core\Provider\Cloudinary\Verifier\Request\Signature as SignatureVerifier;
+use Netgen\RemoteMedia\Tests\Core\Provider\Cloudinary\CloudinaryConfigurationInitializer;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\Request;
@@ -17,25 +17,11 @@
#[CoversClass(SignatureVerifier::class)]
class SignatureTest extends TestCase
{
- private const CLOUD_NAME = 'testcloud';
-
- private const API_KEY = 'apikey';
-
- private const API_SECRET = 'secret';
-
private SignatureVerifier $signatureVerifier;
protected function setUp(): void
{
- $cloudinary = new Cloudinary();
- $cloudinary->config(
- [
- 'cloud_name' => self::CLOUD_NAME,
- 'api_key' => self::API_KEY,
- 'api_secret' => self::API_SECRET,
- 'cdn_subdomain' => true,
- ],
- );
+ CloudinaryConfigurationInitializer::getConfiguration();
$this->signatureVerifier = new SignatureVerifier();
}
@@ -77,7 +63,7 @@ public function testVerifyValid(): void
$timestamp = time();
$payloadToSign = $body . $timestamp;
- $signature = CloudinarySignatureVerifier::generateHmac($payloadToSign, self::API_SECRET);
+ $signature = CloudinarySignatureVerifier::generateHmac($payloadToSign, CloudinaryConfigurationInitializer::API_SECRET);
$request->headers->add(
[