Merge "Add support for mulitpart mime email to email sending code"
[lhc/web/wiklou.git] / includes / objectcache / EhcacheBagOStuff.php
index fb31d5c..60d0645 100644 (file)
  * @ingroup Cache
  */
 class EhcacheBagOStuff extends BagOStuff {
-       var $servers, $cacheName, $connectTimeout, $timeout, $curlOptions, 
+       var $servers, $cacheName, $connectTimeout, $timeout, $curlOptions,
                $requestData, $requestDataPos;
-       
+
        var $curls = array();
 
+       /**
+        * @param $params array
+        * @throws MWException
+        */
        function __construct( $params ) {
                if ( !defined( 'CURLOPT_TIMEOUT_MS' ) ) {
                        throw new MWException( __CLASS__.' requires curl version 7.16.2 or later.' );
@@ -45,7 +49,7 @@ class EhcacheBagOStuff extends BagOStuff {
                }
                $this->servers = $params['servers'];
                $this->cacheName = isset( $params['cache'] ) ? $params['cache'] : 'mw';
-               $this->connectTimeout = isset( $params['connectTimeout'] ) 
+               $this->connectTimeout = isset( $params['connectTimeout'] )
                        ? $params['connectTimeout'] : 1;
                $this->timeout = isset( $params['timeout'] ) ? $params['timeout'] : 1;
                $this->curlOptions = array(
@@ -59,6 +63,10 @@ class EhcacheBagOStuff extends BagOStuff {
                );
        }
 
+       /**
+        * @param $key string
+        * @return bool|mixed
+        */
        public function get( $key ) {
                wfProfileIn( __METHOD__ );
                $response = $this->doItemRequest( $key );
@@ -69,7 +77,7 @@ class EhcacheBagOStuff extends BagOStuff {
                if ( $response['http_code'] >= 300 ) {
                        wfDebug( __METHOD__.": GET failure, got HTTP {$response['http_code']}\n" );
                        wfProfileOut( __METHOD__ );
-                       return false;                   
+                       return false;
                }
                $body = $response['body'];
                $type = $response['content_type'];
@@ -93,6 +101,12 @@ class EhcacheBagOStuff extends BagOStuff {
                return $data;
        }
 
+       /**
+        * @param $key string
+        * @param $value mixed
+        * @param $expiry int
+        * @return bool
+        */
        public function set( $key, $value, $expiry = 0 ) {
                wfProfileIn( __METHOD__ );
                $expiry = $this->convertExpiry( $expiry );
@@ -130,6 +144,11 @@ class EhcacheBagOStuff extends BagOStuff {
                return $result;
        }
 
+       /**
+        * @param $key string
+        * @param $time int
+        * @return bool
+        */
        public function delete( $key, $time = 0 ) {
                wfProfileIn( __METHOD__ );
                $response = $this->doItemRequest( $key,
@@ -145,6 +164,10 @@ class EhcacheBagOStuff extends BagOStuff {
                return $result;
        }
 
+       /**
+        * @param $key string
+        * @return string
+        */
        protected function getCacheUrl( $key ) {
                if ( count( $this->servers ) == 1 ) {
                        $server = reset( $this->servers );
@@ -172,10 +195,17 @@ class EhcacheBagOStuff extends BagOStuff {
                return $this->curls[$cacheUrl];
        }
 
+       /**
+        * @param $key string
+        * @param $data
+        * @param $type
+        * @param $ttl
+        * @return int
+        */
        protected function attemptPut( $key, $data, $type, $ttl ) {
-               // In initial benchmarking, it was 30 times faster to use CURLOPT_POST 
+               // In initial benchmarking, it was 30 times faster to use CURLOPT_POST
                // than CURLOPT_UPLOAD with CURLOPT_READFUNCTION. This was because
-               // CURLOPT_UPLOAD was pushing the request headers first, then waiting 
+               // CURLOPT_UPLOAD was pushing the request headers first, then waiting
                // for an ACK packet, then sending the data, whereas CURLOPT_POST just
                // sends the headers and the data in a single send().
                $response = $this->doItemRequest( $key,
@@ -196,9 +226,13 @@ class EhcacheBagOStuff extends BagOStuff {
                }
        }
 
+       /**
+        * @param $key string
+        * @return bool
+        */
        protected function createCache( $key ) {
                wfDebug( __METHOD__.": creating cache for $key\n" );
-               $response = $this->doCacheRequest( $key, 
+               $response = $this->doCacheRequest( $key,
                        array(
                                CURLOPT_POST => 1,
                                CURLOPT_CUSTOMREQUEST => 'PUT',
@@ -208,21 +242,26 @@ class EhcacheBagOStuff extends BagOStuff {
                        wfDebug( __CLASS__.": failed to create cache for $key\n" );
                        return false;
                }
-               if ( $response['http_code'] == 201 /* created */ 
-                       || $response['http_code'] == 409 /* already there */ ) 
-               {
-                       return true;
-               } else {
-                       return false;
-               }                       
+               return ( $response['http_code'] == 201 /* created */
+                       || $response['http_code'] == 409 /* already there */ );
        }
 
+       /**
+        * @param $key string
+        * @param $curlOptions array
+        * @return array|bool|mixed
+        */
        protected function doCacheRequest( $key, $curlOptions = array() ) {
                $cacheUrl = $this->getCacheUrl( $key );
                $curl = $this->getCurl( $cacheUrl );
                return $this->doRequest( $curl, $cacheUrl, $curlOptions );
        }
 
+       /**
+        * @param $key string
+        * @param $curlOptions array
+        * @return array|bool|mixed
+        */
        protected function doItemRequest( $key, $curlOptions = array() ) {
                $cacheUrl = $this->getCacheUrl( $key );
                $curl = $this->getCurl( $cacheUrl );
@@ -230,11 +269,18 @@ class EhcacheBagOStuff extends BagOStuff {
                return $this->doRequest( $curl, $url, $curlOptions );
        }
 
+       /**
+        * @param $curl
+        * @param $url string
+        * @param $curlOptions array
+        * @return array|bool|mixed
+        * @throws MWException
+        */
        protected function doRequest( $curl, $url, $curlOptions = array() ) {
                if ( array_diff_key( $curlOptions, $this->curlOptions ) ) {
                        // var_dump( array_diff_key( $curlOptions, $this->curlOptions ) );
                        throw new MWException( __METHOD__.": to prevent options set in one doRequest() " .
-                               "call from affecting subsequent doRequest() calls, only options listed " . 
+                               "call from affecting subsequent doRequest() calls, only options listed " .
                                "in \$this->curlOptions may be specified in the \$curlOptions parameter." );
                }
                $curlOptions += $this->curlOptions;