public function cliToArray($userCommand = 'post list --format=ids', callable $splitCallback = null)
{
$this->initPaths();
$command = $this->buildCommand($userCommand);
$this->debugSection('command', $command);
$output = $this->executor->execAndOutput($command, $status);
$this->debugSection('output', $output);
$this->evaluateStatus($output, $status);
if (empty($output)) {
return [];
}
$hasSplitCallback = !is_null($splitCallback);
$originalOutput = $output;
if (!is_array($output) || is_array($output) && $hasSplitCallback) {
if (is_array($output)) {
$output = implode(PHP_EOL, $output);
}
if (!$hasSplitCallback) {
if (!preg_match('/[\\n]+/', $output)) {
$output = preg_split('/\\s+/', $output);
} else {
$output = preg_split('/\\s*\\n+\\s*/', $output);
}
} else {
$output = $splitCallback($output, $userCommand, $this);
}
}
if (!is_array($output) && $hasSplitCallback) {
throw new ModuleException(__CLASS__, "Split callback must return an array, it returned: \n" . print_r($output, true) . "\nfor original output:\n" . print_r($originalOutput, true));
}
return empty($output) ? [] : array_map('trim', $output);
}