<?php
-// @codingStandardsIgnoreFile It's an external lib and it isn't. Let's not bother.
+// phpcs:ignoreFile -- It's an external lib and it isn't. Let's not bother.
/**
* Memcached client for PHP.
*
* Memcache initializer
*
* @param array $args Associative array of settings
- *
- * @return mixed
*/
public function __construct( $args ) {
- $this->set_servers( isset( $args['servers'] ) ? $args['servers'] : array() );
- $this->_debug = isset( $args['debug'] ) ? $args['debug'] : false;
+ $this->set_servers( $args['servers'] ?? array() );
+ $this->_debug = $args['debug'] ?? false;
$this->stats = array();
- $this->_compress_threshold = isset( $args['compress_threshold'] ) ? $args['compress_threshold'] : 0;
- $this->_persistent = isset( $args['persistent'] ) ? $args['persistent'] : false;
+ $this->_compress_threshold = $args['compress_threshold'] ?? 0;
+ $this->_persistent = $args['persistent'] ?? false;
$this->_compress_enable = true;
$this->_have_zlib = function_exists( 'gzcompress' );
$this->_host_dead = array();
$this->_timeout_seconds = 0;
- $this->_timeout_microseconds = isset( $args['timeout'] ) ? $args['timeout'] : 500000;
+ $this->_timeout_microseconds = $args['timeout'] ?? 500000;
- $this->_connect_timeout = isset( $args['connect_timeout'] ) ? $args['connect_timeout'] : 0.1;
+ $this->_connect_timeout = $args['connect_timeout'] ?? 0.1;
$this->_connect_attempts = 2;
- $this->_logger = isset( $args['logger'] ) ? $args['logger'] : new NullLogger();
+ $this->_logger = $args['logger'] ?? new NullLogger();
}
// }}}
+
+ /**
+ * @param mixed $value
+ * @return string|integer
+ */
+ public function serialize( $value ) {
+ return serialize( $value );
+ }
+
+ /**
+ * @param string $value
+ * @return mixed
+ */
+ public function unserialize( $value ) {
+ return unserialize( $value );
+ }
+
// {{{ add()
/**
/**
* Changes the TTL on a key from the server to $time
*
- * @param string $key Key
+ * @param string $key
* @param int $time TTL in seconds
*
* @return bool True on success, false on failure
if ( $this->_debug ) {
foreach ( $val as $k => $v ) {
- $this->_debugprint( sprintf( "MemCache: sock %s got %s", serialize( $sock ), $k ) );
+ $this->_debugprint(
+ sprintf( "MemCache: sock %s got %s", $this->serialize( $sock ), $k ) );
}
}
$timeout = $this->_connect_timeout;
$errno = $errstr = null;
for ( $i = 0; !$sock && $i < $this->_connect_attempts; $i++ ) {
- MediaWiki\suppressWarnings();
+ Wikimedia\suppressWarnings();
if ( $this->_persistent == 1 ) {
$sock = pfsockopen( $ip, $port, $errno, $errstr, $timeout );
} else {
$sock = fsockopen( $ip, $port, $errno, $errstr, $timeout );
}
- MediaWiki\restoreWarnings();
+ Wikimedia\restoreWarnings();
}
if ( !$sock ) {
$this->_error_log( "Error connecting to $host: $errstr" );
* yet read "END"), these 2 calls would collide.
*/
if ( $flags & self::SERIALIZED ) {
- $ret[$rkey] = unserialize( $ret[$rkey] );
+ $ret[$rkey] = $this->unserialize( $ret[$rkey] );
} elseif ( $flags & self::INTVAL ) {
$ret[$rkey] = intval( $ret[$rkey] );
}
if ( is_int( $val ) ) {
$flags |= self::INTVAL;
} elseif ( !is_scalar( $val ) ) {
- $val = serialize( $val );
+ $val = $this->serialize( $val );
$flags |= self::SERIALIZED;
if ( $this->_debug ) {
$this->_debugprint( sprintf( "client: serializing data as it is not scalar" ) );