1313use Joomla \CMS \Cache \CacheController ;
1414use Joomla \CMS \Cache \CacheControllerFactoryInterface ;
1515use Joomla \CMS \Document \FactoryInterface as DocumentFactoryInterface ;
16+ use Joomla \CMS \Event \Application \AfterRenderEvent ;
1617use Joomla \CMS \Event \Application \AfterRespondEvent ;
18+ use Joomla \CMS \Event \Application \AfterRouteEvent ;
1719use Joomla \CMS \Event \PageCache \GetKeyEvent ;
1820use Joomla \CMS \Event \PageCache \IsExcludedEvent ;
1921use Joomla \CMS \Event \PageCache \SetCachingEvent ;
@@ -139,18 +141,20 @@ public static function getSubscribedEvents(): array
139141 /**
140142 * Returns a cached page if the current URL exists in the cache.
141143 *
142- * @param Event $event The Joomla event being handled
144+ * @param AfterRouteEvent $event The Joomla event being handled
143145 *
144146 * @return void
145147 *
146148 * @since 4.0.0
147149 */
148- public function onAfterRoute (Event $ event )
150+ public function onAfterRoute (AfterRouteEvent $ event ): void
149151 {
150152 if (!$ this ->appStateSupportsCaching ()) {
151153 return ;
152154 }
153155
156+ $ app = $ this ->getApplication ();
157+
154158 // Import "pagecache" plugins
155159 $ dispatcher = $ this ->getDispatcher ();
156160 PluginHelper::importPlugin ('pagecache ' , null , true , $ dispatcher );
@@ -169,16 +173,16 @@ public function onAfterRoute(Event $event)
169173 }
170174
171175 // Set the page content from the cache and output it to the browser.
172- $ this -> getApplication () ->setBody ($ data );
176+ $ app ->setBody ($ data );
173177
174- echo $ this -> getApplication ()-> toString ((bool ) $ this -> getApplication () ->get ('gzip ' ));
178+ echo $ app -> toString ((bool ) $ app ->get ('gzip ' ));
175179
176180 // Mark afterCache in debug and run debug onAfterRespond events, e.g. show Joomla Debug Console if debug is active.
177181 if (JDEBUG ) {
178182 // Create a document instance and load it into the application.
179183 $ document = $ this ->documentFactory
180- ->createDocument ($ this -> getApplication () ->getInput ()->get ('format ' , 'html ' ));
181- $ this -> getApplication () ->loadDocument ($ document );
184+ ->createDocument ($ app ->getInput ()->get ('format ' , 'html ' ));
185+ $ app ->loadDocument ($ document );
182186
183187 if ($ this ->profiler ) {
184188 $ this ->profiler ->mark ('afterCache ' );
@@ -187,13 +191,13 @@ public function onAfterRoute(Event $event)
187191 $ this ->getDispatcher ()->dispatch ('onAfterRespond ' , new AfterRespondEvent (
188192 'onAfterRespond ' ,
189193 [
190- 'subject ' => $ this -> getApplication () ,
194+ 'subject ' => $ app ,
191195 ]
192196 ));
193197 }
194198
195199 // Closes the application.
196- $ this -> getApplication () ->close ();
200+ $ app ->close ();
197201 }
198202
199203 /**
@@ -220,16 +224,18 @@ private function appStateSupportsCaching(): bool
220224 static $ isSite = null ;
221225 static $ isGET = null ;
222226
227+ $ app = $ this ->getApplication ();
228+
223229 if ($ isSite === null ) {
224- $ isSite = $ this -> getApplication () ->isClient ('site ' );
225- $ isGET = $ this -> getApplication () ->getInput ()->getMethod () === 'GET ' ;
230+ $ isSite = $ app ->isClient ('site ' );
231+ $ isGET = $ app ->getInput ()->getMethod () === 'GET ' ;
226232 }
227233
228234 // Boolean short–circuit evaluation means this returns fast false when $isSite is false.
229235 return $ isSite
230236 && $ isGET
231- && $ this -> getApplication () ->getIdentity ()->guest
232- && empty ($ this -> getApplication () ->getMessageQueue ());
237+ && $ app ->getIdentity ()->guest
238+ && empty ($ app ->getMessageQueue ());
233239 }
234240
235241 /**
@@ -283,13 +289,13 @@ private function getCacheKey(): string
283289 /**
284290 * After Render Event. Check whether the current page is excluded from cache.
285291 *
286- * @param Event $event The CMS event we are handling.
292+ * @param AfterRenderEvent $event The CMS event we are handling.
287293 *
288294 * @return void
289295 *
290296 * @since 3.9.12
291297 */
292- public function onAfterRender (Event $ event )
298+ public function onAfterRender (AfterRenderEvent $ event ): void
293299 {
294300 if (!$ this ->appStateSupportsCaching () || $ this ->getCacheController ()->getCaching () === false ) {
295301 return ;
@@ -365,13 +371,13 @@ private function isExcluded(): bool
365371 /**
366372 * After Respond Event. Stores page in cache.
367373 *
368- * @param Event $event The application event we are handling.
374+ * @param AfterRespondEvent $event The application event we are handling.
369375 *
370376 * @return void
371377 *
372378 * @since 1.5
373379 */
374- public function onAfterRespond (Event $ event )
380+ public function onAfterRespond (AfterRespondEvent $ event ): void
375381 {
376382 if (!$ this ->appStateSupportsCaching () || $ this ->getCacheController ()->getCaching () === false ) {
377383 return ;
0 commit comments