1010 * of the License, or any later version.
1111 */
1212
13+ use Psr \Http \Message \ServerRequestInterface ;
14+ use TYPO3 \CMS \Core \Http \ApplicationType ;
1315use TYPO3 \CMS \Core \Page \PageRenderer ;
1416use TYPO3 \CMS \Core \Utility \GeneralUtility ;
1517use TYPO3 \CMS \Frontend \Controller \TypoScriptFrontendController ;
2224 */
2325class PageRendererHook
2426{
25- /**
26- * @var ResourceMatcher
27- */
28- protected $ matcher ;
2927
30- /**
31- * @param ResourceMatcher|null $matcher
32- */
33- public function __construct (ResourceMatcher $ matcher = null )
28+ public function __construct (protected ResourceMatcher $ matcher )
3429 {
35- $ this ->matcher = $ matcher ?: GeneralUtility::makeInstance (ResourceMatcher::class);
3630 }
3731
3832 /**
@@ -42,9 +36,15 @@ public function __construct(ResourceMatcher $matcher = null)
4236 */
4337 public function accumulateResources (array $ params , PageRenderer $ pageRenderer )
4438 {
39+ $ request = $ this ->getRequest ();
40+ if ($ request === null ) {
41+ return ;
42+ }
4543 // If this is a second run (non-cached cObjects adding more data), then the existing cached data is fetched
46- if ($ this ->getTypoScriptFrontendController () instanceof TypoScriptFrontendController) {
47- $ allResources = $ this ->getTypoScriptFrontendController ()->config ['b13/http2 ' ] ?? [];
44+ if (ApplicationType::fromRequest ($ GLOBALS ['TYPO3_REQUEST ' ])->isFrontend ()) {
45+ /** @var TypoScriptFrontendController $frontendController */
46+ $ frontendController = $ request ->getAttribute ('frontend.controller ' );
47+ $ allResources = $ frontendController ->config ['b13/http2 ' ] ?? [];
4848 } else {
4949 $ allResources = [];
5050 }
@@ -64,7 +64,7 @@ public function accumulateResources(array $params, PageRenderer $pageRenderer)
6464 $ allResources ['scripts ' ] = array_unique ($ allResources ['scripts ' ] ?? []);
6565 $ allResources ['styles ' ] = array_unique ($ allResources ['styles ' ] ?? []);
6666
67- $ this ->process ($ allResources );
67+ $ this ->process ($ allResources, $ request );
6868 }
6969
7070 /**
@@ -73,18 +73,20 @@ public function accumulateResources(array $params, PageRenderer $pageRenderer)
7373 *
7474 * @param array $allResources
7575 */
76- protected function process (array $ allResources)
76+ protected function process (array $ allResources, ServerRequestInterface $ request ): void
7777 {
78- if ($ this ->getTypoScriptFrontendController () instanceof TypoScriptFrontendController) {
79- $ this ->getTypoScriptFrontendController ()->config ['b13/http2 ' ] = $ allResources ;
78+ if (ApplicationType::fromRequest ($ GLOBALS ['TYPO3_REQUEST ' ])->isFrontend ()) {
79+ /** @var TypoScriptFrontendController $frontendController */
80+ $ frontendController = $ request ->getAttribute ('frontend.controller ' );
81+ $ frontendController ->config ['b13/http2 ' ] = $ allResources ;
8082 } elseif (GeneralUtility::getIndpEnv ('TYPO3_SSL ' )) {
8183 // Push directly into the TYPO3 Backend, but only if TYPO3 is running in SSL
8284 GeneralUtility::makeInstance (ResourcePusher::class)->pushAll ($ allResources );
8385 }
8486 }
8587
86- protected function getTypoScriptFrontendController ()
88+ protected function getRequest (): ? ServerRequestInterface
8789 {
88- return $ GLOBALS ['TSFE ' ] ?? null ;
90+ return $ GLOBALS ['TYPO3_REQUEST ' ] ?? null ;
8991 }
9092}
0 commit comments