Skip to content
Draft
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
11 changes: 11 additions & 0 deletions dependencies.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"recipesEndpoint": "",
"packages": [
{
"requirement": "dev-IBX-12204-siteaccessservice-scope-stack as 6.0.x-dev",
"repositoryUrl": "https://github.com/ibexa/behat.git",
"package": "ibexa/behat",
"shouldBeAddedAsVCS": false
}
]
}
Comment on lines +1 to +11
66 changes: 0 additions & 66 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -1608,18 +1608,6 @@ parameters:
count: 1
path: src/bundle/Core/EventListener/ConfigScopeListener.php

-
message: '#^Cannot access property \$matchingType on Ibexa\\Core\\MVC\\Symfony\\SiteAccess\|null\.$#'
identifier: property.nonObject
count: 2
path: src/bundle/Core/EventListener/ConsoleCommandListener.php

-
message: '#^Cannot access property \$name on Ibexa\\Core\\MVC\\Symfony\\SiteAccess\|null\.$#'
identifier: property.nonObject
count: 3
path: src/bundle/Core/EventListener/ConsoleCommandListener.php

-
message: '#^Method Ibexa\\Bundle\\Core\\EventListener\\ConsoleCommandListener\:\:onConsoleCommand\(\) has no return type specified\.$#'
identifier: missingType.return
Expand All @@ -1638,18 +1626,6 @@ parameters:
count: 1
path: src/bundle/Core/EventListener/ConsoleCommandListener.php

-
message: '#^Method Ibexa\\Bundle\\Core\\EventListener\\ConsoleCommandListener\:\:setSiteAccess\(\) has no return type specified\.$#'
identifier: missingType.return
count: 1
path: src/bundle/Core/EventListener/ConsoleCommandListener.php

-
message: '#^Parameter \#1 \$siteAccess of class Ibexa\\Core\\MVC\\Symfony\\Event\\ScopeChangeEvent constructor expects Ibexa\\Core\\MVC\\Symfony\\SiteAccess, Ibexa\\Core\\MVC\\Symfony\\SiteAccess\|null given\.$#'
identifier: argument.type
count: 1
path: src/bundle/Core/EventListener/ConsoleCommandListener.php

-
message: '#^Method Ibexa\\Bundle\\Core\\EventListener\\ContentDownloadRouteReferenceListener\:\:configureOptions\(\) has no return type specified\.$#'
identifier: missingType.return
Expand Down Expand Up @@ -2982,12 +2958,6 @@ parameters:
count: 1
path: src/bundle/Core/Fragment/InlineFragmentRenderer.php

-
message: '#^Property Ibexa\\Bundle\\Core\\Fragment\\InlineFragmentRenderer\:\:\$siteAccess is never read, only written\.$#'
identifier: property.onlyWritten
count: 1
path: src/bundle/Core/Fragment/InlineFragmentRenderer.php

-
message: '#^Trait Ibexa\\Bundle\\Core\\Fragment\\SiteAccessSerializationTrait is used zero times and is not analysed\.$#'
identifier: trait.unused
Expand Down Expand Up @@ -3036,24 +3006,6 @@ parameters:
count: 1
path: src/bundle/Core/Imagine/Cache/AliasGeneratorDecorator.php

-
message: '#^Method Ibexa\\Bundle\\Core\\Imagine\\Cache\\AliasGeneratorDecorator\:\:setSiteAccess\(\) has no return type specified\.$#'
identifier: missingType.return
count: 1
path: src/bundle/Core/Imagine/Cache/AliasGeneratorDecorator.php

-
message: '#^Property Ibexa\\Bundle\\Core\\Imagine\\Cache\\AliasGeneratorDecorator\:\:\$siteAccess \(Ibexa\\Core\\MVC\\Symfony\\SiteAccess\) does not accept Ibexa\\Core\\MVC\\Symfony\\SiteAccess\|null\.$#'
identifier: assign.propertyType
count: 1
path: src/bundle/Core/Imagine/Cache/AliasGeneratorDecorator.php

-
message: '#^Property Ibexa\\Core\\MVC\\Symfony\\SiteAccess\:\:\$name \(string\) on left side of \?\? is not nullable\.$#'
identifier: nullCoalesce.property
count: 2
path: src/bundle/Core/Imagine/Cache/AliasGeneratorDecorator.php

-
message: '#^Method Ibexa\\Bundle\\Core\\Imagine\\Cache\\Resolver\\RelativeResolver\:\:rewriteUrl\(\) has parameter \$url with no type specified\.$#'
identifier: missingType.parameter
Expand Down Expand Up @@ -3408,12 +3360,6 @@ parameters:
count: 1
path: src/bundle/Core/Routing/DefaultRouter.php

-
message: '#^Cannot access property \$name on Ibexa\\Core\\MVC\\Symfony\\SiteAccess\|null\.$#'
identifier: property.nonObject
count: 2
path: src/bundle/Core/SiteAccess/Config/ComplexConfigProcessor.php

-
message: '#^Method Ibexa\\Bundle\\Core\\SiteAccess\\Matcher\:\:setMatchingConfiguration\(\) has no return type specified\.$#'
identifier: missingType.return
Expand Down Expand Up @@ -7362,18 +7308,6 @@ parameters:
count: 1
path: src/lib/Helper/ContentPreviewHelper.php

-
message: '#^Method Ibexa\\Core\\Helper\\ContentPreviewHelper\:\:setSiteAccess\(\) has no return type specified\.$#'
identifier: missingType.return
count: 1
path: src/lib/Helper/ContentPreviewHelper.php

-
message: '#^Property Ibexa\\Core\\Helper\\ContentPreviewHelper\:\:\$originalSiteAccess \(Ibexa\\Core\\MVC\\Symfony\\SiteAccess\) does not accept Ibexa\\Core\\MVC\\Symfony\\SiteAccess\|null\.$#'
identifier: assign.propertyType
count: 1
path: src/lib/Helper/ContentPreviewHelper.php

-
message: '#^Cannot access property \$fieldTypeIdentifier on Ibexa\\Contracts\\Core\\Repository\\Values\\ContentType\\FieldDefinition\|null\.$#'
identifier: property.nonObject
Expand Down
12 changes: 6 additions & 6 deletions src/bundle/Core/Command/DebugConfigResolverCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
namespace Ibexa\Bundle\Core\Command;

use Ibexa\Contracts\Core\SiteAccess\ConfigResolverInterface;
use Ibexa\Core\MVC\Symfony\SiteAccess;
use Ibexa\Core\MVC\Symfony\SiteAccess\SiteAccessServiceInterface;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
Expand All @@ -28,15 +28,14 @@ class DebugConfigResolverCommand extends Command
/** @var \Ibexa\Contracts\Core\SiteAccess\ConfigResolverInterface */
private $configResolver;

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

public function __construct(
ConfigResolverInterface $configResolver,
SiteAccess $siteAccess
SiteAccessServiceInterface $siteAccessService
) {
$this->configResolver = $configResolver;
$this->siteAccess = $siteAccess;
$this->siteAccessService = $siteAccessService;

parent::__construct();
}
Expand Down Expand Up @@ -102,7 +101,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
return self::SUCCESS;
}

$output->writeln('<comment>SiteAccess name:</comment> ' . $this->siteAccess->name);
$siteAccess = $this->siteAccessService->getCurrent();
$output->writeln('<comment>SiteAccess name:</comment> ' . ($siteAccess !== null ? $siteAccess->name : ''));

$output->writeln('<comment>Parameter:</comment>');
$cloner = new VarCloner();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
namespace Ibexa\Bundle\Core\DependencyInjection\Compiler;

