Coding standard and readability

This commit is contained in:
Kamisama 2013-08-27 14:22:45 -04:00
parent bdd00c2307
commit 244df0764f
2 changed files with 29 additions and 23 deletions

View file

@ -59,6 +59,7 @@ class MemcachedEngine extends CacheEngine {
*
* @param array $settings array of setting for the engine
* @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()) {
if (!class_exists('Memcached')) {
@ -81,11 +82,18 @@ class MemcachedEngine extends CacheEngine {
if (!is_array($this->settings['servers'])) {
$this->settings['servers'] = array($this->settings['servers']);
}
if (!isset($this->_Memcached)) {
if (isset($this->_Memcached)) {
return true;
}
$this->_Memcached = new Memcached($this->settings['persistent'] ? $this->settings['persistent_id'] : null);
$this->_setOptions();
if (!count($this->_Memcached->getServerList())) {
if (count($this->_Memcached->getServerList())) {
return true;
}
$servers = array();
foreach ($this->settings['servers'] as $server) {
$servers[] = $this->_parseServerString($server);
@ -103,8 +111,6 @@ class MemcachedEngine extends CacheEngine {
}
$this->_Memcached->setSaslAuthData($this->settings['login'], $this->settings['password']);
}
}
}
return true;
}
@ -136,10 +142,10 @@ class MemcachedEngine extends CacheEngine {
* @return array Array containing host, port
*/
protected function _parseServerString($server) {
if ($server[0] == 'u') {
if ($server[0] === 'u') {
return array($server, 0);
}
if (substr($server, 0, 1) == '[') {
if (substr($server, 0, 1) === '[') {
$position = strpos($server, ']:');
if ($position !== false) {
$position++;