[Console] fixed PHP comptability
This commit is contained in:
parent
244d3b81be
commit
38f7a6f817
@ -44,8 +44,8 @@ class ProgressBar
|
|||||||
private $formatLineCount;
|
private $formatLineCount;
|
||||||
private $messages;
|
private $messages;
|
||||||
|
|
||||||
static private $formatters;
|
private static $formatters;
|
||||||
static private $formats;
|
private static $formats;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
@ -86,6 +86,18 @@ class ProgressBar
|
|||||||
self::$formatters[$name] = $callable;
|
self::$formatters[$name] = $callable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the placeholder formatter for a given name.
|
||||||
|
*
|
||||||
|
* @param string $name The placeholder name (including the delimiter char like %)
|
||||||
|
*
|
||||||
|
* @return callable|null A PHP callable
|
||||||
|
*/
|
||||||
|
public static function getPlaceholderFormatterDefinition($name)
|
||||||
|
{
|
||||||
|
return isset(self::$formatters[$name]) ? self::$formatters[$name] : null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets a format for a given name.
|
* Sets a format for a given name.
|
||||||
*
|
*
|
||||||
@ -103,6 +115,18 @@ class ProgressBar
|
|||||||
self::$formats[$name] = $format;
|
self::$formats[$name] = $format;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the format for a given name.
|
||||||
|
*
|
||||||
|
* @param string $name The format name
|
||||||
|
*
|
||||||
|
* @return string|null A format string
|
||||||
|
*/
|
||||||
|
public static function getFormatDefinition($name)
|
||||||
|
{
|
||||||
|
return isset(self::$formats[$name]) ? self::$formats[$name] : null;
|
||||||
|
}
|
||||||
|
|
||||||
public function setMessage($message, $name = 'message')
|
public function setMessage($message, $name = 'message')
|
||||||
{
|
{
|
||||||
$this->messages[$name] = $message;
|
$this->messages[$name] = $message;
|
||||||
@ -116,7 +140,7 @@ class ProgressBar
|
|||||||
/**
|
/**
|
||||||
* Gets the progress bar start time.
|
* Gets the progress bar start time.
|
||||||
*
|
*
|
||||||
* @return int The progress bar start time
|
* @return integer The progress bar start time
|
||||||
*/
|
*/
|
||||||
public function getStartTime()
|
public function getStartTime()
|
||||||
{
|
{
|
||||||
@ -126,7 +150,7 @@ class ProgressBar
|
|||||||
/**
|
/**
|
||||||
* Gets the progress bar maximal steps.
|
* Gets the progress bar maximal steps.
|
||||||
*
|
*
|
||||||
* @return int The progress bar max steps
|
* @return integer The progress bar max steps
|
||||||
*/
|
*/
|
||||||
public function getMaxSteps()
|
public function getMaxSteps()
|
||||||
{
|
{
|
||||||
@ -136,7 +160,7 @@ class ProgressBar
|
|||||||
/**
|
/**
|
||||||
* Gets the progress bar step.
|
* Gets the progress bar step.
|
||||||
*
|
*
|
||||||
* @return int The progress bar step
|
* @return integer The progress bar step
|
||||||
*/
|
*/
|
||||||
public function getStep()
|
public function getStep()
|
||||||
{
|
{
|
||||||
@ -146,7 +170,7 @@ class ProgressBar
|
|||||||
/**
|
/**
|
||||||
* Gets the progress bar step width.
|
* Gets the progress bar step width.
|
||||||
*
|
*
|
||||||
* @return int The progress bar step width
|
* @return integer The progress bar step width
|
||||||
*/
|
*/
|
||||||
public function getStepWidth()
|
public function getStepWidth()
|
||||||
{
|
{
|
||||||
@ -156,7 +180,7 @@ class ProgressBar
|
|||||||
/**
|
/**
|
||||||
* Gets the current progress bar percent.
|
* Gets the current progress bar percent.
|
||||||
*
|
*
|
||||||
* @return int The current progress bar percent
|
* @return integer The current progress bar percent
|
||||||
*/
|
*/
|
||||||
public function getProgressPercent()
|
public function getProgressPercent()
|
||||||
{
|
{
|
||||||
@ -166,7 +190,7 @@ class ProgressBar
|
|||||||
/**
|
/**
|
||||||
* Sets the progress bar width.
|
* Sets the progress bar width.
|
||||||
*
|
*
|
||||||
* @param int $size The progress bar size
|
* @param integer $size The progress bar size
|
||||||
*/
|
*/
|
||||||
public function setBarWidth($size)
|
public function setBarWidth($size)
|
||||||
{
|
{
|
||||||
@ -176,7 +200,7 @@ class ProgressBar
|
|||||||
/**
|
/**
|
||||||
* Gets the progress bar width.
|
* Gets the progress bar width.
|
||||||
*
|
*
|
||||||
* @return int The progress bar size
|
* @return integer The progress bar size
|
||||||
*/
|
*/
|
||||||
public function getBarWidth()
|
public function getBarWidth()
|
||||||
{
|
{
|
||||||
@ -257,7 +281,7 @@ class ProgressBar
|
|||||||
/**
|
/**
|
||||||
* Sets the redraw frequency.
|
* Sets the redraw frequency.
|
||||||
*
|
*
|
||||||
* @param int $freq The frequency in steps
|
* @param integer $freq The frequency in steps
|
||||||
*/
|
*/
|
||||||
public function setRedrawFrequency($freq)
|
public function setRedrawFrequency($freq)
|
||||||
{
|
{
|
||||||
@ -365,8 +389,8 @@ class ProgressBar
|
|||||||
|
|
||||||
$self = $this;
|
$self = $this;
|
||||||
$this->overwrite(preg_replace_callback("{%([a-z\-_]+)(?:\:([^%]+))?%}i", function ($matches) use ($self) {
|
$this->overwrite(preg_replace_callback("{%([a-z\-_]+)(?:\:([^%]+))?%}i", function ($matches) use ($self) {
|
||||||
if (isset(self::$formatters[$matches[1]])) {
|
if ($formatter = $self::getPlaceholderFormatterDefinition($matches[1])) {
|
||||||
$text = call_user_func(self::$formatters[$matches[1]], $self);
|
$text = call_user_func($formatter, $self);
|
||||||
} elseif (isset($this->messages[$matches[1]])) {
|
} elseif (isset($this->messages[$matches[1]])) {
|
||||||
$text = $this->messages[$matches[1]];
|
$text = $this->messages[$matches[1]];
|
||||||
} else {
|
} else {
|
||||||
@ -433,7 +457,7 @@ class ProgressBar
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static private function initPlaceholderFormatters()
|
private static function initPlaceholderFormatters()
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
'bar' => function (ProgressBar $bar) {
|
'bar' => function (ProgressBar $bar) {
|
||||||
@ -490,7 +514,7 @@ class ProgressBar
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
static private function initFormats()
|
private static function initFormats()
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
'quiet' => ' %percent%%',
|
'quiet' => ' %percent%%',
|
||||||
|
Reference in New Issue
Block a user