modifs.mineures sans commentaires
This commit is contained in:
parent
888dd6be1a
commit
f6c15f130a
|
@ -10,6 +10,11 @@ interface IMessenger {
|
||||||
/** réinitialiser les paramètres de l'objet */
|
/** réinitialiser les paramètres de l'objet */
|
||||||
function resetParams(?array $params=null): void;
|
function resetParams(?array $params=null): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* créer une copie de cet objet avec éventuellement des paramètres différents
|
||||||
|
*/
|
||||||
|
function clone(?array $params=null): self;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* commencer une section.
|
* commencer une section.
|
||||||
*
|
*
|
||||||
|
|
|
@ -2,11 +2,6 @@
|
||||||
|
|
||||||
## TOOD
|
## TOOD
|
||||||
|
|
||||||
* [ ] ProxyMessenger, vers un ou plusieurs messengers
|
|
||||||
* [ ] support sous-système (instance locale ou globale)
|
|
||||||
* [ ] msg::push() --> nouvelle instance globale
|
|
||||||
* [ ] msg::get() --> nouvelle instance locale
|
|
||||||
* [ ] support `add_date` et `date_format`
|
|
||||||
* [ ] affichage des exceptions en message technique.
|
* [ ] affichage des exceptions en message technique.
|
||||||
si pas de message, prendre le message de l'exception par défaut
|
si pas de message, prendre le message de l'exception par défaut
|
||||||
* [ ] possibilité de paramétrer le nom du fichier destination pour faire une
|
* [ ] possibilité de paramétrer le nom du fichier destination pour faire une
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
<?php
|
<?php
|
||||||
namespace nur\sery\output;
|
namespace nur\sery\output;
|
||||||
|
|
||||||
use nulib\ValueException;
|
|
||||||
use nulib\str;
|
use nulib\str;
|
||||||
|
use nulib\ValueException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class _messenger: classe de base pour say, log et msg
|
* Class _messenger: classe de base pour say, log et msg
|
||||||
|
@ -32,14 +32,35 @@ abstract class _messenger {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @return IMessenger[] */
|
abstract static function get(): IMessenger;
|
||||||
abstract static function get_msgs(): array;
|
|
||||||
|
/** obtenir une nouvelle instance, avec un nouveau paramétrage */
|
||||||
|
static function new(?array $params=null): IMessenger {
|
||||||
|
return static::get()->clone($params);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @var IMessenger */
|
||||||
|
protected static $msg;
|
||||||
|
|
||||||
|
/** @var IMessenger[] */
|
||||||
|
protected static $stack;
|
||||||
|
|
||||||
|
/** pousser une nouvelle instance avec un nouveau paramétrage sur la pile */
|
||||||
|
static function push(?array $params=null) {
|
||||||
|
self::$stack[] = static::get();
|
||||||
|
self::$msg = self::new($params);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** dépiler la précédente instance */
|
||||||
|
static function pop(): IMessenger {
|
||||||
|
if (self::$stack) $msg = self::$msg = array_pop(self::$stack);
|
||||||
|
else $msg = self::$msg;
|
||||||
|
return $msg;
|
||||||
|
}
|
||||||
|
|
||||||
static final function __callStatic($name, $args) {
|
static final function __callStatic($name, $args) {
|
||||||
$name = str::us2camel($name);
|
$name = str::us2camel($name);
|
||||||
foreach (static::get_msgs() as $msg) {
|
call_user_func_array([static::get(), $name], $args);
|
||||||
call_user_func_array([$msg, $name], $args);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#############################################################################
|
#############################################################################
|
||||||
|
@ -49,24 +70,24 @@ abstract class _messenger {
|
||||||
const MAJOR = IMessenger::LEVEL_MAJOR;
|
const MAJOR = IMessenger::LEVEL_MAJOR;
|
||||||
const NONE = IMessenger::LEVEL_NONE;
|
const NONE = IMessenger::LEVEL_NONE;
|
||||||
|
|
||||||
static function reset_params(?array $params) { foreach (static::get_msgs() as $msg) { $msg->resetParams($params); } }
|
static function reset_params(?array $params=null): void { static::get()->resetParams($params); }
|
||||||
function section($content, ?int $level=null): void { foreach (static::get_msgs() as $msg) { $msg->section($content, $level); } }
|
static function section($content, ?int $level=null): void { static::get()->section($content, $level); }
|
||||||
function title($content, ?int $level=null): void { foreach (static::get_msgs() as $msg) { $msg->title($content, $level); } }
|
static function title($content, ?int $level=null): void { static::get()->title($content, $level); }
|
||||||
function desc($content, ?int $level=null): void { foreach (static::get_msgs() as $msg) { $msg->desc($content, $level); } }
|
static function desc($content, ?int $level=null): void { static::get()->desc($content, $level); }
|
||||||
function action($content, ?int $level=null): void { foreach (static::get_msgs() as $msg) { $msg->action($content, $level); } }
|
static function action($content, ?int $level=null): void { static::get()->action($content, $level); }
|
||||||
function step($content, ?int $level=null): void { foreach (static::get_msgs() as $msg) { $msg->step($content, $level); } }
|
static function step($content, ?int $level=null): void { static::get()->step($content, $level); }
|
||||||
function asuccess($content=null): void { foreach (static::get_msgs() as $msg) { $msg->asuccess($content); } }
|
static function asuccess($content=null): void { static::get()->asuccess($content); }
|
||||||
function afailure($content=null): void { foreach (static::get_msgs() as $msg) { $msg->afailure($content); } }
|
static function afailure($content=null): void { static::get()->afailure($content); }
|
||||||
function adone($content=null): void { foreach (static::get_msgs() as $msg) { $msg->adone($content); } }
|
static function adone($content=null): void { static::get()->adone($content); }
|
||||||
function print($content, ?int $level=null): void { foreach (static::get_msgs() as $msg) { $msg->print($content, $level); } }
|
static function print($content, ?int $level=null): void { static::get()->print($content, $level); }
|
||||||
function info($content, ?int $level=null): void { foreach (static::get_msgs() as $msg) { $msg->info($content, $level); } }
|
static function info($content, ?int $level=null): void { static::get()->info($content, $level); }
|
||||||
function note($content, ?int $level=null): void { foreach (static::get_msgs() as $msg) { $msg->note($content, $level); } }
|
static function note($content, ?int $level=null): void { static::get()->note($content, $level); }
|
||||||
function warn($content, ?int $level=null): void { foreach (static::get_msgs() as $msg) { $msg->warn($content, $level); } }
|
static function warn($content, ?int $level=null): void { static::get()->warn($content, $level); }
|
||||||
function error($content, ?int $level=null): void { foreach (static::get_msgs() as $msg) { $msg->error($content, $level); } }
|
static function error($content, ?int $level=null): void { static::get()->error($content, $level); }
|
||||||
function debug($content): void { self::info($content, self::DEBUG);}
|
static function debug($content): void { self::info($content, self::DEBUG);}
|
||||||
function important($content): void { self::info($content, self::MAJOR);}
|
static function important($content): void { self::info($content, self::MAJOR);}
|
||||||
function attention($content): void { self::note($content, self::MAJOR);}
|
static function attention($content): void { self::note($content, self::MAJOR);}
|
||||||
function critical_warn($content): void { self::warn($content, self::MAJOR);}
|
static function critwarn($content): void { self::warn($content, self::MAJOR);}
|
||||||
function critical_error($content): void { self::error($content, self::MAJOR);}
|
static function criterror($content): void { self::error($content, self::MAJOR);}
|
||||||
function end(bool $all=false): void { foreach (static::get_msgs() as $msg) { $msg->end($all); } }
|
static function end(bool $all=false): void { static::get()->end($all); }
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,18 @@
|
||||||
<?php
|
<?php
|
||||||
namespace nur\sery\output;
|
namespace nur\sery\output;
|
||||||
|
|
||||||
|
use nur\sery\output\std\ProxyMessenger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class log: inscrire un message dans les logs uniquement
|
* Class log: inscrire un message dans les logs uniquement
|
||||||
*/
|
*/
|
||||||
class log extends _messenger {
|
class log extends _messenger {
|
||||||
static function get_msgs(): array {
|
static function get(): IMessenger {
|
||||||
$log = self::$log;
|
if (self::$msg === null) {
|
||||||
return $log !== null? [$log]: [];
|
$msg = self::$log;
|
||||||
|
if ($msg === null) $msg = new ProxyMessenger();
|
||||||
|
self::$msg = $msg;
|
||||||
|
}
|
||||||
|
return self::$msg;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,16 +1,22 @@
|
||||||
<?php
|
<?php
|
||||||
namespace nur\sery\output;
|
namespace nur\sery\output;
|
||||||
|
|
||||||
|
use nur\sery\output\std\ProxyMessenger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class msg: inscrire un message dans les logs ET l'afficher sur la console
|
* Class msg: inscrire un message dans les logs ET l'afficher sur la console
|
||||||
*/
|
*/
|
||||||
class msg extends _messenger {
|
class msg extends _messenger {
|
||||||
static function get_msgs(): array {
|
static function get(): IMessenger {
|
||||||
$msgs = [];
|
if (self::$msg === null) {
|
||||||
$log = self::$log;
|
$log = self::$log;
|
||||||
if ($log !== null) $msgs[] = $log;
|
$say = self::$say;
|
||||||
$say = self::$say;
|
if ($log !== null && $say !== null) $msg = new ProxyMessenger($log, $say);
|
||||||
if ($say !== null) $msgs[] = $say;
|
elseif ($log !== null) $msg = $log;
|
||||||
return $msgs;
|
elseif ($say !== null) $msg = $say;
|
||||||
|
else $msg = new ProxyMessenger();
|
||||||
|
self::$msg = $msg;
|
||||||
|
}
|
||||||
|
return self::$msg;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,18 @@
|
||||||
<?php
|
<?php
|
||||||
namespace nur\sery\output;
|
namespace nur\sery\output;
|
||||||
|
|
||||||
|
use nur\sery\output\std\ProxyMessenger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class say: afficher un message sur la console uniquement
|
* Class say: afficher un message sur la console uniquement
|
||||||
*/
|
*/
|
||||||
class say extends _messenger {
|
class say extends _messenger {
|
||||||
static function get_msgs(): array {
|
static function get(): IMessenger {
|
||||||
$say = self::$say;
|
if (self::$msg === null) {
|
||||||
return $say !== null? [$say]: [];
|
$msg = self::$say;
|
||||||
|
if ($msg === null) $msg = new ProxyMessenger();
|
||||||
|
self::$msg = $msg;
|
||||||
|
}
|
||||||
|
return self::$msg;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,42 @@
|
||||||
|
<?php
|
||||||
|
namespace nur\sery\output\std;
|
||||||
|
|
||||||
|
use nur\sery\output\IMessenger;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class ProxyMessenger: un proxy vers ou un plusieurs instances de IMessenger
|
||||||
|
*/
|
||||||
|
class ProxyMessenger implements IMessenger {
|
||||||
|
function __construct(?IMessenger ...$msgs) {
|
||||||
|
$this->msgs = [];
|
||||||
|
foreach ($msgs as $msg) {
|
||||||
|
if ($msg !== null) $this->msgs[] = $msg;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @var IMessenger[] */
|
||||||
|
protected $msgs;
|
||||||
|
|
||||||
|
function resetParams(?array $params=null): void { foreach ($this->msgs as $msg) { $msg->resetParams($params); } }
|
||||||
|
function clone(?array $params=null): self {
|
||||||
|
$clone = clone $this;
|
||||||
|
foreach ($clone->msgs as &$msg) {
|
||||||
|
$msg = $msg->clone($params);
|
||||||
|
}; unset($msg);
|
||||||
|
return $clone;
|
||||||
|
}
|
||||||
|
function section($content, ?int $level=null): void { foreach ($this->msgs as $msg) { $msg->section($content, $level); } }
|
||||||
|
function title($content, ?int $level=null): void { foreach ($this->msgs as $msg) { $msg->title($content, $level); } }
|
||||||
|
function desc($content, ?int $level=null): void { foreach ($this->msgs as $msg) { $msg->desc($content, $level); } }
|
||||||
|
function action($content, ?int $level=null): void { foreach ($this->msgs as $msg) { $msg->action($content, $level); } }
|
||||||
|
function step($content, ?int $level=null): void { foreach ($this->msgs as $msg) { $msg->step($content, $level); } }
|
||||||
|
function asuccess($content=null): void { foreach ($this->msgs as $msg) { $msg->asuccess($content); } }
|
||||||
|
function afailure($content=null): void { foreach ($this->msgs as $msg) { $msg->afailure($content); } }
|
||||||
|
function adone($content=null): void { foreach ($this->msgs as $msg) { $msg->adone($content); } }
|
||||||
|
function print($content, ?int $level=null): void { foreach ($this->msgs as $msg) { $msg->print($content, $level); } }
|
||||||
|
function info($content, ?int $level=null): void { foreach ($this->msgs as $msg) { $msg->info($content, $level); } }
|
||||||
|
function note($content, ?int $level=null): void { foreach ($this->msgs as $msg) { $msg->note($content, $level); } }
|
||||||
|
function warn($content, ?int $level=null): void { foreach ($this->msgs as $msg) { $msg->warn($content, $level); } }
|
||||||
|
function error($content, ?int $level=null): void { foreach ($this->msgs as $msg) { $msg->error($content, $level); } }
|
||||||
|
function end(bool $all=false): void { foreach ($this->msgs as $msg) { $msg->end($all); } }
|
||||||
|
}
|
|
@ -7,6 +7,7 @@ use nur\sery\output\IMessenger;
|
||||||
|
|
||||||
class StdMessenger implements IMessenger {
|
class StdMessenger implements IMessenger {
|
||||||
const INDENT = " ";
|
const INDENT = " ";
|
||||||
|
const DATE_FORMAT = 'Y-m-d\TH:i:s.u';
|
||||||
|
|
||||||
const VALID_LEVELS = [
|
const VALID_LEVELS = [
|
||||||
self::LEVEL_DEBUG,
|
self::LEVEL_DEBUG,
|
||||||
|
@ -92,6 +93,10 @@ class StdMessenger implements IMessenger {
|
||||||
if ($minLevel === null) $minLevel = self::LEVEL_NORMAL;
|
if ($minLevel === null) $minLevel = self::LEVEL_NORMAL;
|
||||||
$minLevel = self::verifix_level($minLevel, self::LEVEL_NONE);
|
$minLevel = self::verifix_level($minLevel, self::LEVEL_NONE);
|
||||||
|
|
||||||
|
$addDate = boolval(cl::get($params, "add_date"));
|
||||||
|
$dateFormat = cl::get($params, "date_format", static::DATE_FORMAT);
|
||||||
|
$id = cl::get($params, "id");
|
||||||
|
|
||||||
$params = [
|
$params = [
|
||||||
"color" => $color,
|
"color" => $color,
|
||||||
"indent" => $indent,
|
"indent" => $indent,
|
||||||
|
@ -104,11 +109,12 @@ class StdMessenger implements IMessenger {
|
||||||
}
|
}
|
||||||
$this->defaultLevel = $defaultLevel;
|
$this->defaultLevel = $defaultLevel;
|
||||||
$this->minLevel = $minLevel;
|
$this->minLevel = $minLevel;
|
||||||
|
$this->addDate = $addDate;
|
||||||
|
$this->dateFormat = $dateFormat;
|
||||||
|
$this->id = $id;
|
||||||
$this->inSection = false;
|
$this->inSection = false;
|
||||||
$this->titles = [];
|
$this->titles = [];
|
||||||
$this->title = null;
|
|
||||||
$this->actions = [];
|
$this->actions = [];
|
||||||
$this->action = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function resetParams(?array $params=null): void {
|
function resetParams(?array $params=null): void {
|
||||||
|
@ -125,6 +131,10 @@ class StdMessenger implements IMessenger {
|
||||||
if ($minLevel === null) $minLevel = cl::get($params, "verbosity"); # alias
|
if ($minLevel === null) $minLevel = cl::get($params, "verbosity"); # alias
|
||||||
if ($minLevel !== null) $minLevel = self::verifix_level($minLevel, self::LEVEL_NONE);
|
if ($minLevel !== null) $minLevel = self::verifix_level($minLevel, self::LEVEL_NONE);
|
||||||
|
|
||||||
|
$addDate = cl::get($params, "add_date");
|
||||||
|
$dateFormat = cl::get($params, "date_format");
|
||||||
|
$id = cl::get($params, "id");
|
||||||
|
|
||||||
$params = [
|
$params = [
|
||||||
"output" => $output,
|
"output" => $output,
|
||||||
"color" => $color,
|
"color" => $color,
|
||||||
|
@ -138,6 +148,19 @@ class StdMessenger implements IMessenger {
|
||||||
}
|
}
|
||||||
if ($defaultLevel !== null) $this->defaultLevel = $defaultLevel;
|
if ($defaultLevel !== null) $this->defaultLevel = $defaultLevel;
|
||||||
if ($minLevel !== null) $this->minLevel = $minLevel;
|
if ($minLevel !== null) $this->minLevel = $minLevel;
|
||||||
|
if ($addDate !== null) $this->addDate = boolval($addDate);
|
||||||
|
if ($dateFormat !== null) $this->dateFormat = $dateFormat;
|
||||||
|
if ($id !== null) $this->id = $id;
|
||||||
|
}
|
||||||
|
|
||||||
|
function clone(?array $params=null): IMessenger {
|
||||||
|
$clone = clone $this;
|
||||||
|
if ($params !== null) $clone->resetParams($params);
|
||||||
|
#XXX faut-il marquer la section et les titres du clone à "print" => false?
|
||||||
|
# ou en faire des références au parent?
|
||||||
|
# dans tous les cas, on considère qu'il n'y a pas d'actions en cours, et on
|
||||||
|
# ne doit pas dépiler avec end() plus que l'état que l'on a eu lors du clone
|
||||||
|
return $clone;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @var StdOutput la sortie standard */
|
/** @var StdOutput la sortie standard */
|
||||||
|
@ -152,12 +175,35 @@ class StdMessenger implements IMessenger {
|
||||||
/** @var int level minimum que doivent avoir les messages pour être affichés */
|
/** @var int level minimum que doivent avoir les messages pour être affichés */
|
||||||
protected $minLevel;
|
protected $minLevel;
|
||||||
|
|
||||||
|
/** @var bool faut-il ajouter la date à chaque ligne? */
|
||||||
|
protected $addDate;
|
||||||
|
|
||||||
|
/** @var string format de la date */
|
||||||
|
protected $dateFormat;
|
||||||
|
|
||||||
|
/** @var ?string identifiant de ce messenger, à ajouter à chaque ligne */
|
||||||
|
protected $id;
|
||||||
|
|
||||||
|
protected function getLinePrefix(): ?string {
|
||||||
|
$linePrefix = null;
|
||||||
|
if ($this->addDate) {
|
||||||
|
$date = date_create()->format($this->dateFormat);
|
||||||
|
$linePrefix .= "$date ";
|
||||||
|
}
|
||||||
|
if ($this->id !== null) {
|
||||||
|
$linePrefix .= "$this->id ";
|
||||||
|
}
|
||||||
|
return $linePrefix;
|
||||||
|
}
|
||||||
|
|
||||||
protected function checkLevel(?int &$level): bool {
|
protected function checkLevel(?int &$level): bool {
|
||||||
if ($level === null) $level = $this->defaultLevel;
|
if ($level === null) $level = $this->defaultLevel;
|
||||||
return $level >= $this->minLevel;
|
return $level >= $this->minLevel;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function _printTitle(int $level, string $type, $content, int $indentLevel, StdOutput $out): void {
|
protected function _printTitle(?string $linePrefix, int $level,
|
||||||
|
string $type, $content,
|
||||||
|
int $indentLevel, StdOutput $out): void {
|
||||||
$prefixes = self::GENERIC_PREFIXES[$level][$type];
|
$prefixes = self::GENERIC_PREFIXES[$level][$type];
|
||||||
if ($prefixes[0]) $out->print();
|
if ($prefixes[0]) $out->print();
|
||||||
if ($out->isColor()) {
|
if ($out->isColor()) {
|
||||||
|
@ -177,13 +223,16 @@ class StdMessenger implements IMessenger {
|
||||||
$content = [$content, $len];
|
$content = [$content, $len];
|
||||||
}; unset($content);
|
}; unset($content);
|
||||||
if ($before !== null) {
|
if ($before !== null) {
|
||||||
|
if ($linePrefix !== null) $out->write($linePrefix);
|
||||||
$out->iprint($indentLevel, $prefix, substr($before, 1), str_repeat($before[0], $maxlen), $suffix);
|
$out->iprint($indentLevel, $prefix, substr($before, 1), str_repeat($before[0], $maxlen), $suffix);
|
||||||
}
|
}
|
||||||
foreach ($lines as [$content, $len]) {
|
foreach ($lines as [$content, $len]) {
|
||||||
|
if ($linePrefix !== null) $out->write($linePrefix);
|
||||||
$padding = $len < $maxlen? str_repeat(" ", $maxlen - $len): null;
|
$padding = $len < $maxlen? str_repeat(" ", $maxlen - $len): null;
|
||||||
$out->iprint($indentLevel, $prefix2, $content, $padding, $suffix2);
|
$out->iprint($indentLevel, $prefix2, $content, $padding, $suffix2);
|
||||||
}
|
}
|
||||||
if ($after !== null) {
|
if ($after !== null) {
|
||||||
|
if ($linePrefix !== null) $out->write($linePrefix);
|
||||||
$out->iprint($indentLevel, $prefix, substr($after, 1), str_repeat($after[0], $maxlen), $suffix);
|
$out->iprint($indentLevel, $prefix, substr($after, 1), str_repeat($after[0], $maxlen), $suffix);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -192,13 +241,14 @@ class StdMessenger implements IMessenger {
|
||||||
$prefix2 = str_repeat(" ", mb_strlen($prefix));
|
$prefix2 = str_repeat(" ", mb_strlen($prefix));
|
||||||
$lines = $out->getLines(false, $content);
|
$lines = $out->getLines(false, $content);
|
||||||
foreach ($lines as $content) {
|
foreach ($lines as $content) {
|
||||||
|
if ($linePrefix !== null) $out->write($linePrefix);
|
||||||
$out->iprint($indentLevel, $prefix, $content);
|
$out->iprint($indentLevel, $prefix, $content);
|
||||||
$prefix = $prefix2;
|
$prefix = $prefix2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function _printAction(int $level,
|
protected function _printAction(?string $linePrefix, int $level,
|
||||||
bool $printContent, $content,
|
bool $printContent, $content,
|
||||||
bool $printResult, ?bool $rsuccess, $rcontent,
|
bool $printResult, ?bool $rsuccess, $rcontent,
|
||||||
int $indentLevel, StdOutput $out): void {
|
int $indentLevel, StdOutput $out): void {
|
||||||
|
@ -228,6 +278,7 @@ class StdMessenger implements IMessenger {
|
||||||
}
|
}
|
||||||
$lines = $out->getLines(false, $content);
|
$lines = $out->getLines(false, $content);
|
||||||
foreach ($lines as $content) {
|
foreach ($lines as $content) {
|
||||||
|
if ($linePrefix !== null) $out->write($linePrefix);
|
||||||
$out->iprint($indentLevel, $rprefix, $content);
|
$out->iprint($indentLevel, $rprefix, $content);
|
||||||
$rprefix = $rprefix2;
|
$rprefix = $rprefix2;
|
||||||
}
|
}
|
||||||
|
@ -247,6 +298,7 @@ class StdMessenger implements IMessenger {
|
||||||
}
|
}
|
||||||
$lines = $out->getLines(false, $content, ":");
|
$lines = $out->getLines(false, $content, ":");
|
||||||
foreach ($lines as $content) {
|
foreach ($lines as $content) {
|
||||||
|
if ($linePrefix !== null) $out->write($linePrefix);
|
||||||
$out->iprint($indentLevel, $prefix, $content, $suffix);
|
$out->iprint($indentLevel, $prefix, $content, $suffix);
|
||||||
$prefix = $prefix2;
|
$prefix = $prefix2;
|
||||||
}
|
}
|
||||||
|
@ -260,6 +312,7 @@ class StdMessenger implements IMessenger {
|
||||||
$rprefix2 = " $rprefix2";
|
$rprefix2 = " $rprefix2";
|
||||||
$lines = $out->getLines(false, $rcontent);
|
$lines = $out->getLines(false, $rcontent);
|
||||||
foreach ($lines as $rcontent) {
|
foreach ($lines as $rcontent) {
|
||||||
|
if ($linePrefix !== null) $out->write($linePrefix);
|
||||||
$out->iprint($indentLevel, $rprefix, $rcontent);
|
$out->iprint($indentLevel, $rprefix, $rcontent);
|
||||||
$rprefix = $rprefix2;
|
$rprefix = $rprefix2;
|
||||||
}
|
}
|
||||||
|
@ -267,6 +320,7 @@ class StdMessenger implements IMessenger {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function _printGeneric(int $level, string $type, $content, int $indentLevel, StdOutput $out): void {
|
protected function _printGeneric(int $level, string $type, $content, int $indentLevel, StdOutput $out): void {
|
||||||
|
$linePrefix = $this->getLinePrefix();
|
||||||
$prefixes = self::GENERIC_PREFIXES[$level][$type];
|
$prefixes = self::GENERIC_PREFIXES[$level][$type];
|
||||||
if ($out->isColor()) {
|
if ($out->isColor()) {
|
||||||
$prefix = $prefixes[1];
|
$prefix = $prefixes[1];
|
||||||
|
@ -279,6 +333,7 @@ class StdMessenger implements IMessenger {
|
||||||
$suffix = $prefixes[2];
|
$suffix = $prefixes[2];
|
||||||
$lines = $out->getLines(false, $content);
|
$lines = $out->getLines(false, $content);
|
||||||
foreach ($lines as $content) {
|
foreach ($lines as $content) {
|
||||||
|
if ($linePrefix !== null) $out->write($linePrefix);
|
||||||
$out->iprint($indentLevel, $prefix, $content, $suffix);
|
$out->iprint($indentLevel, $prefix, $content, $suffix);
|
||||||
$prefix = $prefix2;
|
$prefix = $prefix2;
|
||||||
}
|
}
|
||||||
|
@ -288,6 +343,7 @@ class StdMessenger implements IMessenger {
|
||||||
$prefix2 = str_repeat(" ", mb_strlen($prefix));
|
$prefix2 = str_repeat(" ", mb_strlen($prefix));
|
||||||
$lines = $out->getLines(false, $content);
|
$lines = $out->getLines(false, $content);
|
||||||
foreach ($lines as $content) {
|
foreach ($lines as $content) {
|
||||||
|
if ($linePrefix !== null) $out->write($linePrefix);
|
||||||
$out->iprint($indentLevel, $prefix, $content);
|
$out->iprint($indentLevel, $prefix, $content);
|
||||||
$prefix = $prefix2;
|
$prefix = $prefix2;
|
||||||
}
|
}
|
||||||
|
@ -305,6 +361,7 @@ class StdMessenger implements IMessenger {
|
||||||
$this->inSection = true;
|
$this->inSection = true;
|
||||||
if (!$this->checkLevel($level)) return;
|
if (!$this->checkLevel($level)) return;
|
||||||
$this->section = [
|
$this->section = [
|
||||||
|
"line_prefix" => $this->getLinePrefix(),
|
||||||
"level" => $level,
|
"level" => $level,
|
||||||
"content" => $content,
|
"content" => $content,
|
||||||
"print_content" => true,
|
"print_content" => true,
|
||||||
|
@ -314,7 +371,10 @@ class StdMessenger implements IMessenger {
|
||||||
protected function printSection() {
|
protected function printSection() {
|
||||||
$section =& $this->section;
|
$section =& $this->section;
|
||||||
if ($section["print_content"]) {
|
if ($section["print_content"]) {
|
||||||
$this->_printTitle($section["level"], "section", $section["content"], 0, $this->err);
|
$this->_printTitle(
|
||||||
|
$section["line_prefix"], $section["level"],
|
||||||
|
"section", $section["content"],
|
||||||
|
0, $this->err);
|
||||||
$section["print_content"] = false;
|
$section["print_content"] = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -345,6 +405,7 @@ class StdMessenger implements IMessenger {
|
||||||
function title($content, ?int $level=null): void {
|
function title($content, ?int $level=null): void {
|
||||||
if (!$this->checkLevel($level)) return;
|
if (!$this->checkLevel($level)) return;
|
||||||
$this->titles[] = [
|
$this->titles[] = [
|
||||||
|
"line_prefix" => $this->getLinePrefix(),
|
||||||
"level" => $level,
|
"level" => $level,
|
||||||
"content" => $content,
|
"content" => $content,
|
||||||
"print_content" => true,
|
"print_content" => true,
|
||||||
|
@ -358,6 +419,7 @@ class StdMessenger implements IMessenger {
|
||||||
if (!$this->checkLevel($level)) return;
|
if (!$this->checkLevel($level)) return;
|
||||||
$title =& $this->title;
|
$title =& $this->title;
|
||||||
$title["descs"][] = [
|
$title["descs"][] = [
|
||||||
|
"line_prefix" => $this->getLinePrefix(),
|
||||||
"level" => $level,
|
"level" => $level,
|
||||||
"content" => $content,
|
"content" => $content,
|
||||||
];
|
];
|
||||||
|
@ -370,7 +432,10 @@ class StdMessenger implements IMessenger {
|
||||||
$indentLevel = 0;
|
$indentLevel = 0;
|
||||||
foreach ($this->titles as &$title) {
|
foreach ($this->titles as &$title) {
|
||||||
if ($title["print_content"]) {
|
if ($title["print_content"]) {
|
||||||
$this->_printTitle($title["level"], "title", $title["content"], $indentLevel, $err);
|
$this->_printTitle(
|
||||||
|
$title["line_prefix"], $title["level"],
|
||||||
|
"title", $title["content"],
|
||||||
|
$indentLevel, $err);
|
||||||
$title["print_content"] = false;
|
$title["print_content"] = false;
|
||||||
}
|
}
|
||||||
if ($title["print_descs"]) {
|
if ($title["print_descs"]) {
|
||||||
|
@ -403,6 +468,7 @@ class StdMessenger implements IMessenger {
|
||||||
function action($content, ?int $level=null): void {
|
function action($content, ?int $level=null): void {
|
||||||
$this->checkLevel($level);
|
$this->checkLevel($level);
|
||||||
$this->actions[] = [
|
$this->actions[] = [
|
||||||
|
"line_prefix" => $this->getLinePrefix(),
|
||||||
"level" => $level,
|
"level" => $level,
|
||||||
"content" => $content,
|
"content" => $content,
|
||||||
"print_content" => true,
|
"print_content" => true,
|
||||||
|
@ -420,15 +486,24 @@ class StdMessenger implements IMessenger {
|
||||||
$index = 0;
|
$index = 0;
|
||||||
foreach ($this->actions as &$action) {
|
foreach ($this->actions as &$action) {
|
||||||
$mergeResult = $index++ == $lastIndex && $willEnd;
|
$mergeResult = $index++ == $lastIndex && $willEnd;
|
||||||
|
$linePrefix = $action["line_prefix"];
|
||||||
$level = $action["level"];
|
$level = $action["level"];
|
||||||
$content = $action["content"];
|
$content = $action["content"];
|
||||||
$printContent = $action["print_content"];
|
$printContent = $action["print_content"];
|
||||||
$rsuccess = $action["result_success"];
|
$rsuccess = $action["result_success"];
|
||||||
$rcontent = $action["result_content"];
|
$rcontent = $action["result_content"];
|
||||||
if ($mergeResult) {
|
if ($mergeResult) {
|
||||||
$this->_printAction($level, $printContent, $content, true, $rsuccess, $rcontent, $indentLevel, $err);
|
$this->_printAction(
|
||||||
|
$linePrefix, $level,
|
||||||
|
$printContent, $content,
|
||||||
|
true, $rsuccess, $rcontent,
|
||||||
|
$indentLevel, $err);
|
||||||
} elseif ($printContent) {
|
} elseif ($printContent) {
|
||||||
$this->_printAction($level, $printContent, $content, false, $rsuccess, $rcontent, $indentLevel, $err);
|
$this->_printAction(
|
||||||
|
$linePrefix, $level,
|
||||||
|
$printContent, $content,
|
||||||
|
false, $rsuccess, $rcontent,
|
||||||
|
$indentLevel, $err);
|
||||||
$action["print_content"] = false;
|
$action["print_content"] = false;
|
||||||
}
|
}
|
||||||
$indentLevel++;
|
$indentLevel++;
|
||||||
|
|
|
@ -34,6 +34,13 @@ for ($i = 1; $i <= $count; $i++) {
|
||||||
case "-M":
|
case "-M":
|
||||||
$params["default_level"] = "major";
|
$params["default_level"] = "major";
|
||||||
break;
|
break;
|
||||||
|
case "-i":
|
||||||
|
$i++;
|
||||||
|
$params["id"] = $argv[$i];
|
||||||
|
break;
|
||||||
|
case "-t":
|
||||||
|
$params["add_date"] = true;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$c = new StdMessenger($params);
|
$c = new StdMessenger($params);
|
||||||
|
|
Loading…
Reference in New Issue