77use Neos \Flow \Annotations as Flow ;
88use Neos \Fusion \Afx \Parser \AfxParserException ;
99use Neos \Fusion \Afx \Service \AfxService ;
10+ use Neos \Fusion \Core \FusionConfiguration ;
11+ use Neos \Fusion \Core \FusionSourceCodeCollection ;
1012use Neos \Fusion \Core \Parser ;
1113use Neos \Fusion \Core \RuntimeFactory as FusionRuntimeFactory ;
1214use Neos \Fusion \Exception \RuntimeException ;
13- use Neos \Neos \Domain \Service \FusionService as NeosFusionService ;
15+ use Neos \Neos \Domain \Repository \SiteRepository ;
16+ use Neos \Neos \Domain \Service \FusionSourceCodeFactory ;
1417use Symfony \Component \Yaml \Yaml ;
1518
1619/**
1720 * Class FusionService
1821 */
19- class FusionService extends NeosFusionService
22+ class FusionService
2023{
2124 use DummyControllerContextTrait;
2225
2326 /**
24- * @Flow\InjectConfiguration(path="fusion.autoInclude", package="Neos.Neos")
25- * @var array
27+ * @Flow\Inject
28+ * @var FusionRuntimeFactory
2629 */
27- protected $ autoIncludeConfiguration = array () ;
30+ protected $ fusionRuntimeFactory ;
2831
2932 /**
3033 * @Flow\Inject
31- * @var FusionRuntimeFactory
34+ * @var Parser
3235 */
33- protected $ fusionRuntimeFactory ;
36+ protected $ fusionParser ;
37+
38+ /**
39+ * @Flow\Inject
40+ * @var FusionSourceCodeFactory
41+ */
42+ protected $ fusionSourceCodeFactory ;
43+
44+ /**
45+ * @Flow\Inject
46+ * @var SiteRepository
47+ */
48+ protected $ siteRepository ;
3449
3550 /**
3651 * Render the given string of AFX and returns it
3752 *
38- * @param [NodeInterface ] $contextNodes
53+ * @param TraversableNodeInterface[ ] $contextNodes
3954 * @param string $html
4055 * @param string|null $props
4156 * @return string
@@ -48,9 +63,9 @@ public function render(array $contextNodes, string $html, ?string $props = null)
4863
4964 try {
5065 $ fusion = AfxService::convertAfxToFusion ($ html );
51- $ parsedFusion = $ this ->getMergedFusionObjectTree ('html = ' . $ fusion , $ contextNodes ['site ' ] ?? null );
66+ $ parsedFusion = $ this ->parseFusionSourceCode ('html = ' . $ fusion , $ contextNodes ['site ' ] ?? null );
5267
53- $ fusionRuntime = $ this ->fusionRuntimeFactory ->create ($ parsedFusion , $ controllerContext );
68+ $ fusionRuntime = $ this ->fusionRuntimeFactory ->createFromConfiguration ($ parsedFusion , $ controllerContext );
5469 $ fusionRuntime ->pushContext ('props ' , $ props );
5570 if (isset ($ contextNodes ['node ' ])) {
5671 $ fusionRuntime ->pushContext ('node ' , $ contextNodes ['node ' ]);
@@ -62,7 +77,6 @@ public function render(array $contextNodes, string $html, ?string $props = null)
6277 $ fusionRuntime ->pushContext ('site ' , $ contextNodes ['site ' ]);
6378 }
6479 $ fusionRuntime ->setEnableContentCache (false );
65-
6680 return $ fusionRuntime ->render ('html ' );
6781 } catch (RuntimeException $ e ) {
6882 throw new ContentBoxRenderingException ($ e ->getPrevious ()->getMessage (), 1600950000 , $ e );
@@ -71,36 +85,34 @@ public function render(array $contextNodes, string $html, ?string $props = null)
7185 }
7286 }
7387
74- /**
75- * @Flow\Inject
76- * @var Parser
77- */
78- protected $ fusionParser ;
88+ private function parseFusionSourceCode (string $ fusionSourceCode , ?TraversableNodeInterface $ currentSiteNode ): FusionConfiguration
89+ {
90+ return $ this ->fusionParser ->parseFromSource (
91+ $ this ->tryFusionCodeCollectionFromSiteNode ($ currentSiteNode )
92+ ->union (
93+ $ this ->fusionSourceCodeFactory ->createFromNodeTypeDefinitions ()
94+ )
95+ ->union (
96+ $ this ->fusionSourceCodeFactory ->createFromAutoIncludes ()
97+ )
98+ ->union (
99+ FusionSourceCodeCollection::fromFilePath ('resource://Garagist.ContentBox/Private/ContentBox/Root.fusion ' )
100+ )
101+ ->union (
102+ FusionSourceCodeCollection::fromString ($ fusionSourceCode )
103+ )
104+ );
105+ }
79106
80- /**
81- * Parse all the fusion files the are in the current fusionPathPatterns
82- *
83- * @param $fusion
84- * @param TraversableNodeInterface $startNode
85- * @return array
86- */
87- public function getMergedFusionObjectTree ($ fusion , ?TraversableNodeInterface $ startNode = null ): array
107+ private function tryFusionCodeCollectionFromSiteNode (?TraversableNodeInterface $ siteNode ): FusionSourceCodeCollection
88108 {
89- $ siteRootFusionCode = '' ;
90- if ($ startNode ) {
91- $ siteResourcesPackageKey = $ this ->getSiteForSiteNode ($ startNode )->getSiteResourcesPackageKey ();
92- $ siteRootFusionPathAndFilename = sprintf ('resource://%s/Private/Fusion/Root.fusion ' , $ siteResourcesPackageKey );
93- $ siteRootFusionCode = $ this ->getFusionIncludes ([$ siteRootFusionPathAndFilename ]);
109+ $ site = null ;
110+ if ($ siteNode ) {
111+ $ site = $ this ->siteRepository ->findOneByNodeName ((string )$ siteNode ->getNodeName ())
112+ ?? throw new \Neos \Neos \Domain \Exception (sprintf ('No site found for nodeNodeName "%s" ' , $ siteNode ->getNodeName ()), 1677245517 );
94113 }
95-
96- $ fusionCode = $ this ->generateNodeTypeDefinitions ();
97- $ fusionCode .= $ this ->getFusionIncludes ($ this ->prepareAutoIncludeFusion ());
98- $ fusionCode .= $ this ->getFusionIncludes ($ this ->prependFusionIncludes );
99- $ fusionCode .= $ siteRootFusionCode ;
100- $ fusionCode .= $ this ->getFusionIncludes ($ this ->appendFusionIncludes );
101- $ fusionCode .= $ this ->getFusionIncludes (['resource://Garagist.ContentBox/Private/ContentBox/Root.fusion ' ]);
102- $ fusionCode .= $ fusion ;
103-
104- return $ this ->fusionParser ->parse ($ fusionCode , null );
114+ return $ site
115+ ? $ this ->fusionSourceCodeFactory ->createFromSite ($ site )
116+ : FusionSourceCodeCollection::empty ();
105117 }
106118}
0 commit comments