mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Coding standard and readability
This commit is contained in:
parent
bdd00c2307
commit
244df0764f
2 changed files with 29 additions and 23 deletions
|
@ -59,6 +59,7 @@ class MemcachedEngine extends CacheEngine {
|
||||||
*
|
*
|
||||||
* @param array $settings array of setting for the engine
|
* @param array $settings array of setting for the engine
|
||||||
* @return boolean True if the engine has been successfully initialized, false if not
|
* @return boolean True if the engine has been successfully initialized, false if not
|
||||||
|
* @throws CacheException when you try use authentication without Memcached compiled with SASL support
|
||||||
*/
|
*/
|
||||||
public function init($settings = array()) {
|
public function init($settings = array()) {
|
||||||
if (!class_exists('Memcached')) {
|
if (!class_exists('Memcached')) {
|
||||||
|
@ -81,29 +82,34 @@ class MemcachedEngine extends CacheEngine {
|
||||||
if (!is_array($this->settings['servers'])) {
|
if (!is_array($this->settings['servers'])) {
|
||||||
$this->settings['servers'] = array($this->settings['servers']);
|
$this->settings['servers'] = array($this->settings['servers']);
|
||||||
}
|
}
|
||||||
if (!isset($this->_Memcached)) {
|
|
||||||
$this->_Memcached = new Memcached($this->settings['persistent'] ? $this->settings['persistent_id'] : null);
|
|
||||||
$this->_setOptions();
|
|
||||||
|
|
||||||
if (!count($this->_Memcached->getServerList())) {
|
if (isset($this->_Memcached)) {
|
||||||
$servers = array();
|
return true;
|
||||||
foreach ($this->settings['servers'] as $server) {
|
}
|
||||||
$servers[] = $this->_parseServerString($server);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!$this->_Memcached->addServers($servers)) {
|
$this->_Memcached = new Memcached($this->settings['persistent'] ? $this->settings['persistent_id'] : null);
|
||||||
return false;
|
$this->_setOptions();
|
||||||
}
|
|
||||||
|
|
||||||
if ($this->settings['login'] !== null && $this->settings['password'] !== null) {
|
if (count($this->_Memcached->getServerList())) {
|
||||||
if (!method_exists($this->_Memcached, 'setSaslAuthData')) {
|
return true;
|
||||||
throw new CacheException(
|
}
|
||||||
__d('cake_dev', 'Memcached extension is not build with SASL support')
|
|
||||||
);
|
$servers = array();
|
||||||
}
|
foreach ($this->settings['servers'] as $server) {
|
||||||
$this->_Memcached->setSaslAuthData($this->settings['login'], $this->settings['password']);
|
$servers[] = $this->_parseServerString($server);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!$this->_Memcached->addServers($servers)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->settings['login'] !== null && $this->settings['password'] !== null) {
|
||||||
|
if (!method_exists($this->_Memcached, 'setSaslAuthData')) {
|
||||||
|
throw new CacheException(
|
||||||
|
__d('cake_dev', 'Memcached extension is not build with SASL support')
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
$this->_Memcached->setSaslAuthData($this->settings['login'], $this->settings['password']);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -136,10 +142,10 @@ class MemcachedEngine extends CacheEngine {
|
||||||
* @return array Array containing host, port
|
* @return array Array containing host, port
|
||||||
*/
|
*/
|
||||||
protected function _parseServerString($server) {
|
protected function _parseServerString($server) {
|
||||||
if ($server[0] == 'u') {
|
if ($server[0] === 'u') {
|
||||||
return array($server, 0);
|
return array($server, 0);
|
||||||
}
|
}
|
||||||
if (substr($server, 0, 1) == '[') {
|
if (substr($server, 0, 1) === '[') {
|
||||||
$position = strpos($server, ']:');
|
$position = strpos($server, ']:');
|
||||||
if ($position !== false) {
|
if ($position !== false) {
|
||||||
$position++;
|
$position++;
|
||||||
|
|
|
@ -155,8 +155,8 @@ class MemcachedEngineTest extends CakeTestCase {
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->setExpectedException(
|
$this->setExpectedException(
|
||||||
'CacheException', 'Memcached extension is not build with SASL support'
|
'CacheException', 'Memcached extension is not build with SASL support'
|
||||||
);
|
);
|
||||||
$Memcached->init($settings);
|
$Memcached->init($settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue