| 1 |
<?php |
| 2 |
|
| 3 |
namespace Aws\S3\S3Transfer\Progress; |
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
abstract class AbstractProgressBarFormat |
| 9 |
{ |
| 10 |
|
| 11 |
private array $args; |
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
public function __construct( |
| 17 |
array $args = [] |
| 18 |
) { |
| 19 |
$this->args = $args; |
| 20 |
} |
| 21 |
|
| 22 |
public function getArgs(): array |
| 23 |
{ |
| 24 |
return $this->args; |
| 25 |
} |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
public function setArgs(array $args): void |
| 38 |
{ |
| 39 |
foreach ($args as $key => $value) { |
| 40 |
$this->args[$key] = $value; |
| 41 |
} |
| 42 |
} |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
public function setArg(string $key, mixed $value): void |
| 51 |
{ |
| 52 |
$this->args[$key] = $value; |
| 53 |
} |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
public function format(): string |
| 59 |
{ |
| 60 |
$parameters = $this->getFormatParameters(); |
| 61 |
$defaultParameterValues = $this->getFormatDefaultParameterValues(); |
| 62 |
foreach ($parameters as $param) { |
| 63 |
if (!array_key_exists($param, $this->args)) { |
| 64 |
$this->args[$param] = $defaultParameterValues[$param] ?? ''; |
| 65 |
} |
| 66 |
} |
| 67 |
|
| 68 |
$replacements = []; |
| 69 |
foreach ($parameters as $param) { |
| 70 |
$replacements["|$param|"] = $this->args[$param] ?? ''; |
| 71 |
} |
| 72 |
|
| 73 |
return strtr($this->getFormatTemplate(), $replacements); |
| 74 |
} |
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
abstract public function getFormatTemplate(): string; |
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
abstract public function getFormatParameters(): array; |
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
abstract protected function getFormatDefaultParameterValues(): array; |
| 90 |
} |