Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IBX-8470: Upgraded codebase to Symfony 6 #31

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
20 changes: 10 additions & 10 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,20 @@
],
"require": {
"php": " >=8.3",
"ibexa/core": "~5.0.x-dev",
"symfony/asset": "^5.0",
"symfony/config": "^5.0",
"symfony/dependency-injection": "^5.0",
"symfony/filesystem": "^5.0",
"symfony/finder": "^5.0",
"symfony/http-foundation": "^5.0",
"symfony/http-kernel": "^5.0",
"symfony/templating": "^5.0",
"ibexa/core": "dev-ibx-8470-symfony-6 as 5.0.x-dev",
"symfony/asset": "^6.4",
"symfony/config": "^6.4",
"symfony/dependency-injection": "^6.4",
"symfony/filesystem": "^6.4",
"symfony/finder": "^6.4",
"symfony/http-foundation": "^6.4",
"symfony/http-kernel": "^6.4",
"symfony/templating": "^6.4",
"twig/twig": "^3.0"
},
"require-dev": {
"ibexa/code-style": "~2.0.0",
"ibexa/doctrine-schema": "~5.0.x-dev",
"ibexa/doctrine-schema": "dev-ibx-8470-symfony-6 as 5.0.x-dev",
"mikey179/vfsstream": "^1.6",
"phpunit/phpunit": "^9.6"
},
Expand Down
51 changes: 4 additions & 47 deletions src/bundle/DataCollector/TwigDataCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,12 @@

use Ibexa\DesignEngine\Templating\TemplatePathRegistryInterface;
use Symfony\Bridge\Twig\DataCollector\TwigDataCollector as BaseCollector;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\DataCollector\LateDataCollectorInterface;
use Twig\Environment;
use Twig\Profiler\Profile;

class TwigDataCollector extends BaseCollector implements LateDataCollectorInterface
class TwigDataCollector extends BaseCollector

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
class TwigDataCollector extends BaseCollector
final class TwigDataCollector extends BaseCollector

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

public function __construct(Profile $profile, Environment $environment, TemplatePathRegistryInterface $templatePathRegistry)
{
Expand All @@ -37,28 +31,13 @@ private function getTemplatePathRegistry()
return $this->templatePathRegistry;
}

public function collect(Request $request, Response $response, \Throwable $exception = null)
{
parent::collect($request, $response, $exception);
}

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

public function getTime()
{
return parent::getTime();
}

public function getTemplateCount()
{
return parent::getTemplateCount();
}

public function getTemplates()
public function getTemplates(): array
{
$registry = $this->getTemplatePathRegistry();
$templates = [];
Expand All @@ -68,26 +47,4 @@ public function getTemplates()

return $templates;
}

public function getBlockCount()
{
return parent::getBlockCount();
}

public function getMacroCount()
{
return parent::getMacroCount();
}

public function getHtmlCallGraph()
{
return parent::getHtmlCallGraph();
}

public function getProfile()
{
$profile = parent::getProfile();

return $profile;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@
*/
class AssetPathResolutionPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container)
/**
* @throws \Exception
*/
public function process(ContainerBuilder $container): void
{
if ($container->getParameter('ibexa.design.assets.resolution.disabled')) {
return;
Expand All @@ -39,7 +42,7 @@ public function process(ContainerBuilder $container)
$container->setAlias('ibexadesign.asset_path_resolver', new Alias(ProvisionedPathResolver::class));
}

private function preResolveAssetsPaths(AssetPathProvisionerInterface $provisioner, array $designPathMap)
private function preResolveAssetsPaths(AssetPathProvisionerInterface $provisioner, array $designPathMap): array
{
$resolvedPathsByDesign = [];
foreach ($designPathMap as $design => $paths) {
Expand Down
4 changes: 2 additions & 2 deletions src/bundle/DependencyInjection/Compiler/AssetThemePass.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

class AssetThemePass implements CompilerPassInterface
{
public function process(ContainerBuilder $container)
public function process(ContainerBuilder $container): void
{
if (!($container->hasParameter('kernel.bundles') && $container->hasParameter('webroot_dir') && $container->hasDefinition('assets.packages'))) {
return;
Expand Down Expand Up @@ -50,7 +50,7 @@ public function process(ContainerBuilder $container)
if (is_dir($appLevelThemeDir)) {
foreach ((new Finder())->directories()->in($appLevelThemeDir)->depth('== 0') as $directoryInfo) {
$theme = $directoryInfo->getBasename();
$themePaths = isset($themesPathMap[$theme]) ? $themesPathMap[$theme] : [];
$themePaths = $themesPathMap[$theme] ?? [];
// Application level paths are always top priority.
array_unshift($themePaths, 'assets/themes/' . $theme);
$themesPathMap[$theme] = $themePaths;
Expand Down
5 changes: 4 additions & 1 deletion src/bundle/DependencyInjection/Compiler/TwigThemePass.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@
*/
class TwigThemePass implements CompilerPassInterface
{
public function process(ContainerBuilder $container)
/**
* @throws \ReflectionException
*/
public function process(ContainerBuilder $container): void
{
if (!($container->hasParameter('kernel.bundles') && $container->hasDefinition(TwigThemeLoader::class))) {
return;
Expand Down
10 changes: 6 additions & 4 deletions src/bundle/DependencyInjection/DesignConfigParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,24 @@

class DesignConfigParser implements ParserInterface
{
public function mapConfig(array &$scopeSettings, $currentScope, ContextualizerInterface $contextualizer)
public function mapConfig(array &$scopeSettings, $currentScope, ContextualizerInterface $contextualizer): void
{
if (isset($scopeSettings['design'])) {
$contextualizer->setContextualParameter('design', $currentScope, $scopeSettings['design']);
}
}

public function preMap(array $config, ContextualizerInterface $contextualizer)
public function preMap(array $config, ContextualizerInterface $contextualizer): void
{
// Nothing to map
}

public function postMap(array $config, ContextualizerInterface $contextualizer)
public function postMap(array $config, ContextualizerInterface $contextualizer): void
{
// Nothing to map
}

public function addSemanticConfig(NodeBuilder $nodeBuilder)
public function addSemanticConfig(NodeBuilder $nodeBuilder): void
{
$nodeBuilder
->scalarNode('design')
Expand Down
10 changes: 7 additions & 3 deletions src/bundle/DependencyInjection/IbexaDesignEngineExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

class IbexaDesignEngineExtension extends Extension
{
public const EXTENSION_NAME = 'ibexa_design_engine';
public const string EXTENSION_NAME = 'ibexa_design_engine';

public function getAlias(): string
{
Expand All @@ -28,20 +28,24 @@ public function getConfiguration(array $config, ContainerBuilder $container): ?C
return new Configuration();
}

public function load(array $configs, ContainerBuilder $container)
/**
* @throws \Exception
*/
public function load(array $configs, ContainerBuilder $container): void
{
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$loader->load('services.yaml');
$loader->load('default_settings.yaml');

$configuration = $this->getConfiguration($configs, $container);
assert(null !== $configuration);
$config = $this->processConfiguration($configuration, $configs);
$processor = new ConfigurationProcessor($container, 'ezdesign');

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

private function configureDesigns(array $config, ConfigurationProcessor $processor, ContainerBuilder $container)
private function configureDesigns(array $config, ConfigurationProcessor $processor, ContainerBuilder $container): void
{
// Always add "standard" design to the list (defaults to application level & override paths only)
$config['design_list'] += ['standard' => []];
Expand Down
3 changes: 2 additions & 1 deletion src/bundle/IbexaDesignEngineBundle.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\DesignEngine;

Expand All @@ -19,7 +20,7 @@

class IbexaDesignEngineBundle extends Bundle
{
public function build(ContainerBuilder $container)
public function build(ContainerBuilder $container): void
{
parent::build($container);

Expand Down
3 changes: 2 additions & 1 deletion src/contracts/DesignAwareInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
* @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\Contracts\DesignEngine;

interface DesignAwareInterface
{
public const DESIGN_NAMESPACE = 'ibexadesign';
public const string DESIGN_NAMESPACE = 'ibexadesign';

public function getCurrentDesign(): ?string;
}
8 changes: 4 additions & 4 deletions src/lib/Asset/AssetPathProvisionerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ interface AssetPathProvisionerInterface
{
/**
* Pre-resolves assets paths for a given design from themes paths, where are stored physical assets.
* Returns an map with asset logical path as key and its resolved path (relative to webroot dir) as value.
* Returns a map with asset logical path as key and its resolved path (relative to webroot dir) as value.
* Example => ['images/foo.png' => 'asset/themes/some_theme/images/foo.png'].
*
* @param string $design
* @param string[] $assetsPaths
*
* @return array
* @return array<string, string>
*/
public function provisionResolvedPaths(array $assetsPaths, $design);
public function provisionResolvedPaths(array $assetsPaths, string $design): array;
}
32 changes: 11 additions & 21 deletions src/lib/Asset/AssetPathResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,12 @@

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

/**
* @var string
*/
private $webRootDir;
private string $webRootDir;

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

public function __construct(array $designPaths, $webRootDir, LoggerInterface $logger = null)
{
Expand All @@ -34,7 +26,7 @@ public function __construct(array $designPaths, $webRootDir, LoggerInterface $lo
$this->logger = $logger;
}

public function resolveAssetPath($path, $design)
public function resolveAssetPath(string $path, string $design): string
{
if (!isset($this->designPaths[$design])) {
throw new InvalidDesignException("Invalid design '$design'");
Expand All @@ -46,14 +38,12 @@ public function resolveAssetPath($path, $design)
}
}

if ($this->logger) {
$this->logger->warning(
"Asset '$path' cannot be found in any configured themes.\nTried directories: " . implode(
', ',
array_values($this->designPaths[$design])
)
);
}
$this->logger?->warning(
"Asset '$path' cannot be found in any configured themes.\nTried directories: " . implode(
', ',
array_values($this->designPaths[$design])
)
);

return $path;
}
Expand Down
5 changes: 2 additions & 3 deletions src/lib/Asset/AssetPathResolverInterface.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\DesignEngine\Asset;

Expand All @@ -18,8 +19,6 @@ interface AssetPathResolverInterface
*
* @param string $path Asset path to resolve
* @param string $design Design to resolve path for
*
* @return string
*/
public function resolveAssetPath($path, $design);
public function resolveAssetPath(string $path, string $design): string;
}
Loading
Loading