/**
- Handles responses for all stat methods.
-
- @param boolean $decode Whether to decode data before returning it or not. Default is
true .
- @return array|string|boolean
false on error otherwise statistical data.
*/
protected function _statsRead($decode = true) {
$status = strtok($this->_read(),' ');
switch ($status) {
case 'OK':
$data = $this->_read((integer) strtok(' '));
return $decode ? $this->_decode($data) : $data;
default:
$this->_error($status);
return false;
}
}
/**
- Decodes YAML data. This is a super naive decoder which just works on
- a subset of YAML which is commonly returned by beanstalk.
-
- @param string $data The data in YAML format,can be either a list or a dictionary.
- @return array An (associative) array of the converted data.
*/
protected function _decode($data) {
$data = array_slice(explode("n",$data),1);
$result = [];
foreach ($data as $key => $value) {
if ($value[0] === '-') {
$value = ltrim($value,'- ');
} elseif (strpos($value,':') !== false) {
list($key,$value) = explode(':',$value);
$value = ltrim($value,' ');
}
if (is_numeric($value)) {
$value = (integer) $value == $value ? (integer) $value : (float) $value;
}
$result[$key] = $value;
}
return $result;
}
}
?>
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持编程之家。 (编辑:晋中站长网)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|