| 1 |
<?php |
| 2 |
// phpcs:ignoreFile -- Bundled third-party (Mozart) dependency; exempt from plugin coding standards. |
| 3 |
|
| 4 |
declare(strict_types=1); |
| 5 |
|
| 6 |
namespace WPDeveloper\BetterDocs\Dependencies\DI\Definition; |
| 7 |
|
| 8 |
/** |
| 9 |
* Definition of an array containing values or references. |
| 10 |
* |
| 11 |
* @since 5.0 |
| 12 |
* @author Matthieu Napoli <matthieu@mnapoli.fr> |
| 13 |
*/ |
| 14 |
class ArrayDefinition implements Definition |
| 15 |
{ |
| 16 |
/** |
| 17 |
* Entry name. |
| 18 |
* @var string |
| 19 |
*/ |
| 20 |
private $name = ''; |
| 21 |
|
| 22 |
/** |
| 23 |
* @var array |
| 24 |
*/ |
| 25 |
private $values; |
| 26 |
|
| 27 |
public function __construct(array $values) |
| 28 |
{ |
| 29 |
$this->values = $values; |
| 30 |
} |
| 31 |
|
| 32 |
public function getName() : string |
| 33 |
{ |
| 34 |
return $this->name; |
| 35 |
} |
| 36 |
|
| 37 |
public function setName(string $name) |
| 38 |
{ |
| 39 |
$this->name = $name; |
| 40 |
} |
| 41 |
|
| 42 |
public function getValues() : array |
| 43 |
{ |
| 44 |
return $this->values; |
| 45 |
} |
| 46 |
|
| 47 |
public function replaceNestedDefinitions(callable $replacer) |
| 48 |
{ |
| 49 |
$this->values = array_map($replacer, $this->values); |
| 50 |
} |
| 51 |
|
| 52 |
public function __toString() |
| 53 |
{ |
| 54 |
$str = '[' . PHP_EOL; |
| 55 |
|
| 56 |
foreach ($this->values as $key => $value) { |
| 57 |
if (is_string($key)) { |
| 58 |
$key = "'" . $key . "'"; |
| 59 |
} |
| 60 |
|
| 61 |
$str .= ' ' . $key . ' => '; |
| 62 |
|
| 63 |
if ($value instanceof Definition) { |
| 64 |
$str .= str_replace(PHP_EOL, PHP_EOL . ' ', (string) $value); |
| 65 |
} else { |
| 66 |
$str .= var_export($value, true); |
| 67 |
} |
| 68 |
|
| 69 |
$str .= ',' . PHP_EOL; |
| 70 |
} |
| 71 |
|
| 72 |
return $str . ']'; |
| 73 |
} |
| 74 |
} |
| 75 |
|