Merge "Clarify that gender-unknown option is gender neutral"
[lhc/web/wiklou.git] / includes / objectcache / MemcachedClient.php
index 41eebfb..6912864 100644 (file)
@@ -64,6 +64,9 @@
  * @version 0.1.2
  */
 
+use Psr\Log\LoggerInterface;
+use Psr\Log\NullLogger;
+
 // {{{ requirements
 // }}}
 
@@ -233,6 +236,11 @@ class MWMemcached {
         */
        public $_connect_attempts;
 
+       /**
+        * @var LoggerInterface
+        */
+       private $_logger;
+
        // }}}
        // }}}
        // {{{ methods
@@ -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;
        }
 
@@ -741,13 +745,13 @@ class MWMemcached {
                $timeout = $this->_connect_timeout;
                $errno = $errstr = null;
                for ( $i = 0; !$sock && $i < $this->_connect_attempts; $i++ ) {
-                       wfSuppressWarnings();
+                       MediaWiki\suppressWarnings();
                        if ( $this->_persistent == 1 ) {
                                $sock = pfsockopen( $ip, $port, $errno, $errstr, $timeout );
                        } else {
                                $sock = fsockopen( $ip, $port, $errno, $errstr, $timeout );
                        }
-                       wfRestoreWarnings();
+                       MediaWiki\restoreWarnings();
                }
                if ( !$sock ) {
                        $this->_error_log( "Error connecting to $host: $errstr\n" );
@@ -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" );
        }
 
        /**