Skip to content

Commit

Permalink
Merge branch 'main' into bugfix/#33
Browse files Browse the repository at this point in the history
* main:
  TASK: Make BaseUri argument nullable in DummyImageSource constructor

# Conflicts:
#	Classes/Domain/DummyImageSource.php
  • Loading branch information
mficzel committed Sep 27, 2024
2 parents 60476f4 + 0146228 commit 742fab2
Showing 1 changed file with 48 additions and 4 deletions.
52 changes: 48 additions & 4 deletions Classes/Domain/DummyImageSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
namespace Sitegeist\Kaleidoscope\Domain;

use Neos\Flow\Annotations as Flow;
use Neos\Flow\Http\ServerRequestAttributes;
use Neos\Flow\Mvc\ActionRequestFactory;
use Neos\Flow\Mvc\Routing\Dto\RouteParameters;
use Neos\Flow\Mvc\Routing\UriBuilder;
use Psr\Http\Message\ServerRequestFactoryInterface;
use Psr\Http\Message\UriFactoryInterface;

class DummyImageSource extends AbstractScalableImageSource
{
Expand All @@ -15,6 +21,24 @@ class DummyImageSource extends AbstractScalableImageSource
*/
protected $dummyImageGenerator;

/**
* @var UriFactoryInterface
* @Flow\Inject
*/
protected $uriFactory;

/**
* @var ServerRequestFactoryInterface
* @Flow\Inject
*/
protected $serverRequestFactory;

/**
* @var ActionRequestFactory
* @Flow\Inject
*/
protected $actionRequestFactory;

/**
* @var string
*/
Expand All @@ -31,7 +55,7 @@ class DummyImageSource extends AbstractScalableImageSource
protected $text;

/**
* @var string
* @var string|null
*/
protected $baseUri;

Expand All @@ -41,16 +65,17 @@ class DummyImageSource extends AbstractScalableImageSource
private $allowUpScaling;

/**
* @param string $baseUri
* @param string|null $baseUri
* @param string|null $title
* @param string|null $alt
* @param int|null $baseWidth
* @param int|null $baseHeight
* @param string|null $backgroundColor
* @param string|null $foregroundColor
* @param string|null $text
* @param bool $allowUpScaling
*/
public function __construct(string $baseUri, ?string $title = null, ?string $alt = null, ?int $baseWidth = null, ?int $baseHeight = null, ?string $backgroundColor = null, ?string $foregroundColor = null, ?string $text = null, bool $allowUpScaling = true)
public function __construct(?string $baseUri, ?string $title = null, ?string $alt = null, ?int $baseWidth = null, ?int $baseHeight = null, ?string $backgroundColor = null, ?string $foregroundColor = null, ?string $text = null, $allowUpScaling = false)
{
parent::__construct($title, $alt);
$this->baseUri = $baseUri;
Expand Down Expand Up @@ -94,6 +119,25 @@ public function withVariantPreset(string $presetIdentifier, string $presetVarian
*/
public function src(): string
{
if (is_string($this->baseUri)) {
$baseUri = $this->baseUri;
} else {
$uri = $this->uriFactory->createUri('http://localhost');

$httpRequest = $this->serverRequestFactory->createServerRequest('GET', $uri)
->withAttribute(
ServerRequestAttributes::ROUTING_PARAMETERS,
RouteParameters::createEmpty()->withParameter('requestUriHost', $uri->getHost())
);

$uriBuilder = new UriBuilder();
$uriBuilder->setRequest($this->actionRequestFactory->createActionRequest($httpRequest));
$uriBuilder->setFormat('html');
$uriBuilder->setCreateAbsoluteUri(false);

$baseUri = $uriBuilder->uriFor('image', [], 'DummyImage', 'Sitegeist.Kaleidoscope');
}

$arguments = [
'w' => $this->getCurrentWidth(),
'h' => $this->getCurrentHeight(),
Expand All @@ -115,7 +159,7 @@ public function src(): string
$arguments['f'] = $this->targetFormat;
}

return $this->baseUri . '?' . http_build_query($arguments);
return $baseUri . '?' . http_build_query($arguments);
}

public function dataSrc(): string
Expand Down

0 comments on commit 742fab2

Please sign in to comment.