From d3c5bd9d4073cbffa629adffb41e0d879261bf1c Mon Sep 17 00:00:00 2001 From: Hamid Ghorashi Date: Thu, 13 Jun 2024 17:54:11 +0400 Subject: [PATCH] support removing version on demand --- src/Publiux/laravelcdn/Cdn.php | 2 +- src/Publiux/laravelcdn/CdnFacade.php | 7 +++++++ src/Publiux/laravelcdn/CdnHelper.php | 4 ++-- src/Publiux/laravelcdn/Contracts/CdnHelperInterface.php | 2 +- src/Publiux/laravelcdn/Contracts/CdnInterface.php | 2 +- 5 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/Publiux/laravelcdn/Cdn.php b/src/Publiux/laravelcdn/Cdn.php index aeb4cf4..a6f10a9 100644 --- a/src/Publiux/laravelcdn/Cdn.php +++ b/src/Publiux/laravelcdn/Cdn.php @@ -99,7 +99,7 @@ public function emptyBucket() * @param string $name The name to append to the upload folder. * @return $this The current instance of the Cdn class. */ - public function version(string $name) + public function version(?string $name) { $this->helper->setVersion($name); diff --git a/src/Publiux/laravelcdn/CdnFacade.php b/src/Publiux/laravelcdn/CdnFacade.php index 8e12fa5..081a7a7 100644 --- a/src/Publiux/laravelcdn/CdnFacade.php +++ b/src/Publiux/laravelcdn/CdnFacade.php @@ -186,4 +186,11 @@ private function generateUrl($path, $prepend = '') // call the provider specific url generator return $this->provider->urlGenerator($clean_path); } + + public function version(?string $name) + { + $this->helper->setVersion($name); + + return $this; + } } diff --git a/src/Publiux/laravelcdn/CdnHelper.php b/src/Publiux/laravelcdn/CdnHelper.php index 525a63e..91a7bcb 100644 --- a/src/Publiux/laravelcdn/CdnHelper.php +++ b/src/Publiux/laravelcdn/CdnHelper.php @@ -111,9 +111,9 @@ public function cleanPath($path) * * @return $this The current instance for method chaining. */ - public function setVersion(string $version): self + public function setVersion(?string $version): self { - $this->configurations->set('cdn.providers.aws.s3.cloudfront.cdn_version', trim($version, ' \/')); + $this->configurations->set('cdn.providers.aws.s3.cloudfront.cdn_version', !is_null($version) ? trim($version, ' \/') : null); return $this; } diff --git a/src/Publiux/laravelcdn/Contracts/CdnHelperInterface.php b/src/Publiux/laravelcdn/Contracts/CdnHelperInterface.php index bf0a1f3..8b248f0 100644 --- a/src/Publiux/laravelcdn/Contracts/CdnHelperInterface.php +++ b/src/Publiux/laravelcdn/Contracts/CdnHelperInterface.php @@ -19,5 +19,5 @@ public function startsWith($haystack, $needle); public function cleanPath($path); - public function setVersion(string $version): CdnHelperInterface; + public function setVersion(?string $name): CdnHelperInterface; } diff --git a/src/Publiux/laravelcdn/Contracts/CdnInterface.php b/src/Publiux/laravelcdn/Contracts/CdnInterface.php index d6a88da..3536dba 100644 --- a/src/Publiux/laravelcdn/Contracts/CdnInterface.php +++ b/src/Publiux/laravelcdn/Contracts/CdnInterface.php @@ -13,5 +13,5 @@ public function push(); public function emptyBucket(); - public function version(string $name); + public function version(?string $name); }