change method sign to static

This commit is contained in:
sunxyw 2022-12-21 21:09:53 +08:00
parent 9da98fde5a
commit 0ee6e43f06
No known key found for this signature in database
GPG Key ID: F391C42B19AFFC98

View File

@ -139,6 +139,27 @@ class ConsoleLogger extends AbstractLogger
return self::VERSION; return self::VERSION;
} }
/**
* 插入字段到指定字段之前,或之后
* @param string $field 字段名
* @param string $alter 要插入的字段
* @param string $position 插入位置before after
*/
public static function alterFormat(string $field, string $alter, string $position = 'before'): void
{
$format = self::$format;
$pos = strpos($format, $field);
if ($pos === false) {
return;
}
if ($position === 'before') {
$format = substr_replace($format, $alter, $pos, 0);
} else {
$format = substr_replace($format, $alter, $pos + strlen($field), 0);
}
self::$format = $format;
}
/** /**
* 添加静态上下文 * 添加静态上下文
*/ */
@ -203,27 +224,6 @@ class ConsoleLogger extends AbstractLogger
return ConsoleColor::apply($styles, $string)->__toString(); return ConsoleColor::apply($styles, $string)->__toString();
} }
/**
* 插入字段到指定字段之前,或之后
* @param string $field 字段名
* @param string $alter 要插入的字段
* @param string $position 插入位置before after
*/
public function alterFormat(string $field, string $alter, string $position = 'before'): void
{
$format = self::$format;
$pos = strpos($format, $field);
if ($pos === false) {
return;
}
if ($position === 'before') {
$format = substr_replace($format, $alter, $pos, 0);
} else {
$format = substr_replace($format, $alter, $pos + strlen($field), 0);
}
self::$format = $format;
}
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */