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

Main merged test - Testing merge of 4.6, PR 430, IBX-8957: Fixed deserializing SiteAccess Matchers for ESI #445

Merged
merged 2 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
95 changes: 0 additions & 95 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -11400,31 +11400,6 @@ parameters:
count: 1
path: src/lib/MVC/Symfony/EventListener/LanguageSwitchListener.php

-
message: "#^Call to an undefined method Ibexa\\\\Core\\\\MVC\\\\Symfony\\\\SiteAccess\\\\Matcher\\:\\:setSubMatchers\\(\\)\\.$#"
count: 1
path: src/lib/MVC/Symfony/EventListener/SiteAccessMatchListener.php

-
message: "#^Method Ibexa\\\\Core\\\\MVC\\\\Symfony\\\\EventListener\\\\SiteAccessMatchListener\\:\\:deserializeMatcher\\(\\) has parameter \\$serializedSubMatchers with no value type specified in iterable type array\\.$#"
count: 1
path: src/lib/MVC/Symfony/EventListener/SiteAccessMatchListener.php

-
message: "#^Parameter \\#1 \\$serializedGroups of method Ibexa\\\\Core\\\\MVC\\\\Symfony\\\\EventListener\\\\SiteAccessMatchListener\\:\\:buildGroups\\(\\) expects array\\<array\\{name\\: string\\}\\>, array\\<Ibexa\\\\Core\\\\MVC\\\\Symfony\\\\SiteAccessGroup\\> given\\.$#"
count: 1
path: src/lib/MVC/Symfony/EventListener/SiteAccessMatchListener.php

-
message: "#^Parameter \\#2 \\$haystack of function in_array expects array, array\\<string, class\\-string\\>\\|false given\\.$#"
count: 1
path: src/lib/MVC/Symfony/EventListener/SiteAccessMatchListener.php

-
message: "#^Parameter \\#2 \\$matcherFQCN of method Ibexa\\\\Core\\\\MVC\\\\Symfony\\\\EventListener\\\\SiteAccessMatchListener\\:\\:deserializeMatcher\\(\\) expects string, Ibexa\\\\Core\\\\MVC\\\\Symfony\\\\SiteAccess\\\\Matcher given\\.$#"
count: 1
path: src/lib/MVC/Symfony/EventListener/SiteAccessMatchListener.php

-
message: "#^Method Ibexa\\\\Core\\\\MVC\\\\Symfony\\\\ExpressionLanguage\\\\TwigVariableProviderExtension\\:\\:hasParameterProvider\\(\\) has parameter \\$variables with no value type specified in iterable type array\\.$#"
count: 1
Expand Down Expand Up @@ -24670,11 +24645,6 @@ parameters:
count: 1
path: tests/bundle/Core/Fragment/DecoratedFragmentRendererTest.php

-
message: "#^Parameter \\#1 \\$innerRenderer of class Ibexa\\\\Bundle\\\\Core\\\\Fragment\\\\DecoratedFragmentRenderer constructor expects Symfony\\\\Component\\\\HttpKernel\\\\Fragment\\\\FragmentRendererInterface, PHPUnit\\\\Framework\\\\MockObject\\\\MockObject given\\.$#"
count: 5
path: tests/bundle/Core/Fragment/DecoratedFragmentRendererTest.php

-
message: "#^Binary operation \"\\.\" between 'rendered_' and \\(Closure\\(array\\<string, mixed\\>\\)\\: string\\)\\|string results in an error\\.$#"
count: 1
Expand Down Expand Up @@ -24720,11 +24690,6 @@ parameters:
count: 1
path: tests/bundle/Core/Fragment/InlineFragmentRendererTest.php

-
message: "#^Parameter \\#1 \\$innerRenderer of class Ibexa\\\\Bundle\\\\Core\\\\Fragment\\\\InlineFragmentRenderer constructor expects Symfony\\\\Component\\\\HttpKernel\\\\Fragment\\\\FragmentRendererInterface, PHPUnit\\\\Framework\\\\MockObject\\\\MockObject given\\.$#"
count: 2
path: tests/bundle/Core/Fragment/InlineFragmentRendererTest.php

-
message: "#^Method Ibexa\\\\Tests\\\\Bundle\\\\Core\\\\Imagine\\\\AliasCleanerTest\\:\\:testRemoveAliases\\(\\) has no return type specified\\.$#"
count: 1
Expand Down Expand Up @@ -44755,36 +44720,6 @@ parameters:
count: 3
path: tests/lib/MVC/Symfony/EventListener/LanguageSwitchListenerTest.php

-
message: "#^Method Ibexa\\\\Tests\\\\Core\\\\MVC\\\\Symfony\\\\EventListener\\\\SiteAccessMatchListenerTest\\:\\:testGetSubscribedEvents\\(\\) has no return type specified\\.$#"
count: 1
path: tests/lib/MVC/Symfony/EventListener/SiteAccessMatchListenerTest.php

-
message: "#^Method Ibexa\\\\Tests\\\\Core\\\\MVC\\\\Symfony\\\\EventListener\\\\SiteAccessMatchListenerTest\\:\\:testOnKernelRequest\\(\\) has no return type specified\\.$#"
count: 1
path: tests/lib/MVC/Symfony/EventListener/SiteAccessMatchListenerTest.php

-
message: "#^Method Ibexa\\\\Tests\\\\Core\\\\MVC\\\\Symfony\\\\EventListener\\\\SiteAccessMatchListenerTest\\:\\:testOnKernelRequestSerializedSA\\(\\) has no return type specified\\.$#"
count: 1
path: tests/lib/MVC/Symfony/EventListener/SiteAccessMatchListenerTest.php

-
message: "#^Method Ibexa\\\\Tests\\\\Core\\\\MVC\\\\Symfony\\\\EventListener\\\\SiteAccessMatchListenerTest\\:\\:testOnKernelRequestSerializedSAWithCompoundMatcher\\(\\) has no return type specified\\.$#"
count: 1
path: tests/lib/MVC/Symfony/EventListener/SiteAccessMatchListenerTest.php

-
message: "#^Method Ibexa\\\\Tests\\\\Core\\\\MVC\\\\Symfony\\\\EventListener\\\\SiteAccessMatchListenerTest\\:\\:testOnKernelRequestSiteAccessPresent\\(\\) has no return type specified\\.$#"
count: 1
path: tests/lib/MVC/Symfony/EventListener/SiteAccessMatchListenerTest.php

-
message: "#^Method Ibexa\\\\Tests\\\\Core\\\\MVC\\\\Symfony\\\\EventListener\\\\SiteAccessMatchListenerTest\\:\\:testOnKernelRequestUserHashWithOriginalRequest\\(\\) has no return type specified\\.$#"
count: 1
path: tests/lib/MVC/Symfony/EventListener/SiteAccessMatchListenerTest.php

-
message: "#^Method Ibexa\\\\Tests\\\\Core\\\\MVC\\\\Symfony\\\\FieldType\\\\ImageAsset\\\\ParameterProviderTest\\:\\:dataProviderForTestGetViewParameters\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
Expand Down Expand Up @@ -46150,36 +46085,6 @@ parameters:
count: 6
path: tests/lib/MVC/Symfony/SiteAccess/Compound/CompoundOrTest.php

-
message: "#^Method Ibexa\\\\Tests\\\\Core\\\\MVC\\\\Symfony\\\\SiteAccess\\\\MatcherSerializationTest\\:\\:getMapHostMatcherTestCase\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: tests/lib/MVC/Symfony/SiteAccess/MatcherSerializationTest.php

-
message: "#^Method Ibexa\\\\Tests\\\\Core\\\\MVC\\\\Symfony\\\\SiteAccess\\\\MatcherSerializationTest\\:\\:getMapPortMatcherTestCase\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: tests/lib/MVC/Symfony/SiteAccess/MatcherSerializationTest.php

-
message: "#^Method Ibexa\\\\Tests\\\\Core\\\\MVC\\\\Symfony\\\\SiteAccess\\\\MatcherSerializationTest\\:\\:getMapURIMatcherTestCase\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: tests/lib/MVC/Symfony/SiteAccess/MatcherSerializationTest.php

-
message: "#^Method Ibexa\\\\Tests\\\\Core\\\\MVC\\\\Symfony\\\\SiteAccess\\\\MatcherSerializationTest\\:\\:matcherProvider\\(\\) has no return type specified\\.$#"
count: 1
path: tests/lib/MVC/Symfony/SiteAccess/MatcherSerializationTest.php

-
message: "#^Method Ibexa\\\\Tests\\\\Core\\\\MVC\\\\Symfony\\\\SiteAccess\\\\MatcherSerializationTest\\:\\:testDeserialize\\(\\) has no return type specified\\.$#"
count: 1
path: tests/lib/MVC/Symfony/SiteAccess/MatcherSerializationTest.php

-
message: "#^Parameter \\#1 \\$subMatchers of method Ibexa\\\\Core\\\\MVC\\\\Symfony\\\\SiteAccess\\\\Matcher\\\\Compound\\:\\:setSubMatchers\\(\\) expects array\\<Ibexa\\\\Core\\\\MVC\\\\Symfony\\\\SiteAccess\\\\Matcher\\>, array\\<string, array\\<string, array\\<string, string\\>\\>\\> given\\.$#"
count: 4
path: tests/lib/MVC/Symfony/SiteAccess/MatcherSerializationTest.php

-
message: "#^Method Ibexa\\\\Tests\\\\Core\\\\MVC\\\\Symfony\\\\SiteAccess\\\\Provider\\\\ChainSiteAccessProviderTest\\:\\:getExistingSiteProvider\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Ibexa\Bundle\Core\Fragment\DecoratedFragmentRenderer;
use Ibexa\Bundle\Core\Fragment\FragmentListenerFactory;
use Ibexa\Bundle\Core\Fragment\InlineFragmentRenderer;
use Ibexa\Bundle\Core\Fragment\SiteAccessSerializerInterface;
use Symfony\Component\DependencyInjection\ChildDefinition;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
Expand Down Expand Up @@ -48,7 +49,7 @@ public function process(ContainerBuilder $container)
$container->setDefinition($renamedId, $definition);

$decoratedDef = new ChildDefinition(DecoratedFragmentRenderer::class);
$decoratedDef->setArguments([new Reference($renamedId)]);
$decoratedDef->setArguments([new Reference($renamedId), new Reference(SiteAccessSerializerInterface::class)]);
$decoratedDef->setPublic($public);
$decoratedDef->setTags($tags);
// Special treatment for inline fragment renderer, to fit ESI renderer constructor type hinting (forced to InlineFragmentRenderer)
Expand Down
15 changes: 9 additions & 6 deletions src/bundle/Core/Fragment/DecoratedFragmentRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,20 @@

