Skip to content

Commit

Permalink
TASK: Add all important arguments to constructor in new image sources
Browse files Browse the repository at this point in the history
  • Loading branch information
mficzel committed Apr 11, 2022
1 parent 1e6d67a commit 8aac406
Show file tree
Hide file tree
Showing 17 changed files with 174 additions and 121 deletions.
6 changes: 6 additions & 0 deletions Classes/Domain/AbstractImageSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ abstract class AbstractImageSource implements ImageSourceInterface, ProtectedCon
*/
protected $alt;

public function __construct(?string $title = null, ?string $alt = null)
{
$this->title = $title;
$this->alt = $alt;
}

/**
* @deprecated
*/
Expand Down
25 changes: 6 additions & 19 deletions Classes/Domain/AssetImageSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,35 +46,22 @@ class AssetImageSource extends AbstractScalableImageSource
protected $request;

/**
* AssetImageSourceHelper constructor.
*
* @param ImageInterface $asset
* @param string|null $title
* @param string|null $alt
* @param bool $async
* @param ActionRequest|null $request
*/
public function __construct(ImageInterface $asset, bool $async = true, ?ActionRequest $request = null)
public function __construct(ImageInterface $asset, ?string $title = null, ?string $alt = null, bool $async = true, ?ActionRequest $request = null)
{
parent::__construct($title, $alt);
$this->asset = $asset;
$this->request = $request;
$this->async = $async;
$this->baseWidth = $this->asset->getWidth();
$this->baseHeight = $this->asset->getHeight();
}

/**
* @deprecated use constructor
*/
public function setAsync(bool $async): void
{
$this->async = $async;
}

/**
* @deprecated use constructor
*/
public function setRequest(ActionRequest $request): void
{
$this->request = $request;
}

