Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
16bc04e
Defined strict types for IO contracts
alongosz Jul 8, 2025
9ed4b40
Defined template type for IO HandlerRegistry
alongosz Jul 8, 2025
e2fffbb
Fixed type hints for IOBinarydataHandler implementations
alongosz Jul 8, 2025
04d4062
Fixed type hints for IOMetadataHandler implementations
alongosz Jul 8, 2025
81e7128
Added missing type hints to IO UrlDecorator
alongosz Jul 8, 2025
0a2bfe2
Aligned NotFoundException `$previous` arg type with `\Exception` sign…
alongosz Jul 8, 2025
d06f1cf
Added missing type hints to IO\MimeTypeDetector\FileInfo
alongosz Jul 8, 2025
74d38cd
Fixed strict types in \Ibexa\Bundle\IO\Migration namespace
alongosz Jul 8, 2025
b41dd5d
Added missing type hints and improved code of Imagine VariationPurger
alongosz Jul 9, 2025
01ab1e3
Added missing type hints to IOServiceInterface and aligned related code
alongosz Jul 14, 2025
072d688
Added missing type hints to \Ibexa\Bundle\Core\Imagine\Filter\FilterC…
alongosz Jul 14, 2025
946ac5c
Added missing type hints to \Ibexa\Core\IO\FilePathNormalizer\Flysystem
alongosz Jul 14, 2025
578d353
Fixed strict types of MigrateFilesCommand and improved its code
alongosz Jul 15, 2025
77d86d6
[DI] Added missing type hints to IO Bundle Configuration
alongosz Jul 15, 2025
e1ce13a
Fixed strict types and improved IO Handler Configuration Factories
alongosz Jul 15, 2025
b3b5197
Added missing type hints to StreamFileListener
alongosz Jul 15, 2025
b482e84
Declared strict types and fixed IbexaIOBundle
alongosz Jul 15, 2025
30cb1ad
Declared strict types for MigrationFileListerPass
alongosz Jul 15, 2025
5d230f7
Declared strict types for FileMigratorInterface
alongosz Jul 15, 2025
78100f8
Declared strict types for BinaryStreamResponse
alongosz Jul 15, 2025
66bc4a4
Simplified LegacyStorageImageFileRowReader::getRow implementation
alongosz Jul 21, 2025
1077810
[Tests] Dropped obsolete test replaced by strict types
alongosz Jul 8, 2025
c2e18eb
[Tests] Aligned tests with the changes
alongosz Jul 8, 2025
689887a
[Tests] Aligned VariationPurger unit tests with the changes
alongosz Jul 9, 2025
242e14c
[Tests] Aligned IO\Migration tests with the changes
alongosz Jul 9, 2025
00a2d20
[Tests] Aligned IOServiceTest with the changes
alongosz Jul 9, 2025
c117694
[Tests] Fixed & refactored IORepositoryResolverTest
alongosz Jul 14, 2025
fb8c4c8
[Tests] Fixed & refactored LegacyTest after BinaryFile strict types c…
alongosz Jul 14, 2025
914063e
[Tests] Fixed strict types of IOConfigurationPassTest
alongosz Jul 15, 2025
fbb3bfc
[Tests] Improved quality of LegacyDFSClusterTest
alongosz Jul 15, 2025
be319fb
[Tests] Fixed ConfigurationFactory test cases
alongosz Jul 15, 2025
ce33ab0
[Tests] Improved \Ibexa\Tests\Bundle\IO\DependencyInjection\Configura…
alongosz Jul 15, 2025
c824970
[PHPStan] Removed resolved issues from the baseline
alongosz Jul 9, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,284 changes: 0 additions & 1,284 deletions phpstan-baseline.neon

Large diffs are not rendered by default.

53 changes: 21 additions & 32 deletions src/bundle/Core/Imagine/Filter/FilterConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,17 @@

class FilterConfiguration extends BaseFilterConfiguration
{
/** @var \Ibexa\Contracts\Core\SiteAccess\ConfigResolverInterface */
private $configResolver;
private ConfigResolverInterface $configResolver;

/**
* @param \Ibexa\Contracts\Core\SiteAccess\ConfigResolverInterface $configResolver
*/
public function setConfigResolver(ConfigResolverInterface $configResolver)
public function setConfigResolver(ConfigResolverInterface $configResolver): void
{
$this->configResolver = $configResolver;
}

public function get($filter)
/**
* @return array<string, mixed>
*/
public function get($filter): array
{
$configuredVariations = $this->configResolver->getParameter('image_variations');
if (!array_key_exists($filter, $configuredVariations)) {
Expand All @@ -35,13 +34,16 @@ public function get($filter)
return [
'cache' => 'ibexa',
'data_loader' => 'ibexa',
'reference' => isset($configuredVariations[$filter]['reference']) ? $configuredVariations[$filter]['reference'] : null,
'reference' => $configuredVariations[$filter]['reference'] ?? null,
'filters' => $this->getVariationFilters($filter, $configuredVariations),
'post_processors' => $this->getVariationPostProcessors($filter, $configuredVariations),
] + $filterConfig;
}

public function all()
/**
* @return array<string, mixed>
*/
public function all(): array
{
return $this->configResolver->getParameter('image_variations') + parent::all();
}
Expand All @@ -52,26 +54,18 @@ public function all()
* Both variations configured in Ibexa (SiteAccess context) and LiipImagineBundle are used.
* Ibexa variations always have precedence.
*
* @param string $variationName
* @param array $configuredVariations Variations set in eZ.
* @param array<string, array{filters: array<mixed>}> $configuredVariations Variations set in eZ.
*
* @return array
* @return array<mixed>
*/
private function getVariationFilters($variationName, array $configuredVariations)
private function getVariationFilters(string $variationName, array $configuredVariations): array
{
if (!isset($configuredVariations[$variationName]['filters']) && !isset($this->filters[$variationName]['filters'])) {
return [];
}

// Check variations configured in Ibexa config first.
if (isset($configuredVariations[$variationName]['filters'])) {
$filters = $configuredVariations[$variationName]['filters'];
} else {
// Falback to variations configured in LiipImagineBundle.
$filters = $this->filters[$variationName]['filters'];
}

return $filters;
return $configuredVariations[$variationName]['filters'] ?? $this->filters[$variationName]['filters'];
}

/**
Expand All @@ -80,19 +74,14 @@ private function getVariationFilters($variationName, array $configuredVariations
* Both variations configured in Ibexa and LiipImagineBundle are used.
* Ibexa variations always have precedence.
*
* @param string $variationName
* @param array $configuredVariations Variations set in eZ.
* @param array<string, array{post_processor: array<mixed>}> $configuredVariations Variations set in Ibexa.
*
* @return array
* @return array<mixed>
*/
private function getVariationPostProcessors($variationName, array $configuredVariations)
private function getVariationPostProcessors(string $variationName, array $configuredVariations): array
{
if (isset($configuredVariations[$variationName]['post_processors'])) {
return $configuredVariations[$variationName]['post_processors'];
} elseif (isset($this->filters[$variationName]['post_processors'])) {
return $this->filters[$variationName]['post_processors'];
}

return [];
return $configuredVariations[$variationName]['post_processors']
?? $this->filters[$variationName]['post_processors']
?? [];
}
}
28 changes: 9 additions & 19 deletions src/bundle/Core/Imagine/VariationPurger/IOVariationPurger.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,34 @@
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace Ibexa\Bundle\Core\Imagine\VariationPurger;

use Ibexa\Bundle\Core\Imagine\Cache\AliasGeneratorDecorator;
use Ibexa\Contracts\Core\Variation\VariationPurger;
use Ibexa\Core\IO\IOServiceInterface;
use Ibexa\Core\Persistence\Cache\Identifier\CacheIdentifierGeneratorInterface;
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerAwareTrait;
use Symfony\Component\Cache\Adapter\TagAwareAdapterInterface;

/**
* Purges image variations using the IOService.
*
* Depends on aliases being stored in their own folder, with each alias folder mirroring the original files structure.
*/
class IOVariationPurger implements VariationPurger
class IOVariationPurger implements VariationPurger, LoggerAwareInterface
{
/** @var \Ibexa\Core\IO\IOServiceInterface */
private $io;
use LoggerAwareTrait;

/** @var \Symfony\Component\Cache\Adapter\TagAwareAdapterInterface */
private $cache;
private IOServiceInterface $io;

/** @var \Ibexa\Core\Persistence\Cache\Identifier\CacheIdentifierGeneratorInterface */
private $cacheIdentifierGenerator;
private TagAwareAdapterInterface $cache;

/** @var \Ibexa\Bundle\Core\Imagine\Cache\AliasGeneratorDecorator */
private $aliasGeneratorDecorator;
private CacheIdentifierGeneratorInterface $cacheIdentifierGenerator;

/** @var \Psr\Log\LoggerInterface */
private $logger;
private AliasGeneratorDecorator $aliasGeneratorDecorator;

public function __construct(
IOServiceInterface $io,
Expand All @@ -47,14 +45,6 @@ public function __construct(
$this->aliasGeneratorDecorator = $aliasGeneratorDecorator;
}

/**
* @param \Psr\Log\LoggerInterface $logger
*/
public function setLogger($logger)
{
$this->logger = $logger;
}

public function purge(array $aliasNames): void
{
$variationNameTag = $this->aliasGeneratorDecorator->getVariationNameTag();
Expand Down
3 changes: 3 additions & 0 deletions src/bundle/Core/Imagine/VariationPurger/ImageFileList.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace Ibexa\Bundle\Core\Imagine\VariationPurger;

Expand All @@ -12,6 +13,8 @@

/**
* Iterates over BinaryFile id entries for original images.
*
* @extends \Iterator<array-key, string>
*/
interface ImageFileList extends Countable, Iterator
{
Expand Down
11 changes: 5 additions & 6 deletions src/bundle/Core/Imagine/VariationPurger/ImageFileRowReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace Ibexa\Bundle\Core\Imagine\VariationPurger;

Expand All @@ -17,19 +18,17 @@ interface ImageFileRowReader
*
* Can for instance be used to create and execute a database query.
*/
public function init();
public function init(): void;

/**
* Returns the next row from the data source.
*
* @return mixed|null The row's value, or null if none.
*/
public function getRow();
public function getRow(): ?string;

/**
* Returns the total row count.
*
* @return int
* @phpstan-return int<0, max>
*/
public function getCount();
public function getCount(): int;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,31 @@
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace Ibexa\Bundle\Core\Imagine\VariationPurger;

use Ibexa\Contracts\Core\Variation\VariationPathGenerator;
use Ibexa\Contracts\Core\Variation\VariationPurger;
use Ibexa\Core\IO\IOServiceInterface;
use Iterator;
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerAwareTrait;

/**
* Purges image aliases based on image files referenced by the Image FieldType.
*
* It uses an ImageFileList iterator that lists original images, and the variationPathGenerator + IOService to remove
* aliases if they exist.
*/
class ImageFileVariationPurger implements VariationPurger
class ImageFileVariationPurger implements VariationPurger, LoggerAwareInterface
{
/** @var ImageFileList */
private $imageFileList;
use LoggerAwareTrait;

/** @var \Ibexa\Core\IO\IOServiceInterface */
private $ioService;

/** @var \Ibexa\Contracts\Core\Variation\VariationPathGenerator */
private $variationPathGenerator;

/** @var \Psr\Log\LoggerInterface */
private $logger;

public function __construct(Iterator $imageFileList, IOServiceInterface $ioService, VariationPathGenerator $variationPathGenerator)
{
$this->imageFileList = $imageFileList;
$this->ioService = $ioService;
$this->variationPathGenerator = $variationPathGenerator;
public function __construct(
private readonly ImageFileList $imageFileList,
private readonly IOServiceInterface $ioService,
private readonly VariationPathGenerator $variationPathGenerator
) {
}

public function purge(array $aliasNames): void
Expand All @@ -56,12 +48,4 @@ public function purge(array $aliasNames): void
}
}
}

/**
* @param \Psr\Log\LoggerInterface $logger
*/
public function setLogger($logger)
{
$this->logger = $logger;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace Ibexa\Bundle\Core\Imagine\VariationPurger;

Expand All @@ -19,43 +20,25 @@ class LegacyStorageImageFileList implements ImageFileList
{
/**
* Last fetched item.
*
* @var mixed
*/
private $item;
private ?string $item;

/**
* Iteration cursor on $statement.
*
* @var int
*/
private $cursor;

/**
* Used to get ezimagefile rows.
*
* @var \Ibexa\Bundle\Core\Imagine\VariationPurger\ImageFileRowReader
*/
private $rowReader;

/** @var \Ibexa\Core\IO\IOConfigProvider */
private $ioConfigResolver;

/** @var \Ibexa\Contracts\Core\SiteAccess\ConfigResolverInterface */
private $configResolver;
private int $cursor;

public function __construct(
ImageFileRowReader $rowReader,
IOConfigProvider $ioConfigResolver,
ConfigResolverInterface $configResolver
private readonly ImageFileRowReader $rowReader,
private readonly IOConfigProvider $ioConfigResolver,
private readonly ConfigResolverInterface $configResolver
) {
$this->ioConfigResolver = $ioConfigResolver;
$this->rowReader = $rowReader;
$this->configResolver = $configResolver;
}

#[\ReturnTypeWillChange]
public function current(): mixed
public function current(): ?string
{
return $this->item;
}
Expand Down Expand Up @@ -96,9 +79,13 @@ private function fetchRow(): void
$storageDir = $this->ioConfigResolver->getLegacyUrlPrefix();
$prefix = $storageDir . '/' . $this->configResolver->getParameter('image.published_images_dir');
++$this->cursor;
$imageId = $this->rowReader->getRow();
$this->item = $this->rowReader->getRow();
if ($this->item === null) {
return;
}

if (0 === strncmp((string)$imageId, $prefix, strlen($prefix))) {
$imageId = $this->item;
if (0 === strncmp($imageId, $prefix, strlen($prefix))) {
$imageId = ltrim(substr($imageId, strlen($prefix)), '/');
}

Expand Down
Loading
Loading