Skip to content

Commit

Permalink
Correctly implement the ImageFactoryInterface (see #6939)
Browse files Browse the repository at this point in the history
Description
-----------

We updated the method signatures of the `ImageFactoryInterface` in Contao 5 but it seems we forgot to update the `ImageFactory` class accordingly.

Commits
-------

6e7b64a Correctly implement the `ImageFactoryInterface`
bdd2527 Remove an unnecessary type cast
  • Loading branch information
leofeyer committed Feb 27, 2024
1 parent 3607093 commit 0eac53c
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions core-bundle/src/Image/ImageFactory.php
Expand Up @@ -64,16 +64,11 @@ public function setPreserveMetadataFields(array $preserveMetadataFields): void
$this->preserveMetadataFields = $preserveMetadataFields;
}

public function create($path, ResizeConfiguration|array|int|string|null $size = null, $options = null): ImageInterface
public function create(ImageInterface|string $path, ResizeConfiguration|array|int|string|null $size = null, ResizeOptions|string|null $options = null): ImageInterface
{
if (null !== $options && !\is_string($options) && !$options instanceof ResizeOptions) {
throw new \InvalidArgumentException('Options must be of type null, string or '.ResizeOptions::class);
}

if ($path instanceof ImageInterface) {
$image = $path;
} else {
$path = (string) $path;
$fileExtension = Path::getExtension($path, true);

if (\in_array($fileExtension, ['svg', 'svgz'], true)) {
Expand Down Expand Up @@ -113,7 +108,7 @@ public function create($path, ResizeConfiguration|array|int|string|null $size =
[$resizeConfig, $importantPart, $options] = $this->createConfig($size, $image);
}

if (!\is_object($path) || !$path instanceof ImageInterface) {
if (!$path instanceof ImageInterface) {
if (null === $importantPart) {
try {
$importantPart = $this->createImportantPart($image);
Expand Down Expand Up @@ -150,7 +145,7 @@ public function create($path, ResizeConfiguration|array|int|string|null $size =
return $this->resizer->resize($image, $resizeConfig, $options);
}

public function getImportantPartFromLegacyMode(ImageInterface $image, $mode): ImportantPart
public function getImportantPartFromLegacyMode(ImageInterface $image, string $mode): ImportantPart
{
if (1 !== substr_count($mode, '_')) {
throw new \InvalidArgumentException(sprintf('"%s" is not a legacy resize mode', $mode));
Expand Down

0 comments on commit 0eac53c

Please sign in to comment.