/** * @param string $task * * @return array */ public function getAll($task) { $rc = new \ReflectionClass($this); $data = []; foreach ($rc->getConstants() as $n => $field) { if (!Text::startsWith($n, 'FIELD_')) { continue; } $value = $this->adapter->get($this->_formatKey($task, $field)); if ($value !== false) { $data[(string) $field] = $value; } } if (isset($data[self::FIELD_START_TIME])) { if (isset($data[self::FIELD_STOP_TIME])) { $data['up_time'] = strtotime($data[self::FIELD_STOP_TIME]) - strtotime($data[self::FIELD_START_TIME]); } else { $data['up_time'] = time() - strtotime($data[self::FIELD_START_TIME]); } /** @noinspection SummerTimeUnsafeTimeManipulationInspection */ $data['up_time_human'] = round($data['up_time'] / 3600 / 24) . ' days ' . gmstrftime('%H:%M:%S', $data['up_time'] % (3600 * 24)); } if (isset($data[self::FIELD_KEEP_ALIVE_TIME])) { if (isset($data[self::FIELD_STOP_TIME])) { $keep_alive = strtotime($data[self::FIELD_STOP_TIME]) - strtotime($data[self::FIELD_KEEP_ALIVE_TIME]); } else { $keep_alive = time() - strtotime($data[self::FIELD_KEEP_ALIVE_TIME]); } /** @noinspection SummerTimeUnsafeTimeManipulationInspection */ $data['keep_alive_time_human'] = round($keep_alive / 3600 / 24) . ' days ' . gmstrftime('%H:%M:%S', $keep_alive % (3600 * 24)); } if (!isset($data[self::FIELD_STATUS])) { $data[self::FIELD_STATUS] = Task::STATUS_NONE; } if (!isset($data[self::FIELD_CLASS])) { $data[self::FIELD_CLASS] = $task; } ksort($data); return $data; }