/**
* Use the variant generated from the given variant preset in this image source.
*
Expand Down
50 changes: 9 additions & 41 deletions Classes/Domain/DummyImageSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,17 @@ class DummyImageSource extends AbstractScalableImageSource

/**
* @param string $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
*/
public function __construct(string $baseUri, ?int $baseWidth = null, ?int $baseHeight = null, ?string $backgroundColor = null, ?string $foregroundColor = null, ?string $text = null)
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)
{
parent::__construct($title, $alt);
$this->baseUri = $baseUri;
$this->baseWidth = $baseWidth ?? 600;
$this->baseHeight = $baseHeight ?? 400;
Expand All @@ -39,46 +47,6 @@ public function __construct(string $baseUri, ?int $baseWidth = null, ?int $baseH
$this->text = $text ?? '';
}

/**
* @deprecated use constructor
*/
public function setBaseWidth(int $baseWidth): void
{
$this->baseWidth = $baseWidth;
}

/**
* @deprecated use constructor
*/
public function setBaseHeight(int $baseHeight): void
{
$this->baseHeight = $baseHeight;
}

/**
* @deprecated use constructor
*/
public function setBackgroundColor(string $backgroundColor): void
{
$this->backgroundColor = $backgroundColor;
}

/**
* @deprecated use constructor
*/
public function setForegroundColor(string $foregroundColor): void
{
$this->foregroundColor = $foregroundColor;
}

/**
* @deprecated use constructor
*/
public function setText(string $text): void
{
$this->text = $text;
}

/**
* Use the variant generated from the given variant preset in this image source.
*
Expand Down
9 changes: 5 additions & 4 deletions Classes/Domain/ResourceImageSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,14 @@ class ResourceImageSource extends AbstractImageSource
protected $package;

/**
* ResourceImageSourceHelper constructor.
*
* @param string|null $package
* @param string $path
* @param string $path
* @param string|null $title
* @param string|null $alt
*/
public function __construct(?string $package, string $path)
public function __construct(?string $package, string $path, ?string $title = null, ?string $alt = null)
{
parent::__construct($title, $alt);
$this->package = $package;
$this->path = $path;
}
Expand Down
7 changes: 4 additions & 3 deletions Classes/Domain/UriImageSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@ class UriImageSource extends AbstractImageSource
protected $uri;

/**
* ResourceImageSourceHelper constructor.
*
* @param string $uri
* @param string|null $title
* @param string|null $alt
*/
public function __construct(string $uri)
public function __construct(string $uri, ?string $title = null, ?string $alt = null)
{
parent::__construct($title, $alt);
$this->uri = $uri;
}

Expand Down
14 changes: 0 additions & 14 deletions Classes/EelHelpers/AbstractImageSourceHelper.php

This file was deleted.

14 changes: 0 additions & 14 deletions Classes/EelHelpers/AbstractScalableImageSourceHelper.php

This file was deleted.

27 changes: 27 additions & 0 deletions Classes/EelHelpers/AssetImageSourceHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,38 @@

namespace Sitegeist\Kaleidoscope\EelHelpers;

use Neos\Flow\Mvc\ActionRequest;
use Neos\Media\Domain\Model\ImageInterface;
use Sitegeist\Kaleidoscope\Domain\AssetImageSource;

/**
* @deprecated use Sitegeist\Kaleidoscope\Domain\AssetImageSource;
*/
class AssetImageSourceHelper extends AssetImageSource
{
/**
* AssetImageSourceHelper constructor.
*
* @param ImageInterface $asset
*/
public function __construct(ImageInterface $asset)
{
parent::__construct($asset);
}

/**
* @param bool $async
*/
public function setAsync(bool $async): void
{
$this->async = $async;
}

/**
* @param ActionRequest $request
*/
public function setRequest(ActionRequest $request): void
{
$this->request = $request;
}
}
54 changes: 54 additions & 0 deletions Classes/EelHelpers/DummyImageSourceHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,58 @@
*/
class DummyImageSourceHelper extends DummyImageSource
{

/**
* @param string $baseUri
*/
public function __construct(string $baseUri)
{
parent::__construct(
$this->baseUri = $baseUri,
null,
null,
600,
400
);
}

/**
* @param int $baseWidth
*/
public function setBaseWidth(int $baseWidth): void
{
$this->baseWidth = $baseWidth;
}

/**
* @param int $baseHeight
*/
public function setBaseHeight(int $baseHeight): void
{
$this->baseHeight = $baseHeight;
}

/**
* @param string $backgroundColor
*/
public function setBackgroundColor(string $backgroundColor): void
{
$this->backgroundColor = $backgroundColor;
}

/**
* @param string $foregroundColor
*/
public function setForegroundColor(string $foregroundColor): void
{
$this->foregroundColor = $foregroundColor;
}

/**
* @param string $text
*/
public function setText($text): void
{
$this->text = $text;
}
}
2 changes: 1 addition & 1 deletion Classes/EelHelpers/ImageSourceHelperInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
/**
* @deprecated use Sitegeist\Kaleidoscope\Domain\ImageSourceInterface;
*/
interface ImageSourceHelperInterface extends ImageSourceInterface
interface ImageSourceHelperInterface
{
/** deprecated methods with variing mutability */

Expand Down
10 changes: 10 additions & 0 deletions Classes/EelHelpers/ResourceImageSourceHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,14 @@
*/
class ResourceImageSourceHelper extends ResourceImageSource
{
/**
* ResourceImageSourceHelper constructor.
*
* @param string|null $package
* @param string $path
*/
public function __construct(?string $package, string $path)
{
parent::__construct($package, $path);
}
}
21 changes: 21 additions & 0 deletions Classes/EelHelpers/UriImageSourceHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

namespace Sitegeist\Kaleidoscope\EelHelpers;

use Sitegeist\Kaleidoscope\Domain\UriImageSource;

class UriImageSourceHelper extends UriImageSource
{

/**
* ResourceImageSourceHelper constructor.
*
* @param string $uri
*/
public function __construct(string $uri)
{
parent::__construct($uri);
}
}
24 changes: 11 additions & 13 deletions Classes/FusionObjects/AssetImageSourceImplementation.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ public function getAsset(): ?ImageInterface
}

/**
* @return bool|null
* @return bool
*/
public function getAsync(): ?bool
public function getAsync(): bool
{
return $this->fusionValue('async');
return (bool)$this->fusionValue('async');
}

/**
Expand All @@ -58,23 +58,21 @@ public function createHelper(): ?ImageSourceInterface
if (in_array($asset->getResource()->getMediaType(), $this->nonScalableMediaTypes, true)) {
$uri = $this->resourceManager->getPublicPersistentResourceUri($asset->getResource());
if (is_string($uri)) {
$helper = new UriImageSource($uri);
if ($title = $this->getTitle()) {
$helper = $helper->withTitle($title);
}
if ($alt = $this->getAlt()) {
$helper = $helper->withAlt($alt);
}

return $helper;
return new UriImageSource(
$uri,
$this->getTitle(),
$this->getAlt()
);
} else {
return null;
}
}

$helper = new AssetImageSource(
$asset,
(bool) $this->getAsync(),
$this->getTitle(),
$this->getAlt(),
$this->getAsync(),
$this->getRuntime()->getControllerContext()->getRequest()
);

Expand Down
10 changes: 4 additions & 6 deletions Classes/FusionObjects/DummyImageSourceImplementation.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,15 @@ public function createHelper(): ?ImageSourceInterface
$uriBuilder = $this->runtime->getControllerContext()->getUriBuilder()->reset()->setCreateAbsoluteUri(true);
$baseUri = $uriBuilder->uriFor('image', [], 'DummyImage', 'Sitegeist.Kaleidoscope');

$helper = (new DummyImageSource(
return new DummyImageSource(
$baseUri,
$this->getTitle(),
$this->getAlt(),
$this->getBaseWidth(),
$this->getBaseHeight(),
$this->getBackgroundColor(),
$this->getForegroundColor(),
$this->getText()
))
->withTitle($this->getTitle())
->withAlt($this->getAlt());

return $helper;
);
}
}
Loading

0 comments on commit 8aac406

Please sign in to comment.