8000 [Console] fixed PHP comptability · symfony/symfony@38f7a6f · GitHub
[go: up one dir, main page]

Skip to content

Commit 38f7a6f

Browse files
committed
[Console] fixed PHP comptability
1 parent 244d3b8 commit 38f7a6f

File tree

1 file changed

+38
-14
lines changed

1 file changed

+38
-14
lines changed

src/Symfony/Component/Console/Helper/ProgressBar.php

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ class ProgressBar
4444
private $formatLineCount;
4545
private $messages;
4646

47-
static private $formatters;
48-
static private $formats;
47+
private static $formatters;
48+
private static $formats;
4949

5050
/**
5151
* Constructor.
@@ -86,6 +86,18 @@ public static function setPlaceholderFormatterDefinition($name, $callable)
8686
self::$formatters[$name] = $callable;
8787
}
8888

89+
/**
90+
* Gets the placeholder formatter for a given name.
91+
*
92+
* @param string $name The placeholder name (including the delimiter char like %)
93+
*
94+
* @return callable|null A PHP callable
95+
*/
96+
public static function getPlaceholderFormatterDefinition($name)
97+
{
98+
return isset(self::$formatters[$name]) ? self::$formatters[$name] : null;
99+
}
100+
89101
/**
90102
* Sets a format for a given name.
91103
*
@@ -103,6 +115,18 @@ public static function setFormatDefinition($name, $format)
103115
self::$formats[$name] = $format;
104116
}
105117

118+
/**
119+
* Gets the format for a given name.
120+
*
121+
* @param string $name The format name
122+
*
123+
* @return string|null A format string
124+
*/
125+
public static function getFormatDefinition($name)
126+
{
127+
return isset(self::$formats[$name]) ? self::$formats[$name] : null;
128+
}
129+
106130
public function setMessage($message, $name = 'message')
107131
{
108132
$this->messages[$name] = $message;
@@ -116,7 +140,7 @@ public function getMessage($name = 'message')
116140
/**
117141
* Gets the progress bar start time.
118142
*
119-
* @return int The progress bar start time
143+
* @return integer The progress bar start time
120144
*/
121145
public function getStartTime()
122146
{
@@ -126,7 +150,7 @@ public function getStartTime()
126150
/**
127151
* Gets the progress bar maximal steps.
128152
*
129-
* @return int The progress bar max steps
153+
* @return integer The progress bar max steps
130154
*/
131155
public function getMaxSteps()
132156
{
@@ -136,7 +160,7 @@ public function getMaxSteps()
136160
/**
137161
* Gets the progress bar step.
138162
*
139-
* @return int The progress bar step
163+
* @return integer The progress bar step
140164
*/
141165
public function getStep()
142166
{
@@ -146,7 +170,7 @@ public function getStep()
146170
/**
147171
* Gets the progress bar step width.
148172
*
149-
* @return int The progress bar step width
173+
* @return integer The progress bar step width
150174
*/
151175
public function getStepWidth()
152176
{
@@ -156,7 +180,7 @@ public function getStepWidth()
156180
/**
157181
* Gets the current progress bar percent.
158182
*
159-
* @return int The current progress bar percent
183+
* @return integer The current progress bar percent
160184
*/
161185
public function getProgressPercent()
162186
{
@@ -166,7 +190,7 @@ public function getProgressPercent()
166190
/**
167191
* Sets the progress bar width.
168192
*
169-
* @param int $size The progress bar size
193+
* @param integer $size The progress bar size
170194
*/
171195
public function setBarWidth($size)
172196
{
@@ -176,7 +200,7 @@ public function setBarWidth($size)
176200
/**
177201
* Gets the progress bar width.
178202
*
179-
* @return int The progress bar size
203+
* @return integer The progress bar size
180204
*/
181205
public function getBarWidth()
182206
{
@@ -257,7 +281,7 @@ public function setFormat($format)
257281
/**
258282
* Sets the redraw frequency.
259283
*
260-
* @param int $freq The frequency in steps
284+
* @param integer $freq The frequency in steps
261285
*/
262286
public function setRedrawFrequency($freq)
263287
{
@@ -365,8 +389,8 @@ public function display()
365389

366390
$self = $this;
367391
$this->overwrite(preg_replace_callback("{%([a-z\-_]+)(?:\:([^%]+))?%}i", function ($matches) use ($self) {
368-
if (isset(self::$formatters[$matches[1]])) {
369-
$text = call_user_func(self::$formatters[$matches[1]], $self);
392+
if ($formatter = $self::getPlaceholderFormatterDefinition($matches[1])) {
393+
$text = call_user_func($formatter, $self);
370394
} elseif (isset($this->messages[$matches[1]])) {
371395
$text = $this->messages[$matches[1]];
372396
} else {
@@ -433,7 +457,7 @@ private function determineBestFormat()
433457
}
434458
}
435459

436-
static private function initPlaceholderFormatters()
460+
private static function initPlaceholderFormatters()
437461
{
438462
return array(
439463
'bar' => function (ProgressBar $bar) {
@@ -490,7 +514,7 @@ static private function initPlaceholderFormatters()
490514
);
491515
}
492516

493-
static private function initFormats()
517+
private static function initFormats()
494518
{
495519
return array(
496520
'quiet' => ' %percent%%',

0 commit comments

Comments
 (0)
0