55use Flowpack \DecoupledContentStore \Aspects \CacheUrlMappingAspect ;
66use Flowpack \DecoupledContentStore \Exception ;
77use Flowpack \DecoupledContentStore \Core \Infrastructure \ContentReleaseLogger ;
8+ use Flowpack \DecoupledContentStore \NodeRendering \NodeRenderingUriService ;
89use Flowpack \DecoupledContentStore \Transfer \Resource \Target \MultisiteFileSystemSymlinkTarget ;
910use GuzzleHttp \Psr7 \ServerRequest ;
1011use Neos \Flow \Annotations as Flow ;
@@ -38,6 +39,12 @@ class DocumentRenderer
3839 */
3940 protected $ useRelativeResourceUris ;
4041
42+ /**
43+ * @Flow\Inject
44+ * @var NodeRenderingUriService
45+ */
46+ protected $ nodeRenderingUriService ;
47+
4148 /**
4249 * Add HTTP message if rendering full content
4350 *
@@ -52,51 +59,12 @@ class DocumentRenderer
5259 */
5360 protected $ fusionView ;
5461
55- /**
56- * @Flow\Inject
57- * @var SecurityContext
58- */
59- protected $ securityContext ;
60-
61- /**
62- * @Flow\Inject
63- * @var ConfigurationManager
64- */
65- protected $ configurationManager ;
66-
6762 /**
6863 * @Flow\Inject(lazy=false)
6964 * @var ResourceManager
7065 */
7166 protected $ resourceManager ;
7267
73- /**
74- * @Flow\Inject
75- * @var \Neos\Neos\Service\LinkingService
76- */
77- protected $ linkingService ;
78-
79- /**
80- * NOTE: we need to use EAGER injection here, because in buildControllerContextAndSetBaseUri(), we
81- * directly set a property of the BaseUriProvider using ObjectAccess::setProperty() with forceDirectAccess.
82- *
83- * @Flow\Inject(lazy=false)
84- * @var BaseUriProvider
85- */
86- protected $ baseUriProvider ;
87-
88- /**
89- * @var \Neos\Flow\Mvc\Routing\Router
90- * @Flow\Inject
91- */
92- protected $ router ;
93-
94- /**
95- * @Flow\Inject
96- * @var \Neos\Flow\Property\PropertyMapper
97- */
98- protected $ propertyMapper ;
99-
10068 /**
10169 * @Flow\Inject
10270 * @var CacheUrlMappingAspect
@@ -119,7 +87,7 @@ class DocumentRenderer
11987 public function renderDocumentNodeVariant (NodeInterface $ node , array $ arguments , ContentReleaseLogger $ contentReleaseLogger ): string
12088 {
12189 $ this ->cacheUrlMappingAspect ->beforeDocumentRendering ($ contentReleaseLogger );
122- $ nodeUri = $ this ->buildNodeUri ($ node , $ arguments );
90+ $ nodeUri = $ this ->nodeRenderingUriService -> buildNodeUri ($ node , $ arguments );
12391
12492 try {
12593 $ arguments ['node ' ] = $ node ->getContextPath ();
@@ -131,75 +99,6 @@ public function renderDocumentNodeVariant(NodeInterface $node, array $arguments,
13199 }
132100 }
133101
134- /**
135- * @param string $uri
136- * @param NodeInterface $node
137- * @param array $arguments
138- * @return ControllerContext
139- */
140- protected function buildControllerContextAndSetBaseUri (string $ uri , NodeInterface $ node , array $ arguments = [])
141- {
142- $ request = $ this ->getRequest ($ uri , $ node );
143- if (isset ($ arguments ['@format ' ])) {
144- $ request ->setFormat ($ arguments ['@format ' ]);
145- }
146-
147- // NASTY SIDE-EFFECT: we not only build the controller context, but we also need to inject the "current" base URL to BaseUriProvider,
148- // as this is now (Flow 6.x) used in the UriBuilder to determine the domain.
149- $ baseUri = rtrim (RequestInformationHelper::generateBaseUri ($ request ->getHttpRequest ()), '/ ' );
150- ObjectAccess::setProperty ($ this ->baseUriProvider , 'configuredBaseUri ' , $ baseUri , true );
151-
152- ObjectAccess::setProperty ($ this ->securityContext , 'initialized ' , true , true );
153- $ this ->securityContext ->setRequest ($ request );
154- $ uriBuilder = $ this ->getUriBuilder ($ request );
155-
156- return new ControllerContext (
157- $ request ,
158- new ActionResponse (),
159- new Arguments ([]),
160- $ uriBuilder
161- );
162- }
163-
164- /**
165- * @param ActionRequest $request
166- * @return UriBuilder
167- * @throws \Neos\Utility\Exception\PropertyNotAccessibleException
168- */
169- protected function getUriBuilder ($ request )
170- {
171- $ uriBuilder = new UriBuilder ();
172- $ uriBuilder ->setRequest ($ request );
173-
174- $ routesConfiguration = $ this ->configurationManager ->getConfiguration (ConfigurationManager::CONFIGURATION_TYPE_ROUTES );
175- $ router = ObjectAccess::getProperty ($ uriBuilder , 'router ' , true );
176-
177- $ router ->setRoutesConfiguration ($ routesConfiguration );
178-
179- return $ uriBuilder ;
180- }
181-
182- /**
183- * @param string $uri
184- * @param NodeInterface $node
185- * @return ActionRequest
186- */
187- protected function getRequest ($ uri , NodeInterface $ node )
188- {
189- $ _SERVER ['FLOW_REWRITEURLS ' ] = '1 ' ;
190-
191- $ httpRequest = new ServerRequest ('GET ' , $ uri );
192- $ routingParameters = RouteParameters::createEmpty ()->withParameter ('requestUriHost ' , $ httpRequest ->getUri ()->getHost ());
193- $ httpRequest = $ httpRequest ->withAttribute (ServerRequestAttributes::ROUTING_PARAMETERS , $ routingParameters );
194-
195- $ request = ActionRequest::fromHttpRequest ($ httpRequest );
196- $ request ->setControllerObjectName ('Neos\Neos\Controller\Frontend\NodeController ' );
197- $ request ->setControllerActionName ('show ' );
198- $ request ->setFormat ('html ' );
199- $ request ->setArgument ('node ' , $ node ->getContextPath ());
200-
201- return $ request ;
202- }
203102
204103 /**
205104 * Render the view of a document node
@@ -231,7 +130,7 @@ protected function renderDocumentView(NodeInterface $node, $uri, array $requestA
231130
232131 $ contentReleaseLogger ->info ('Rendering document for URI ' . $ uri , ['baseUri ' => $ baseUri ]);
233132
234- $ controllerContext = $ this ->buildControllerContextAndSetBaseUri ($ uri , $ node , $ requestArguments );
133+ $ controllerContext = $ this ->nodeRenderingUriService -> buildControllerContextAndSetBaseUri ($ uri , $ node , $ requestArguments );
235134 /** @var ActionRequest $request */
236135 $ request = $ controllerContext ->getRequest ();
237136 $ request ->setArguments ($ requestArguments );
@@ -282,34 +181,6 @@ private static function wrapInHttpMessage(string $output, ActionResponse $respon
282181 return "HTTP/1.1 " . (empty ($ headerLines ) ? "\r\n" : implode ("\r\n" , $ headerLines )) . "\r\n" . $ output ;
283182 }
284183
285-
286- /**
287- * @param NodeInterface $node
288- * @param array $arguments
289- * @return string The resolved URI for the given node
290- * @throws \Exception
291- */
292- protected function buildNodeUri (NodeInterface $ node , array $ arguments )
293- {
294- /** @var Site $currentSite */
295- $ currentSite = $ node ->getContext ()->getCurrentSite ();
296- if (!$ currentSite ->hasActiveDomains ()) {
297- throw new Exception (sprintf ("Site %s has no active domain " , $ currentSite ->getNodeName ()), 1666684522 );
298- }
299- $ primaryDomain = $ currentSite ->getPrimaryDomain ();
300- if ((string )$ primaryDomain ->getScheme () === '' ) {
301- throw new Exception (sprintf ("Domain %s for site %s has no scheme defined " , $ primaryDomain ->getHostname (), $ currentSite ->getNodeName ()), 1666684523 );
302- }
303-
304- // HINT: We cannot use a static URL here, but instead need to use an URL of the current site.
305- // This is changed from the the old behavior, where we have changed the LinkingService in LinkingServiceAspect,
306- // to properly generate the domain part of the routes - and this relies on the proper ControllerContext URI path.
307- $ baseControllerContext = $ this ->buildControllerContextAndSetBaseUri ($ primaryDomain ->__toString (), $ node , $ arguments );
308- $ format = $ arguments ['@format ' ] ?? 'html ' ;
309- $ uri = $ this ->linkingService ->createNodeUri ($ baseControllerContext , $ node , null , $ format , true , $ arguments , '' , false , [], false );
310- return $ this ->removeQueryPartFromUri ($ uri );
311- }
312-
313184 /**
314185 * @return bool
315186 */
@@ -318,17 +189,6 @@ public function isRendering()
318189 return $ this ->isRendering ;
319190 }
320191
321- /**
322- * @param string $uri
323- * @return string
324- */
325- protected function removeQueryPartFromUri ($ uri )
326- {
327- $ uriData = explode ('? ' , $ uri );
328-
329- return $ uriData [0 ];
330- }
331-
332192 public function disableCache ()
333193 {
334194 $ this ->fusionView ->disableCache ();
@@ -338,5 +198,4 @@ public function enableCache()
338198 {
339199 $ this ->fusionView ->enableCache ();
340200 }
341-
342201}
0 commit comments