use Ibexa\Core\MVC\Symfony\Routing\ChainRouter;
use Ibexa\Core\MVC\Symfony\SiteAccess;
use Ibexa\Core\MVC\Symfony\SiteAccess\Router;
use Ibexa\Core\MVC\Symfony\SiteAccess\SiteAccessServiceInterface;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
Expand All @@ -28,7 +28,7 @@ public function process(ContainerBuilder $container): void
// The default router will be given the highest priority so that it will be used by default
if ($container->hasDefinition('router.default')) {
$defaultRouter = $container->getDefinition('router.default');
$defaultRouter->addMethodCall('setSiteAccess', [new Reference(SiteAccess::class)]);
$defaultRouter->setArgument('$siteAccessService', new Reference(SiteAccessServiceInterface::class));
$defaultRouter->addMethodCall('setConfigResolver', [new Reference('ibexa.config.resolver')]);
$defaultRouter->addMethodCall(
'setNonSiteAccessAwareRoutes',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Ibexa\Bundle\Core\Fragment\FragmentListenerFactory;
use Ibexa\Bundle\Core\Fragment\InlineFragmentRenderer;
use Ibexa\Bundle\Core\Fragment\SiteAccessSerializerInterface;
use Ibexa\Core\MVC\Symfony\SiteAccess\SiteAccessServiceInterface;
use Symfony\Component\DependencyInjection\ChildDefinition;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
Expand Down Expand Up @@ -49,10 +50,16 @@ public function process(ContainerBuilder $container): void
$container->setDefinition($renamedId, $definition);

$decoratedDef = new ChildDefinition(DecoratedFragmentRenderer::class);
$decoratedDef->setArguments([new Reference($renamedId), new Reference(SiteAccessSerializerInterface::class)]);
$decoratedDef->setArguments([
new Reference($renamedId),
new Reference(SiteAccessSerializerInterface::class),
new Reference(SiteAccessServiceInterface::class),
]);
$decoratedDef->setPublic($public);
$decoratedDef->setTags($tags);
// Special treatment for inline fragment renderer, to fit ESI renderer constructor type hinting (forced to InlineFragmentRenderer)
// Note: InlineFragmentRenderer's constructor only declares the first 2 arguments (it has
// no use for SiteAccessServiceInterface); PHP silently ignores the extra 3rd argument.
if ($id === 'fragment.renderer.inline') {
$decoratedDef->setClass(InlineFragmentRenderer::class);
}
Expand Down
7 changes: 2 additions & 5 deletions src/bundle/Core/DependencyInjection/Compiler/SecurityPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use Ibexa\Core\MVC\Symfony\Security\Authentication\AnonymousUserAccessListener;
use Ibexa\Core\MVC\Symfony\Security\Authentication\DefaultAuthenticationSuccessHandler;
use Ibexa\Core\MVC\Symfony\Security\HttpUtils;
use Ibexa\Core\MVC\Symfony\SiteAccess;
use Ibexa\Core\MVC\Symfony\SiteAccess\SiteAccessServiceInterface;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Exception\OutOfBoundsException;
Expand All @@ -39,10 +39,7 @@ private function registerHttpUtils(ContainerBuilder $container): void

$httpUtilsDef = $container->findDefinition('security.http_utils');
$httpUtilsDef->setClass(HttpUtils::class);
$httpUtilsDef->addMethodCall(
'setSiteAccess',
[new Reference(SiteAccess::class)]
);
$httpUtilsDef->setArgument('$siteAccessService', new Reference(SiteAccessServiceInterface::class));
}

private function registerSecurityAuthenticationSuccessHandler(ContainerBuilder $container): void
Expand Down
34 changes: 11 additions & 23 deletions src/bundle/Core/EventListener/ConsoleCommandListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,41 +8,34 @@
namespace Ibexa\Bundle\Core\EventListener;

use Ibexa\Core\MVC\Exception\InvalidSiteAccessException;
use Ibexa\Core\MVC\Symfony\Event\ScopeChangeEvent;
use Ibexa\Core\MVC\Symfony\MVCEvents;
use Ibexa\Core\MVC\Symfony\SiteAccess;
use Ibexa\Core\MVC\Symfony\SiteAccess\SiteAccessAware;
use Ibexa\Core\MVC\Symfony\SiteAccess\SiteAccessServiceInterface;
use Symfony\Component\Console\ConsoleEvents;
use Symfony\Component\Console\Event\ConsoleCommandEvent;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

class ConsoleCommandListener implements EventSubscriberInterface, SiteAccessAware
class ConsoleCommandListener implements EventSubscriberInterface
{
/** @var string */
private $defaultSiteAccessName;

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

/** @var \Symfony\Component\EventDispatcher\EventDispatcherInterface */
private $eventDispatcher;

/** @var \Ibexa\Core\MVC\Symfony\SiteAccess|null */
private $siteAccess;
private SiteAccessServiceInterface $siteAccessService;

/** @var bool */
private $debug;

public function __construct(
string $defaultSiteAccessName,
SiteAccess\SiteAccessProviderInterface $siteAccessProvider,
EventDispatcherInterface $eventDispatcher,
SiteAccessServiceInterface $siteAccessService,
bool $debug = false
) {
$this->defaultSiteAccessName = $defaultSiteAccessName;
$this->siteAccessProvider = $siteAccessProvider;
$this->eventDispatcher = $eventDispatcher;
$this->siteAccessService = $siteAccessService;
$this->debug = $debug;
}

Expand All @@ -57,24 +50,19 @@ public static function getSubscribedEvents(): array

public function onConsoleCommand(ConsoleCommandEvent $event)
{
$this->siteAccess->name = $event->getInput()->getParameterOption('--siteaccess', $this->defaultSiteAccessName);
$this->siteAccess->matchingType = 'cli';
$siteAccessName = $event->getInput()->getParameterOption('--siteaccess', $this->defaultSiteAccessName);
$siteAccess = new SiteAccess($siteAccessName, 'cli');

if (!$this->siteAccessProvider->isDefined($this->siteAccess->name)) {
if (!$this->siteAccessProvider->isDefined($siteAccess->name)) {
throw new InvalidSiteAccessException(
$this->siteAccess->name,
$siteAccess->name,
$this->siteAccessProvider,
$this->siteAccess->matchingType,
$siteAccess->matchingType,
$this->debug
);
}

$this->eventDispatcher->dispatch(new ScopeChangeEvent($this->siteAccess), MVCEvents::CONFIG_SCOPE_CHANGE);
}

public function setSiteAccess(?SiteAccess $siteAccess = null)
{
$this->siteAccess = $siteAccess;
$this->siteAccessService->changeSiteAccess($siteAccess);
}

public function setDebug($debug = false)
Expand Down
19 changes: 8 additions & 11 deletions src/bundle/Core/Fragment/DecoratedFragmentRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,29 @@
namespace Ibexa\Bundle\Core\Fragment;

use Ibexa\Core\MVC\Symfony\SiteAccess;
use Ibexa\Core\MVC\Symfony\SiteAccess\SiteAccessAware;
use Ibexa\Core\MVC\Symfony\SiteAccess\SiteAccessServiceInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Controller\ControllerReference;
use Symfony\Component\HttpKernel\Fragment\FragmentRendererInterface;
use Symfony\Component\HttpKernel\Fragment\RoutableFragmentRenderer;

class DecoratedFragmentRenderer implements FragmentRendererInterface, SiteAccessAware
class DecoratedFragmentRenderer implements FragmentRendererInterface
{
private FragmentRendererInterface $innerRenderer;

private ?SiteAccess $siteAccess = null;

private SiteAccessSerializerInterface $siteAccessSerializer;

private SiteAccessServiceInterface $siteAccessService;

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

public function setSiteAccess(?SiteAccess $siteAccess = null): void
{
$this->siteAccess = $siteAccess;
$this->siteAccessService = $siteAccessService;
}

public function setFragmentPath(string $path): void
Expand All @@ -42,7 +39,7 @@ public function setFragmentPath(string $path): void
return;
}

$matcher = $this->siteAccess?->matcher;
$matcher = $this->siteAccessService->getCurrent()?->matcher;
if ($matcher instanceof SiteAccess\URILexer) {
$path = $matcher->analyseLink($path);
}
Expand Down
11 changes: 1 addition & 10 deletions src/bundle/Core/Fragment/InlineFragmentRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,17 @@

namespace Ibexa\Bundle\Core\Fragment;

use Ibexa\Core\MVC\Symfony\SiteAccess;
use Ibexa\Core\MVC\Symfony\SiteAccess\SiteAccessAware;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Controller\ControllerReference;
use Symfony\Component\HttpKernel\Fragment\FragmentRendererInterface;
use Symfony\Component\HttpKernel\Fragment\InlineFragmentRenderer as BaseRenderer;
use Symfony\Component\HttpKernel\Fragment\RoutableFragmentRenderer;

class InlineFragmentRenderer extends BaseRenderer implements SiteAccessAware, FragmentRendererInterface
class InlineFragmentRenderer extends BaseRenderer implements FragmentRendererInterface
{
protected FragmentRendererInterface $innerRenderer;

private ?SiteAccess $siteAccess = null;

private SiteAccessSerializerInterface $siteAccessSerializer;

public function __construct(
Expand All @@ -39,11 +35,6 @@ public function setFragmentPath($path): void
}
}

public function setSiteAccess(?SiteAccess $siteAccess = null): void
{
$this->siteAccess = $siteAccess;
}

/**
* @param array<string, mixed> $options
*/
Expand Down
Loading