From e93cb965df45f3cec62cb099711f34fec14ca551 Mon Sep 17 00:00:00 2001 From: roadiz-ci Date: Fri, 8 Mar 2024 14:45:45 +0000 Subject: [PATCH] Merge branch hotfix/v2.2.12 --- src/Exceptions/PrivateDocumentException.php | 9 +++++ src/Renderer/AbstractImageRenderer.php | 7 +++- src/Renderer/VideoRenderer.php | 2 +- .../AbstractDocumentUrlGenerator.php | 36 ++++--------------- 4 files changed, 23 insertions(+), 31 deletions(-) create mode 100644 src/Exceptions/PrivateDocumentException.php diff --git a/src/Exceptions/PrivateDocumentException.php b/src/Exceptions/PrivateDocumentException.php new file mode 100644 index 0000000..133a087 --- /dev/null +++ b/src/Exceptions/PrivateDocumentException.php @@ -0,0 +1,9 @@ +getRelativePath())) { + if ( + isset($set['format']) && + isset($set['rule']) && + !$document->isPrivate() && + !empty($document->getRelativePath()) + ) { $this->documentUrlGenerator->setOptions($this->urlOptionsResolver->resolve($set['format'])); $this->documentUrlGenerator->setDocument($document); $path = $this->documentUrlGenerator->getUrl($absolute); diff --git a/src/Renderer/VideoRenderer.php b/src/Renderer/VideoRenderer.php index 109e056..15a84e4 100644 --- a/src/Renderer/VideoRenderer.php +++ b/src/Renderer/VideoRenderer.php @@ -78,7 +78,7 @@ protected function getPosterUrl( $document->hasThumbnails() ) { $thumbnail = $document->getThumbnails()->first(); - if ($thumbnail instanceof DocumentInterface) { + if (false !== $thumbnail) { $this->documentUrlGenerator->setOptions($options); $this->documentUrlGenerator->setDocument($thumbnail); return $this->documentUrlGenerator->getUrl($absolute); diff --git a/src/UrlGenerators/AbstractDocumentUrlGenerator.php b/src/UrlGenerators/AbstractDocumentUrlGenerator.php index 5208d1a..2c05f7f 100644 --- a/src/UrlGenerators/AbstractDocumentUrlGenerator.php +++ b/src/UrlGenerators/AbstractDocumentUrlGenerator.php @@ -7,6 +7,7 @@ use League\Flysystem\FilesystemOperator; use Psr\Cache\CacheItemPoolInterface; use Psr\Cache\InvalidArgumentException; +use RZ\Roadiz\Documents\Exceptions\PrivateDocumentException; use RZ\Roadiz\Documents\Models\DocumentInterface; use RZ\Roadiz\Documents\OptionsResolver\ViewOptionsResolver; use Symfony\Component\HttpFoundation\UrlHelper; @@ -15,35 +16,18 @@ abstract class AbstractDocumentUrlGenerator implements DocumentUrlGeneratorInter { protected ?DocumentInterface $document; protected array $options; - protected CacheItemPoolInterface $optionsCacheAdapter; protected ViewOptionsResolver $viewOptionsResolver; protected OptionsCompiler $optionCompiler; - protected FilesystemOperator $documentsStorage; - private UrlHelper $urlHelper; - /** - * @param FilesystemOperator $documentsStorage - * @param UrlHelper $urlHelper - * @param CacheItemPoolInterface $optionsCacheAdapter - * @param DocumentInterface|null $document - * @param array $options - * @throws InvalidArgumentException - */ public function __construct( - FilesystemOperator $documentsStorage, - UrlHelper $urlHelper, - CacheItemPoolInterface $optionsCacheAdapter, - DocumentInterface $document = null, + protected FilesystemOperator $documentsStorage, + protected UrlHelper $urlHelper, + protected CacheItemPoolInterface $optionsCacheAdapter, array $options = [] ) { - $this->document = $document; $this->viewOptionsResolver = new ViewOptionsResolver(); $this->optionCompiler = new OptionsCompiler(); - $this->optionsCacheAdapter = $optionsCacheAdapter; - $this->setOptions($options); - $this->documentsStorage = $documentsStorage; - $this->urlHelper = $urlHelper; } /** @@ -85,23 +69,17 @@ public function setDocument(DocumentInterface $document): static return $this; } - /** - * @param bool $absolute - * - * @return string - */ public function getUrl(bool $absolute = false): string { if (null === $this->document) { throw new \InvalidArgumentException('Cannot get URL from a NULL document'); } - - $mountPath = $this->document->getMountPath(); - if ($this->document->isPrivate()) { - throw new \InvalidArgumentException('Cannot get URL from a private document'); + throw new PrivateDocumentException('Cannot get URL from a private document'); } + $mountPath = $this->document->getMountPath(); + if (null !== $mountPath && ($this->options['noProcess'] === true || !$this->document->isProcessable())) { $publicUrl = $this->documentsStorage->publicUrl($mountPath); if ($absolute && \str_starts_with($publicUrl, '/')) {