Merge "Ignore EXIF data in FormatMetadata::fetchExtendedMetadata()"
[lhc/web/wiklou.git] / includes / objectcache / MemcachedClient.php
index 7990053..bc4a00b 100644 (file)
@@ -64,6 +64,9 @@
  * @version 0.1.2
  */
 
+use Psr\Log\LoggerInterface;
+use Psr\Log\NullLogger;
+
 // {{{ requirements
 // }}}
 
@@ -106,7 +109,7 @@ class MWMemcached {
         * @var array
         * @access public
         */
-       var $stats;
+       public $stats;
 
        // }}}
        // {{{ private
@@ -117,7 +120,7 @@ class MWMemcached {
         * @var array
         * @access private
         */
-       var $_cache_sock;
+       public $_cache_sock;
 
        /**
         * Current debug status; 0 - none to 9 - profiling
@@ -125,7 +128,7 @@ class MWMemcached {
         * @var bool
         * @access private
         */
-       var $_debug;
+       public $_debug;
 
        /**
         * Dead hosts, assoc array, 'host'=>'unixtime when ok to check again'
@@ -133,7 +136,7 @@ class MWMemcached {
         * @var array
         * @access private
         */
-       var $_host_dead;
+       public $_host_dead;
 
        /**
         * Is compression available?
@@ -141,7 +144,7 @@ class MWMemcached {
         * @var bool
         * @access private
         */
-       var $_have_zlib;
+       public $_have_zlib;
 
        /**
         * Do we want to use compression?
@@ -149,7 +152,7 @@ class MWMemcached {
         * @var bool
         * @access private
         */
-       var $_compress_enable;
+       public $_compress_enable;
 
        /**
         * At how many bytes should we compress?
@@ -157,7 +160,7 @@ class MWMemcached {
         * @var int
         * @access private
         */
-       var $_compress_threshold;
+       public $_compress_threshold;
 
        /**
         * Are we using persistent links?
@@ -165,7 +168,7 @@ class MWMemcached {
         * @var bool
         * @access private
         */
-       var $_persistent;
+       public $_persistent;
 
        /**
         * If only using one server; contains ip:port to connect to
@@ -173,7 +176,7 @@ class MWMemcached {
         * @var string
         * @access private
         */
-       var $_single_sock;
+       public $_single_sock;
 
        /**
         * Array containing ip:port or array(ip:port, weight)
@@ -181,7 +184,7 @@ class MWMemcached {
         * @var array
         * @access private
         */
-       var $_servers;
+       public $_servers;
 
        /**
         * Our bit buckets
@@ -189,7 +192,7 @@ class MWMemcached {
         * @var array
         * @access private
         */
-       var $_buckets;
+       public $_buckets;
 
        /**
         * Total # of bit buckets we have
@@ -197,7 +200,7 @@ class MWMemcached {
         * @var int
         * @access private
         */
-       var $_bucketcount;
+       public $_bucketcount;
 
        /**
         * # of total servers we have
@@ -205,7 +208,7 @@ class MWMemcached {
         * @var int
         * @access private
         */
-       var $_active;
+       public $_active;
 
        /**
         * Stream timeout in seconds. Applies for example to fread()
@@ -213,7 +216,7 @@ class MWMemcached {
         * @var int
         * @access private
         */
-       var $_timeout_seconds;
+       public $_timeout_seconds;
 
        /**
         * Stream timeout in microseconds
@@ -221,17 +224,22 @@ class MWMemcached {
         * @var int
         * @access private
         */
-       var $_timeout_microseconds;
+       public $_timeout_microseconds;
 
        /**
         * Connect timeout in seconds
         */
-       var $_connect_timeout;
+       public $_connect_timeout;
 
        /**
         * Number of connection attempts for each server
         */
-       var $_connect_attempts;
+       public $_connect_attempts;
+
+       /**
+        * @var LoggerInterface
+        */
+       private $_logger;
 
        // }}}
        // }}}
@@ -263,6 +271,8 @@ class MWMemcached {
 
                $this->_connect_timeout = isset( $args['connect_timeout'] ) ? $args['connect_timeout'] : 0.1;
                $this->_connect_attempts = 2;
+
+               $this->_logger = isset( $args['logger'] ) ? $args['logger'] : new NullLogger();
        }
 
        // }}}
@@ -413,7 +423,6 @@ class MWMemcached {
         * @return mixed
         */
        public function get( $key, &$casToken = null ) {
-               wfProfileIn( __METHOD__ );
 
                if ( $this->_debug ) {
                        $this->_debugprint( "get($key)\n" );
@@ -421,19 +430,16 @@ class MWMemcached {
 
                if ( !is_array( $key ) && strval( $key ) === '' ) {
                        $this->_debugprint( "Skipping key which equals to an empty string" );
-                       wfProfileOut( __METHOD__ );
                        return false;
                }
 
                if ( !$this->_active ) {
-                       wfProfileOut( __METHOD__ );
                        return false;
                }
 
                $sock = $this->get_sock( $key );
 
                if ( !is_resource( $sock ) ) {
-                       wfProfileOut( __METHOD__ );
                        return false;
                }
 
@@ -446,7 +452,6 @@ class MWMemcached {
 
                $cmd = "gets $key\r\n";
                if ( !$this->_fwrite( $sock, $cmd ) ) {
-                       wfProfileOut( __METHOD__ );
                        return false;
                }
 
@@ -463,7 +468,6 @@ class MWMemcached {
                if ( isset( $val[$key] ) ) {
                        $value = $val[$key];
                }
-               wfProfileOut( __METHOD__ );
                return $value;
        }
 
@@ -1110,14 +1114,14 @@ class MWMemcached {
         * @param string $text
         */
        function _debugprint( $text ) {
-               wfDebugLog( 'memcached', $text );
+               $this->_logger->debug( $text );
        }
 
        /**
         * @param string $text
         */
        function _error_log( $text ) {
-               wfDebugLog( 'memcached-serious', "Memcached error: $text" );
+               $this->_logger->error( "Memcached error: $text" );
        }
 
        /**