Merge "Move up devunt's name to Developers"
[lhc/web/wiklou.git] / includes / actions / CachedAction.php
index d21f9ae..864094d 100644 (file)
@@ -1,22 +1,8 @@
 <?php
-
 /**
  * Abstract action class with scaffolding for caching HTML and other values
  * in a single blob.
  *
- * Before using any of the caching functionality, call startCache.
- * After the last call to either getCachedValue or addCachedHTML, call saveCache.
- *
- * To get a cached value or compute it, use getCachedValue like this:
- * $this->getCachedValue( $callback );
- *
- * To add HTML that should be cached, use addCachedHTML like this:
- * $this->addCachedHTML( $callback );
- *
- * The callback function is only called when needed, so do all your expensive
- * computations here. This function should returns the HTML to be cached.
- * It should not add anything to the PageOutput object!
- *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 2 of the License, or
  * http://www.gnu.org/copyleft/gpl.html
  *
  * @file
- * @ingroup Action
+ * @ingroup Actions
  * @author Jeroen De Dauw < jeroendedauw@gmail.com >
  * @since 1.20
  */
+
+/**
+ * Abstract action class with scaffolding for caching HTML and other values
+ * in a single blob.
+ *
+ * Before using any of the caching functionality, call startCache.
+ * After the last call to either getCachedValue or addCachedHTML, call saveCache.
+ *
+ * To get a cached value or compute it, use getCachedValue like this:
+ * $this->getCachedValue( $callback );
+ *
+ * To add HTML that should be cached, use addCachedHTML like this:
+ * $this->addCachedHTML( $callback );
+ *
+ * The callback function is only called when needed, so do all your expensive
+ * computations here. This function should returns the HTML to be cached.
+ * It should not add anything to the PageOutput object!
+ *
+ * @ingroup Actions
+ */
 abstract class CachedAction extends FormlessAction implements ICacheHelper {
 
        /**
@@ -52,7 +58,7 @@ abstract class CachedAction extends FormlessAction implements ICacheHelper {
         * If the cache is enabled or not.
         *
         * @since 1.20
-        * @var boolean
+        * @var bool
         */
        protected $cacheEnabled = true;
 
@@ -60,7 +66,7 @@ abstract class CachedAction extends FormlessAction implements ICacheHelper {
         * Sets if the cache should be enabled or not.
         *
         * @since 1.20
-        * @param boolean $cacheEnabled
+        * @param bool $cacheEnabled
         */
        public function setCacheEnabled( $cacheEnabled ) {
                $this->cacheHelper->setCacheEnabled( $cacheEnabled );
@@ -72,14 +78,14 @@ abstract class CachedAction extends FormlessAction implements ICacheHelper {
         *
         * @since 1.20
         *
-        * @param integer|null $cacheExpiry Sets the cache expiry, either ttl in seconds or unix timestamp.
-        * @param boolean|null $cacheEnabled Sets if the cache should be enabled or not.
+        * @param int|null $cacheExpiry Sets the cache expiry, either ttl in seconds or unix timestamp.
+        * @param bool|null $cacheEnabled Sets if the cache should be enabled or not.
         */
        public function startCache( $cacheExpiry = null, $cacheEnabled = null ) {
                $this->cacheHelper = new CacheHelper();
 
                $this->cacheHelper->setCacheEnabled( $this->cacheEnabled );
-               $this->cacheHelper->setOnInitializedHandler( array( $this, 'onCacheInitialized' ) );
+               $this->cacheHelper->setOnInitializedHandler( [ $this, 'onCacheInitialized' ] );
 
                $keyArgs = $this->getCacheKey();
 
@@ -104,13 +110,13 @@ abstract class CachedAction extends FormlessAction implements ICacheHelper {
         *
         * @since 1.20
         *
-        * @param {function} $computeFunction
+        * @param callable $computeFunction
         * @param array|mixed $args
         * @param string|null $key
         *
         * @return mixed
         */
-       public function getCachedValue( $computeFunction, $args = array(), $key = null ) {
+       public function getCachedValue( $computeFunction, $args = [], $key = null ) {
                return $this->cacheHelper->getCachedValue( $computeFunction, $args, $key );
        }
 
@@ -122,12 +128,13 @@ abstract class CachedAction extends FormlessAction implements ICacheHelper {
         *
         * @since 1.20
         *
-        * @param {function} $computeFunction
+        * @param callable $computeFunction
         * @param array $args
         * @param string|null $key
         */
-       public function addCachedHTML( $computeFunction, $args = array(), $key = null ) {
-               $this->getOutput()->addHTML( $this->cacheHelper->getCachedValue( $computeFunction, $args, $key ) );
+       public function addCachedHTML( $computeFunction, $args = [], $key = null ) {
+               $html = $this->cacheHelper->getCachedValue( $computeFunction, $args, $key );
+               $this->getOutput()->addHTML( $html );
        }
 
        /**
@@ -141,11 +148,12 @@ abstract class CachedAction extends FormlessAction implements ICacheHelper {
        }
 
        /**
-        * Sets the time to live for the cache, in seconds or a unix timestamp indicating the point of expiry.
+        * Sets the time to live for the cache, in seconds or a unix timestamp
+        * indicating the point of expiry.
         *
         * @since 1.20
         *
-        * @param integer $cacheExpiry
+        * @param int $cacheExpiry
         */
        public function setExpiry( $cacheExpiry ) {
                $this->cacheHelper->setExpiry( $cacheExpiry );
@@ -159,11 +167,11 @@ abstract class CachedAction extends FormlessAction implements ICacheHelper {
         * @return array
         */
        protected function getCacheKey() {
-               return array(
+               return [
                        get_class( $this->page ),
                        $this->getName(),
                        $this->getLanguage()->getCode()
-               );
+               ];
        }
 
        /**
@@ -171,12 +179,11 @@ abstract class CachedAction extends FormlessAction implements ICacheHelper {
         *
         * @since 1.20
         *
-        * @param boolean $hasCached
+        * @param bool $hasCached
         */
        public function onCacheInitialized( $hasCached ) {
                if ( $hasCached ) {
                        $this->getOutput()->setSubtitle( $this->cacheHelper->getCachedNotice( $this->getContext() ) );
                }
        }
-
 }