Skip to content

Commit

Permalink
Merge branch hotfix/v2.2.12
Browse files Browse the repository at this point in the history
  • Loading branch information
roadiz-ci committed Mar 8, 2024
1 parent 135360d commit e93cb96
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 31 deletions.
9 changes: 9 additions & 0 deletions src/Exceptions/PrivateDocumentException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

declare(strict_types=1);

namespace RZ\Roadiz\Documents\Exceptions;

final class PrivateDocumentException extends \InvalidArgumentException
{
}
7 changes: 6 additions & 1 deletion src/Renderer/AbstractImageRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,12 @@ protected function parseSrcSetInner(
): string {
$output = [];
foreach ($srcSetArray as $set) {
if (isset($set['format']) && isset($set['rule']) && !empty($document->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);
Expand Down
2 changes: 1 addition & 1 deletion src/Renderer/VideoRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
36 changes: 7 additions & 29 deletions src/UrlGenerators/AbstractDocumentUrlGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}

/**
Expand Down Expand Up @@ -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, '/')) {
Expand Down

0 comments on commit e93cb96

Please sign in to comment.