diff --git a/Neos.Neos/Classes/Domain/Service/FusionService.php b/Neos.Neos/Classes/Domain/Service/FusionService.php index 05db82195f5..773283dd264 100644 --- a/Neos.Neos/Classes/Domain/Service/FusionService.php +++ b/Neos.Neos/Classes/Domain/Service/FusionService.php @@ -14,65 +14,27 @@ * source code. */ -use Neos\ContentRepository\Core\Projection\ContentGraph\Node; -use Neos\Flow\Mvc\Controller\ControllerContext; -use Neos\Fusion\Core\FusionConfiguration; use Neos\Flow\Annotations as Flow; +use Neos\Flow\Mvc\ActionRequest; +use Neos\Fusion\Core\FusionConfiguration; use Neos\Fusion\Core\FusionGlobals; -use Neos\Fusion\Core\FusionSourceCode; use Neos\Fusion\Core\FusionSourceCodeCollection; use Neos\Fusion\Core\Parser; use Neos\Fusion\Core\Runtime; use Neos\Fusion\Core\RuntimeFactory; use Neos\Neos\Domain\Model\Site; -use Neos\Neos\Domain\Model\SiteNodeName; use Neos\Neos\Domain\Repository\SiteRepository; /** - * @todo currently scope prototype will change with the removal of the internal state to singleton in Neos 9.0 - * - * @Flow\Scope("prototype") * @api */ +#[Flow\Scope('singleton')] class FusionService { /** * Pattern used for determining the Fusion root file for a site - * - * @deprecated with Neos 8.3, will be immutable with 9.0 - * @var string - */ - protected $siteRootFusionPattern = 'resource://%s/Private/Fusion/Root.fusion'; - - /** - * Array of Fusion files to include before the site Fusion - * - * Example: - * - * array( - * 'resources://MyVendor.MyPackageKey/Private/Fusion/Root.fusion', - * 'resources://SomeVendor.OtherPackage/Private/Fusion/Root.fusion' - * ) - * - * @deprecated with Neos 8.3, will be removed with 9.0 - * @var array */ - protected $prependFusionIncludes = []; - - /** - * Array of Fusion files to include after the site Fusion - * - * Example: - * - * array( - * 'resources://MyVendor.MyPackageKey/Private/Fusion/Root.fusion', - * 'resources://SomeVendor.OtherPackage/Private/Fusion/Root.fusion' - * ) - * - * @deprecated with Neos 8.3, will be removed with 9.0 - * @var array - */ - protected $appendFusionIncludes = []; + private const SITE_ROOT_FUSION_PATTERN = 'resource://%s/Private/Fusion/Root.fusion'; /** * @Flow\Inject @@ -109,156 +71,35 @@ public function createFusionConfigurationFromSite(Site $site): FusionConfigurati return $this->fusionConfigurationCache->cacheFusionConfigurationBySite($site, function () use ($site) { $siteResourcesPackageKey = $site->getSiteResourcesPackageKey(); - $siteRootFusionPathAndFilename = sprintf($this->siteRootFusionPattern, $siteResourcesPackageKey); + $siteRootFusionPathAndFilename = sprintf(self::SITE_ROOT_FUSION_PATTERN, $siteResourcesPackageKey); return $this->fusionParser->parseFromSource( $this->fusionSourceCodeFactory->createFromNodeTypeDefinitions($site->getConfiguration()->contentRepositoryId) ->union( $this->fusionSourceCodeFactory->createFromAutoIncludes() ) - ->union( - $this->createSourceCodeFromLegacyFusionIncludes($this->prependFusionIncludes, $siteRootFusionPathAndFilename) - ) ->union( FusionSourceCodeCollection::tryFromFilePath($siteRootFusionPathAndFilename) ) - ->union( - $this->createSourceCodeFromLegacyFusionIncludes($this->appendFusionIncludes, $siteRootFusionPathAndFilename) - ) ); }); } /** - * Returns a merged Fusion object tree in the context of the given nodes - * - * @deprecated with Neos 8.3, will be removed with 9.0 {@link createFusionConfigurationFromSite} - * - * @param Node $startNode Node marking the starting point (i.e. the "Site" node) - * @return array The merged object tree as of the given node - */ - public function getMergedFusionObjectTree(Node $startNode) - { - return $this->createFusionConfigurationFromSite($this->findSiteBySiteNode($startNode))->toArray(); - } - - /** - * Create a runtime for the given site node - * - * @deprecated with Neos 8.3, will be removed with 9.0 use {@link createFusionConfigurationFromSite} and {@link RuntimeFactory::createFromConfiguration} instead + * Create a runtime for the given site * * @return Runtime */ public function createRuntime( - Node $currentSiteNode, - ControllerContext $controllerContext - ) { + Site $site, + ActionRequest $actionRequest + ): Runtime { $fusionGlobals = FusionGlobals::fromArray( - ['request' => $controllerContext->getRequest()] + ['request' => $actionRequest] ); - $runtime = $this->runtimeFactory->createFromConfiguration( - $this->createFusionConfigurationFromSite($this->findSiteBySiteNode($currentSiteNode)), + return $this->runtimeFactory->createFromConfiguration( + $this->createFusionConfigurationFromSite($site), $fusionGlobals ); - $runtime->setControllerContext($controllerContext); - return $runtime; - } - - /** - * Set the pattern for including the site root Fusion - * - * @deprecated with Neos 8.3, will be removed with 9.0 - * use {@link FusionSourceCodeFactory} in combination with {@link RuntimeFactory::createRuntimeFromSourceCode()} instead - * - * @param string $siteRootFusionPattern A string for the sprintf format that takes the site package key as a single placeholder - * @return void - */ - public function setSiteRootFusionPattern($siteRootFusionPattern) - { - $this->siteRootFusionPattern = $siteRootFusionPattern; - } - - /** - * Get the Fusion resources that are included before the site Fusion. - * - * @deprecated with Neos 8.3, will be removed with 9.0 - * use {@link FusionSourceCodeFactory} in combination with {@link RuntimeFactory::createRuntimeFromSourceCode()} instead - * - * @return array - */ - public function getPrependFusionIncludes() - { - return $this->prependFusionIncludes; - } - - /** - * Set Fusion resources that should be prepended before the site Fusion, - * it defaults to the Neos Root.fusion Fusion. - * - * @deprecated with Neos 8.3, will be removed with 9.0 - * use {@link FusionSourceCodeFactory} in combination with {@link RuntimeFactory::createRuntimeFromSourceCode()} instead - * - * @param array $prependFusionIncludes - * @return void - */ - public function setPrependFusionIncludes(array $prependFusionIncludes) - { - $this->prependFusionIncludes = $prependFusionIncludes; - } - - - /** - * Get Fusion resources that will be appended after the site Fusion. - * - * @deprecated with Neos 8.3, will be removed with 9.0 - * use {@link FusionSourceCodeFactory} in combination with {@link RuntimeFactory::createRuntimeFromSourceCode()} instead - * - * @return array - */ - public function getAppendFusionIncludes() - { - return $this->appendFusionIncludes; - } - - /** - * Set Fusion resources that should be appended after the site Fusion, - * this defaults to an empty array. - * - * @deprecated with Neos 8.3, will be removed with 9.0 - * use {@link FusionSourceCodeFactory} in combination with {@link RuntimeFactory::createRuntimeFromSourceCode()} instead - * - * @param array $appendFusionIncludes An array of Fusion resource URIs - * @return void - */ - public function setAppendFusionIncludes(array $appendFusionIncludes) - { - $this->appendFusionIncludes = $appendFusionIncludes; - } - - /** - * @param array $fusionIncludes - * @deprecated with Neos 8.3, will be removed with 9.0 - */ - private function createSourceCodeFromLegacyFusionIncludes(array $fusionIncludes, string $filePathForRelativeResolves): FusionSourceCodeCollection - { - return new FusionSourceCodeCollection(...array_map( - function (string $fusionFile) use ($filePathForRelativeResolves) { - if (str_starts_with($fusionFile, "resource://") === false) { - // legacy relative includes - $fusionFile = dirname($filePathForRelativeResolves) . '/' . $fusionFile; - } - return FusionSourceCode::fromFilePath($fusionFile); - }, - $fusionIncludes - )); - } - - private function findSiteBySiteNode(Node $siteNode): Site - { - if ($siteNode->nodeName === null) { - throw new \Neos\Neos\Domain\Exception(sprintf('Site node "%s" is unnamed', $siteNode->nodeAggregateId->value), 1681286146); - } - return $this->siteRepository->findOneByNodeName(SiteNodeName::fromNodeName($siteNode->nodeName)) - ?? throw new \Neos\Neos\Domain\Exception(sprintf('No site found for nodeNodeName "%s"', $siteNode->nodeName->value), 1677245517); } }