Debian Codegraph @

lib/3rdParty/composer/aws/aws-sdk-php/src/S3/S3Transfer/Progress/AbstractProgressBarFormat.php

raw symbols SCIP
1 <?php
2
3 namespace Aws\S3\S3Transfer\Progress;
4
5 /**
6 * Defines a progress bar format.
7 */
8 abstract class AbstractProgressBarFormat
9 {
10 /** @var array */
11 private array $args;
12
13 /**
14 * @param array $args
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 * To set multiple arguments at once.
29 * It does not override all the values, instead
30 * it adds the arguments individually and if a value
31 * already exists then that value will be overridden.
32 *
33 * @param array $args
34 *
35 * @return void
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 * @param string $key
46 * @param mixed $value
47 *
48 * @return void
49 */
50 public function setArg(string $key, mixed $value): void
51 {
52 $this->args[$key] = $value;
53 }
54
55 /**
56 * @return string
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 * @return string
78 */
79 abstract public function getFormatTemplate(): string;
80
81 /**
82 * @return array
83 */
84 abstract public function getFormatParameters(): array;
85
86 /**
87 * @return array
88 */
89 abstract protected function getFormatDefaultParameterValues(): array;
90 }