Viewing File: /usr/local/cpanel/3rdparty/wpinstaller/src/Common/ActionLogger.php
<?php
namespace Common;
class ActionLogger {
protected $actions;
private $protected_keys = array('result', 'action', 'details');
function __construct($actions = []) {
$this->actions = $actions;
}
function action_start($new_action) {
if (!empty($this->actions)) {
$last_indx = count($this->actions) - 1;
$last_elem = $this->actions[$last_indx];
if (!array_key_exists('result', $last_elem)) {
$this->actions[$last_indx]['result'] = 'success';
}
}
$this->actions[] = ['action' => $new_action];
}
function action_end($succeeded = true, $details = '') {
if (empty($this->actions)) {
$this->action_start('unknown');
}
$last_indx = count($this->actions) - 1;
if (!empty($details)) {
# convert exceptions to an associative array
if (is_a($details, 'Exception')) {
$details = ['error' => $details->getMessage()];
}
$this->actions[$last_indx]['details'] = $details;
}
$result = $succeeded ? 'success' : 'fail';
$this->actions[$last_indx]['result'] = $result;
}
public function add_note($note, $key = 'note') {
if (empty($this->actions)) {
$this->action_start('unknown');
}
$last_indx = count($this->actions) - 1;
$last_elem = $this->actions[$last_indx];
if (in_array($key, $this->protected_keys)) {
throw new \Exception('Cannot use ' . $key . 'as a note key');
}
if (array_key_exists('result', $last_elem)) {
$this->action_start('unknown');
$last_indx++;
}
$this->actions[$last_indx][$key] = $note;
}
public function actions() {
return $this->actions;
}
}
?>
Back to Directory
File Manager