class DecoratedFragmentRenderer implements FragmentRendererInterface, SiteAccessAware
{
use SiteAccessSerializationTrait;

/** @var \Symfony\Component\HttpKernel\Fragment\FragmentRendererInterface */
private $innerRenderer;

/** @var \Ibexa\Core\MVC\Symfony\SiteAccess */
private $siteAccess;

public function __construct(FragmentRendererInterface $innerRenderer)
{
private SiteAccessSerializerInterface $siteAccessSerializer;

public function __construct(
FragmentRendererInterface $innerRenderer,
SiteAccessSerializerInterface $siteAccessSerializer
) {
$this->innerRenderer = $innerRenderer;
$this->siteAccessSerializer = $siteAccessSerializer;
}

/**
Expand Down Expand Up @@ -62,10 +65,10 @@ public function setFragmentPath($path)
public function render($uri, Request $request, array $options = [])
{
if ($uri instanceof ControllerReference && $request->attributes->has('siteaccess')) {
// Serialize the siteaccess to get it back after.
// Serialize a SiteAccess to get it back after.
// @see \Ibexa\Core\MVC\Symfony\EventListener\SiteAccessMatchListener
$siteAccess = $request->attributes->get('siteaccess');
$this->serializeSiteAccess($siteAccess, $uri);
$this->siteAccessSerializer->serializeSiteAccessAsControllerAttributes($siteAccess, $uri);
}

return $this->innerRenderer->render($uri, $request, $options);
Expand Down
13 changes: 8 additions & 5 deletions src/bundle/Core/Fragment/InlineFragmentRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,20 @@

class InlineFragmentRenderer extends BaseRenderer implements SiteAccessAware
{
use SiteAccessSerializationTrait;

/** @var \Symfony\Component\HttpKernel\Fragment\FragmentRendererInterface */
private $innerRenderer;

/** @var \Ibexa\Core\MVC\Symfony\SiteAccess */
private $siteAccess;

public function __construct(FragmentRendererInterface $innerRenderer)
{
private SiteAccessSerializerInterface $siteAccessSerializer;

public function __construct(
FragmentRendererInterface $innerRenderer,
SiteAccessSerializerInterface $siteAccessSerializer
) {
$this->innerRenderer = $innerRenderer;
$this->siteAccessSerializer = $siteAccessSerializer;
}

public function setFragmentPath($path)
Expand All @@ -48,7 +51,7 @@ public function render($uri, Request $request, array $options = [])
if ($request->attributes->has('siteaccess')) {
/** @var \Ibexa\Core\MVC\Symfony\SiteAccess $siteAccess */
$siteAccess = $request->attributes->get('siteaccess');
$this->serializeSiteAccess($siteAccess, $uri);
$this->siteAccessSerializer->serializeSiteAccessAsControllerAttributes($siteAccess, $uri);
}
if ($request->attributes->has('semanticPathinfo')) {
$uri->attributes['semanticPathinfo'] = $request->attributes->get('semanticPathinfo');
Expand Down
4 changes: 4 additions & 0 deletions src/bundle/Core/Fragment/SiteAccessSerializationTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
use Symfony\Component\HttpKernel\Controller\ControllerReference;
use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;

/**
* @deprecated Deprecated since 4.6. Inject an instance of {@see \Ibexa\Bundle\Core\Fragment\SiteAccessSerializerInterface}
* instead.
*/
trait SiteAccessSerializationTrait
{
use SerializerTrait;
Expand Down
51 changes: 51 additions & 0 deletions src/bundle/Core/Fragment/SiteAccessSerializer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

/**
* @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\Fragment;

use Ibexa\Core\MVC\Symfony\SiteAccess;
use Symfony\Component\HttpKernel\Controller\ControllerReference;
use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
use Symfony\Component\Serializer\SerializerInterface;

/**
* @internal
*/
final class SiteAccessSerializer implements SiteAccessSerializerInterface
{
private SerializerInterface $serializer;

public function __construct(SerializerInterface $serializer)
{
$this->serializer = $serializer;
}

/**
* @throws \JsonException
*/
public function serializeSiteAccessAsControllerAttributes(SiteAccess $siteAccess, ControllerReference $controller): void
{
// Serialize the SiteAccess to get it back after. @see \Ibexa\Core\MVC\Symfony\EventListener\SiteAccessMatchListener
$controller->attributes['serialized_siteaccess'] = json_encode($siteAccess, JSON_THROW_ON_ERROR);
$controller->attributes['serialized_siteaccess_matcher'] = $this->serializer->serialize(
$siteAccess->matcher,
'json',
[AbstractNormalizer::IGNORED_ATTRIBUTES => ['request', 'container', 'matcherBuilder', 'connection']]
);
if ($siteAccess->matcher instanceof SiteAccess\Matcher\CompoundInterface) {
$subMatchers = $siteAccess->matcher->getSubMatchers();
foreach ($subMatchers as $subMatcher) {
$controller->attributes['serialized_siteaccess_sub_matchers'][get_class($subMatcher)] = $this->serializer->serialize(
$subMatcher,
'json',
[AbstractNormalizer::IGNORED_ATTRIBUTES => ['request', 'container', 'matcherBuilder', 'connection']]
);
}
}
}
}
20 changes: 20 additions & 0 deletions src/bundle/Core/Fragment/SiteAccessSerializerInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

/**
* @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\Fragment;

use Ibexa\Core\MVC\Symfony\SiteAccess;
use Symfony\Component\HttpKernel\Controller\ControllerReference;

/**
* @internal
*/
interface SiteAccessSerializerInterface
{
public function serializeSiteAccessAsControllerAttributes(SiteAccess $siteAccess, ControllerReference $controller): void;
}
5 changes: 4 additions & 1 deletion src/bundle/Core/Resources/config/routing.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
imports:
- { resource: routing/serializers.yml }

parameters:
ibexa.default_router.non_site_access_aware_routes: ['_assetic_', '_wdt', '_profiler', '_configurator_', 'ibexa.user_hash']
# characters that may require encoding in the urlalias generator
Expand All @@ -19,7 +22,7 @@ services:
arguments:
$siteAccessRouter: '@Ibexa\Core\MVC\Symfony\SiteAccess\Router'
$eventDispatcher: '@event_dispatcher'
$siteAccessMatcherRegistry: '@Ibexa\Bundle\Core\SiteAccess\SiteAccessMatcherRegistryInterface'
$serializer: '@ibexa.core.mvc.serializer'
tags:
- { name: kernel.event_subscriber }

Expand Down
65 changes: 65 additions & 0 deletions src/bundle/Core/Resources/config/routing/serializers.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
services:
ibexa.core.mvc.serializer:
class: Symfony\Component\Serializer\Serializer
arguments:
$normalizers:
- '@ibexa.core.mvc.serializer.normalizer.array_denormalizer'
- '@Ibexa\Core\MVC\Symfony\Component\Serializer\SiteAccessNormalizer'
- '@Ibexa\Core\MVC\Symfony\Component\Serializer\MatcherDenormalizer'
- '@Ibexa\Core\MVC\Symfony\Component\Serializer\CompoundMatcherNormalizer'
- '@Ibexa\Core\MVC\Symfony\Component\Serializer\HostElementNormalizer'
- '@Ibexa\Core\MVC\Symfony\Component\Serializer\MapNormalizer'
- '@Ibexa\Core\MVC\Symfony\Component\Serializer\URITextNormalizer'
- '@Ibexa\Core\MVC\Symfony\Component\Serializer\HostTextNormalizer'
- '@Ibexa\Core\MVC\Symfony\Component\Serializer\RegexURINormalizer'
- '@Ibexa\Core\MVC\Symfony\Component\Serializer\RegexHostNormalizer'
- '@Ibexa\Core\MVC\Symfony\Component\Serializer\RegexNormalizer'
- '@Ibexa\Core\MVC\Symfony\Component\Serializer\URIElementNormalizer'
- '@Ibexa\Core\MVC\Symfony\Component\Serializer\SimplifiedRequestNormalizer'
- '@ibexa.core.mvc.serializer.normalizer.json_serializable_normalizer'
- '@ibexa.core.mvc.serializer.normalizer.property_normalizer'
$encoders:
- '@ibexa.core.mvc.serializer.json_encoder'

Ibexa\Bundle\Core\Fragment\SiteAccessSerializer:
arguments:
$serializer: '@ibexa.core.mvc.serializer'

Ibexa\Bundle\Core\Fragment\SiteAccessSerializerInterface:
alias: Ibexa\Bundle\Core\Fragment\SiteAccessSerializer

ibexa.core.mvc.serializer.json_encoder:
class: Symfony\Component\Serializer\Encoder\JsonEncoder

Ibexa\Core\MVC\Symfony\Component\Serializer\MatcherDenormalizer:
arguments:
$registry: '@Ibexa\Bundle\Core\SiteAccess\SiteAccessMatcherRegistryInterface'

Ibexa\Core\MVC\Symfony\Component\Serializer\SiteAccessNormalizer: ~

Ibexa\Core\MVC\Symfony\Component\Serializer\HostElementNormalizer: ~

Ibexa\Core\MVC\Symfony\Component\Serializer\MapNormalizer: ~

Ibexa\Core\MVC\Symfony\Component\Serializer\URITextNormalizer: ~

Ibexa\Core\MVC\Symfony\Component\Serializer\HostTextNormalizer: ~

Ibexa\Core\MVC\Symfony\Component\Serializer\RegexURINormalizer: ~

Ibexa\Core\MVC\Symfony\Component\Serializer\RegexHostNormalizer: ~

Ibexa\Core\MVC\Symfony\Component\Serializer\RegexNormalizer: ~

Ibexa\Core\MVC\Symfony\Component\Serializer\URIElementNormalizer: ~

Ibexa\Core\MVC\Symfony\Component\Serializer\SimplifiedRequestNormalizer: ~

ibexa.core.mvc.serializer.normalizer.json_serializable_normalizer:
class: Symfony\Component\Serializer\Normalizer\JsonSerializableNormalizer

ibexa.core.mvc.serializer.normalizer.property_normalizer:
class: Symfony\Component\Serializer\Normalizer\PropertyNormalizer

ibexa.core.mvc.serializer.normalizer.array_denormalizer:
class: Symfony\Component\Serializer\Normalizer\ArrayDenormalizer
Loading
Loading