7
7
use Neos \Flow \Annotations as Flow ;
8
8
use Neos \Fusion \Afx \Parser \AfxParserException ;
9
9
use Neos \Fusion \Afx \Service \AfxService ;
10
+ use Neos \Fusion \Core \FusionConfiguration ;
11
+ use Neos \Fusion \Core \FusionSourceCodeCollection ;
10
12
use Neos \Fusion \Core \Parser ;
11
13
use Neos \Fusion \Core \RuntimeFactory as FusionRuntimeFactory ;
12
14
use 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 ;
14
17
use Symfony \Component \Yaml \Yaml ;
15
18
16
19
/**
17
20
* Class FusionService
18
21
*/
19
- class FusionService extends NeosFusionService
22
+ class FusionService
20
23
{
21
24
use DummyControllerContextTrait;
22
25
23
26
/**
24
- * @Flow\InjectConfiguration(path="fusion.autoInclude", package="Neos.Neos")
25
- * @var array
27
+ * @Flow\Inject
28
+ * @var FusionRuntimeFactory
26
29
*/
27
- protected $ autoIncludeConfiguration = array () ;
30
+ protected $ fusionRuntimeFactory ;
28
31
29
32
/**
30
33
* @Flow\Inject
31
- * @var FusionRuntimeFactory
34
+ * @var Parser
32
35
*/
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 ;
34
49
35
50
/**
36
51
* Render the given string of AFX and returns it
37
52
*
38
- * @param [NodeInterface ] $contextNodes
53
+ * @param TraversableNodeInterface[ ] $contextNodes
39
54
* @param string $html
40
55
* @param string|null $props
41
56
* @return string
@@ -48,9 +63,9 @@ public function render(array $contextNodes, string $html, ?string $props = null)
48
63
49
64
try {
50
65
$ fusion = AfxService::convertAfxToFusion ($ html );
51
- $ parsedFusion = $ this ->getMergedFusionObjectTree ('html = ' . $ fusion , $ contextNodes ['site ' ] ?? null );
66
+ $ parsedFusion = $ this ->parseFusionSourceCode ('html = ' . $ fusion , $ contextNodes ['site ' ] ?? null );
52
67
53
- $ fusionRuntime = $ this ->fusionRuntimeFactory ->create ($ parsedFusion , $ controllerContext );
68
+ $ fusionRuntime = $ this ->fusionRuntimeFactory ->createFromConfiguration ($ parsedFusion , $ controllerContext );
54
69
$ fusionRuntime ->pushContext ('props ' , $ props );
55
70
if (isset ($ contextNodes ['node ' ])) {
56
71
$ fusionRuntime ->pushContext ('node ' , $ contextNodes ['node ' ]);
@@ -62,7 +77,6 @@ public function render(array $contextNodes, string $html, ?string $props = null)
62
77
$ fusionRuntime ->pushContext ('site ' , $ contextNodes ['site ' ]);
63
78
}
64
79
$ fusionRuntime ->setEnableContentCache (false );
65
-
66
80
return $ fusionRuntime ->render ('html ' );
67
81
} catch (RuntimeException $ e ) {
68
82
throw new ContentBoxRenderingException ($ e ->getPrevious ()->getMessage (), 1600950000 , $ e );
@@ -71,36 +85,34 @@ public function render(array $contextNodes, string $html, ?string $props = null)
71
85
}
72
86
}
73
87
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
+ }
79
106
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
88
108
{
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 );
94
113
}
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 ();
105
117
}
106
118
}
0 commit comments