@@ -44,8 +44,8 @@ class ProgressBar
44
44
private $ formatLineCount ;
45
45
private $ messages ;
46
46
47
- static private $ formatters ;
48
- static private $ formats ;
47
+ private static $ formatters ;
48
+ private static $ formats ;
49
49
50
50
/**
51
51
* Constructor.
@@ -86,6 +86,18 @@ public static function setPlaceholderFormatterDefinition($name, $callable)
86
86
self ::$ formatters [$ name ] = $ callable ;
87
87
}
88
88
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
+
89
101
/**
90
102
* Sets a format for a given name.
91
103
*
@@ -103,6 +115,18 @@ public static function setFormatDefinition($name, $format)
103
115
self ::$ formats [$ name ] = $ format ;
104
116
}
105
117
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
+
106
130
public function setMessage ($ message , $ name = 'message ' )
107
131
{
108
132
$ this ->messages [$ name ] = $ message ;
@@ -116,7 +140,7 @@ public function getMessage($name = 'message')
116
140
/**
117
141
* Gets the progress bar start time.
118
142
*
119
- * @return int The progress bar start time
143
+ * @return integer The progress bar start time
120
144
*/
121
145
public function getStartTime ()
122
146
{
@@ -126,7 +150,7 @@ public function getStartTime()
126
150
/**
127
151
* Gets the progress bar maximal steps.
128
152
*
129
- * @return int The progress bar max steps
153
+ * @return integer The progress bar max steps
130
154
*/
131
155
public function getMaxSteps ()
132
156
{
@@ -136,7 +160,7 @@ public function getMaxSteps()
136
160
/**
137
161
* Gets the progress bar step.
138
162
*
139
- * @return int The progress bar step
163
+ * @return integer The progress bar step
140
164
*/
141
165
public function getStep ()
142
166
{
@@ -146,7 +170,7 @@ public function getStep()
146
170
/**
147
171
* Gets the progress bar step width.
148
172
*
149
- * @return int The progress bar step width
173
+ * @return integer The progress bar step width
150
174
*/
151
175
public function getStepWidth ()
152
176
{
@@ -156,7 +180,7 @@ public function getStepWidth()
156
180
/**
157
181
* Gets the current progress bar percent.
158
182
*
159
- * @return int The current progress bar percent
183
+ * @return integer The current progress bar percent
160
184
*/
161
185
public function getProgressPercent ()
162
186
{
@@ -166,7 +190,7 @@ public function getProgressPercent()
166
190
/**
167
191
* Sets the progress bar width.
168
192
*
169
- * @param int $size The progress bar size
193
+ * @param integer $size The progress bar size
170
194
*/
171
195
public function setBarWidth ($ size )
172
196
{
@@ -176,7 +200,7 @@ public function setBarWidth($size)
176
200
/**
177
201
* Gets the progress bar width.
178
202
*
179
- * @return int The progress bar size
203
+ * @return integer The progress bar size
180
204
*/
181
205
public function getBarWidth ()
182
206
{
@@ -257,7 +281,7 @@ public function setFormat($format)
257
281
/**
258
282
* Sets the redraw frequency.
259
283
*
260
- * @param int $freq The frequency in steps
284
+ * @param integer $freq The frequency in steps
261
285
*/
262
286
public function setRedrawFrequency ($ freq )
263
287
{
@@ -365,8 +389,8 @@ public function display()
365
389
366
390
$ self = $ this ;
367
391
$ 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 );
370
394
} elseif (isset ($ this ->messages [$ matches [1 ]])) {
371
395
$ text = $ this ->messages [$ matches [1 ]];
372
396
} else {
@@ -433,7 +457,7 @@ private function determineBestFormat()
433
457
}
434
458
}
435
459
436
- static private function initPlaceholderFormatters ()
460
+ private static function initPlaceholderFormatters ()
437
461
{
438
462
return array (
439
463
'bar ' => function (ProgressBar $ bar ) {
@@ -490,7 +514,7 @@ static private function initPlaceholderFormatters()
490
514
);
491
515
}
492
516
493
- static private function initFormats ()
517
+ private static function initFormats ()
494
518
{
495
519
return array (
496
520
'quiet ' => ' %percent%% ' ,
0 commit comments