Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
17 changes: 11 additions & 6 deletions src/bundle/DataCollector/TwigDataCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@

class TwigDataCollector extends BaseCollector
{
private TemplatePathRegistryInterface $templatePathRegistry;

public function __construct(Profile $profile, Environment $environment, TemplatePathRegistryInterface $templatePathRegistry)
{
public function __construct(
Profile $profile,
Environment $environment,
private TemplatePathRegistryInterface $templatePathRegistry
) {
parent::__construct($profile, $environment);
$this->templatePathRegistry = $templatePathRegistry;
}

private function getTemplatePathRegistry()
private function getTemplatePathRegistry(): TemplatePathRegistryInterface
{
if (!isset($this->templatePathRegistry)) {
$this->templatePathRegistry = unserialize($this->data['template_path_registry']);
Expand All @@ -31,12 +31,17 @@ private function getTemplatePathRegistry()
return $this->templatePathRegistry;
}

#[\Override]
public function lateCollect(): void
{
parent::lateCollect();
$this->data['template_path_registry'] = serialize($this->templatePathRegistry);
}

/**
* @return array<string, int>
*/
#[\Override]
public function getTemplates(): array
{
$registry = $this->getTemplatePathRegistry();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ public function process(ContainerBuilder $container): void
$container->setAlias('ibexadesign.asset_path_resolver', new Alias(ProvisionedPathResolver::class));
}

/**
* @param array<string, list<string>> $designPathMap
*
* @return array<string, array<string, string>>
*/
private function preResolveAssetsPaths(AssetPathProvisionerInterface $provisioner, array $designPathMap): array
{
$resolvedPathsByDesign = [];
Expand Down
4 changes: 4 additions & 0 deletions src/bundle/DependencyInjection/DesignConfigParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@

class DesignConfigParser implements ParserInterface
{
/**
* @param array<string, mixed> $scopeSettings
* @param string $currentScope
*/
public function mapConfig(array &$scopeSettings, $currentScope, ContextualizerInterface $contextualizer): void
{
if (isset($scopeSettings['design'])) {
Expand Down
8 changes: 4 additions & 4 deletions src/bundle/DependencyInjection/IbexaDesignEngineExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

namespace Ibexa\Bundle\DesignEngine\DependencyInjection;

use Ibexa\Bundle\Core\DependencyInjection\Configuration\SiteAccessAware\ConfigurationProcessor;
use Symfony\Component\Config\Definition\ConfigurationInterface;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
Expand All @@ -18,11 +17,13 @@ class IbexaDesignEngineExtension extends Extension
{
public const string EXTENSION_NAME = 'ibexa_design_engine';

#[\Override]
public function getAlias(): string
{
return self::EXTENSION_NAME;
}

#[\Override]
public function getConfiguration(array $config, ContainerBuilder $container): ?ConfigurationInterface
{
return new Configuration();
Expand All @@ -40,12 +41,11 @@ public function load(array $configs, ContainerBuilder $container): void
$configuration = $this->getConfiguration($configs, $container);
assert(null !== $configuration);
$config = $this->processConfiguration($configuration, $configs);
$processor = new ConfigurationProcessor($container, 'ezdesign');

$this->configureDesigns($config, $processor, $container);
$this->configureDesigns($config, $container);
}

private function configureDesigns(array $config, ConfigurationProcessor $processor, ContainerBuilder $container): void
private function configureDesigns(array $config, ContainerBuilder $container): void
{
// Always add "standard" design to the list (defaults to application level & override paths only)
$config['design_list'] += ['standard' => []];
Expand Down
1 change: 1 addition & 0 deletions src/bundle/IbexaDesignEngineBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public function build(ContainerBuilder $container): void
$container->addCompilerPass(new AssetPathResolutionPass(), PassConfig::TYPE_OPTIMIZE);
}

#[\Override]
public function getContainerExtension(): ?ExtensionInterface
{
if (!isset($this->extension)) {
Expand Down
20 changes: 8 additions & 12 deletions src/lib/Asset/AssetPathResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,14 @@

class AssetPathResolver implements AssetPathResolverInterface
{
/** @var array<string, string> */
private array $designPaths;

private string $webRootDir;

private ?LoggerInterface $logger;

public function __construct(array $designPaths, string $webRootDir, LoggerInterface $logger = null)
{
$this->designPaths = $designPaths;
$this->webRootDir = $webRootDir;
$this->logger = $logger;
/**
* @param array<string, array<string, string>> $designPaths
*/
public function __construct(
private readonly array $designPaths,
private readonly string $webRootDir,
private readonly ?LoggerInterface $logger = null
) {
}

public function resolveAssetPath(string $path, string $design): string
Expand Down
20 changes: 6 additions & 14 deletions src/lib/Asset/ProvisionedPathResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,18 @@
class ProvisionedPathResolver implements AssetPathResolverInterface, AssetPathProvisionerInterface
{
/**
* @var array<string, array<string, string>>
* @param array<string, array<string, string>> $resolvedPaths
*/
private array $resolvedPaths;

private AssetPathResolverInterface $innerResolver;

private string $webRootDir;

public function __construct(array $resolvedPaths, AssetPathResolverInterface $innerResolver, string $webRootDir)
{
$this->resolvedPaths = $resolvedPaths;
$this->innerResolver = $innerResolver;
$this->webRootDir = $webRootDir;
public function __construct(
private array $resolvedPaths,
private readonly AssetPathResolverInterface $innerResolver,
private readonly string $webRootDir
) {
}

/**
* Looks for $path within pre-resolved paths for provided design.
* If it cannot be found, fallbacks to original resolver.
*
* {@inheritdoc}
*/
public function resolveAssetPath(string $path, string $design): string
{
Expand Down
12 changes: 4 additions & 8 deletions src/lib/Asset/ThemePackage.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,10 @@ class ThemePackage implements PackageInterface, DesignAwareInterface
{
use DesignAwareTrait;

private AssetPathResolverInterface $pathResolver;

private PackageInterface $innerPackage;

public function __construct(AssetPathResolverInterface $pathResolver, PackageInterface $innerPackage)
{
$this->pathResolver = $pathResolver;
$this->innerPackage = $innerPackage;
public function __construct(
private AssetPathResolverInterface $pathResolver,
private PackageInterface $innerPackage
) {
}

public function getUrl(string $path): string
Expand Down
16 changes: 10 additions & 6 deletions src/lib/Templating/TemplatePathRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@ class TemplatePathRegistry implements TemplatePathRegistryInterface, Serializabl
/** @var array<string, string> */
private array $pathMap = [];

private string $kernelRootDir;

public function __construct(string $kernelRootDir)
{
$this->kernelRootDir = $kernelRootDir;
public function __construct(
private string $kernelRootDir
) {
}

public function mapTemplatePath(string $templateName, string $path): void
Expand All @@ -41,16 +39,22 @@ public function serialize(): ?string
return serialize([$this->pathMap, $this->kernelRootDir]);
}

public function unserialize($serialized): void
public function unserialize(string $serialized): void
{
[$this->pathMap, $this->kernelRootDir] = unserialize($serialized);
}

/**
* @return array<array<string, string>, string>
*/
public function __serialize(): array
{
return [$this->pathMap, $this->kernelRootDir];
}

/**
* @param array<string, mixed> $data
*/
public function __unserialize(array $data): void
{
[$this->pathMap, $this->kernelRootDir] = $data;
Expand Down
21 changes: 3 additions & 18 deletions src/lib/Templating/Twig/TwigThemeLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,11 @@
*/
class TwigThemeLoader implements LoaderInterface
{
/**
* @var \Ibexa\DesignEngine\Templating\TemplateNameResolverInterface
*/
private TemplateNameResolverInterface $nameResolver;

/**
* @var \Ibexa\DesignEngine\Templating\TemplatePathRegistryInterface
*/
private TemplatePathRegistryInterface $pathRegistry;

private FilesystemLoader $innerFilesystemLoader;

public function __construct(
TemplateNameResolverInterface $templateNameResolver,
TemplatePathRegistryInterface $templatePathRegistry,
FilesystemLoader $innerFilesystemLoader
private readonly TemplateNameResolverInterface $nameResolver,
private readonly TemplatePathRegistryInterface $pathRegistry,
private readonly FilesystemLoader $innerFilesystemLoader
) {
$this->innerFilesystemLoader = $innerFilesystemLoader;
$this->nameResolver = $templateNameResolver;
$this->pathRegistry = $templatePathRegistry;
}

public function exists(string $name): bool
Expand Down
11 changes: 11 additions & 0 deletions tests/lib/Asset/AssetPathResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ public function testResolveInvalidDesign(): void
self::assertSame($assetPath, $resolver->resolveAssetPath($assetPath, 'foo'));
}

/**
* @return list<array{
* 0: array{foo: list<string>},
* 1: list<string>,
* 2: string,
* 3: string
* }>
*/
public function resolveAssetPathProvider(): array
{
return [
Expand Down Expand Up @@ -106,6 +114,9 @@ public function resolveAssetPathProvider(): array

/**
* @dataProvider resolveAssetPathProvider
*
* @param array{foo: array<string>} $designPaths
* @param list<string> $existingPaths
*/
public function testResolveAssetPath(array $designPaths, array $existingPaths, string $path, string $resolvedPath): void
{
Expand Down
6 changes: 2 additions & 4 deletions tests/lib/Asset/ProvisionedPathResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,15 @@
use Ibexa\DesignEngine\Asset\AssetPathResolverInterface;
use Ibexa\DesignEngine\Asset\ProvisionedPathResolver;
use org\bovigo\vfs\vfsStream;
use org\bovigo\vfs\vfsStreamDirectory;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

class ProvisionedPathResolverTest extends TestCase
{
private AssetPathResolverInterface&MockObject $innerResolver;

/**
* @var \org\bovigo\vfs\vfsStreamDirectory
*/
private $webrootDir;
private vfsStreamDirectory $webrootDir;

protected function setUp(): void
{
Expand Down
14 changes: 14 additions & 0 deletions tests/lib/Templating/ThemeTemplateNameResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ protected function setUp(): void
$this->configResolver = $this->createMock(ConfigResolverInterface::class);
}

/**
* @return list<array{
* 0: ?string,
* 1: string,
* 2: string
* }>
*/
public function templateNameProvider(): array
{
return [
Expand All @@ -45,6 +52,13 @@ public function testResolveTemplateName(?string $currentDesign, string $template
self::assertSame($expectedTemplateName, $resolver->resolveTemplateName($templateName));
}

/**
* @return list<array{
* 0: ?string,
* 1: string,
* 2: bool
* }>
*/
public function isTemplateDesignNamespacedProvider(): array
{
return [
Expand Down
Loading