| 1 | <?php |
||
| 5 | class ConfigCollection implements ConfigCollectionInterface |
||
| 6 | { |
||
| 7 | |||
| 8 | /** |
||
| 9 | * Stores a list of key/value config. |
||
| 10 | * |
||
| 11 | * @var array |
||
| 12 | */ |
||
| 13 | protected $config = []; |
||
| 14 | |||
| 15 | /** |
||
| 16 | * @var boolean |
||
| 17 | */ |
||
| 18 | protected $trackMetadata = false; |
||
| 19 | |||
| 20 | 22 | public function __construct($trackMetadata = false) |
|
| 21 | { |
||
| 22 | 22 | $this->trackMetadata = $trackMetadata; |
|
| 23 | 22 | } |
|
| 24 | |||
| 25 | /** |
||
| 26 | * {@inheritdoc} |
||
| 27 | */ |
||
| 28 | 19 | public function set($key, ConfigItemInterface $item) |
|
| 29 | { |
||
| 30 | 19 | if(!$this->exists($key)) { |
|
| 31 | 19 | $this->config[$key] = $item; |
|
| 32 | 19 | } |
|
| 33 | |||
| 34 | // Get the existing item so we can set the new value on it |
||
| 35 | 19 | $existing = $this->config[$key]; |
|
| 36 | |||
| 37 | // Ensure that that tracking is correct for items belonging to this collection |
||
| 38 | 19 | $existing->trackMetadata($this->trackMetadata); |
|
| 39 | |||
| 40 | 19 | $existing->set($item->getValue(), $item->getMetadata()); |
|
| 41 | 19 | } |
|
| 42 | |||
| 43 | /** |
||
| 44 | * {@inheritdoc} |
||
| 45 | */ |
||
| 46 | 19 | public function get($key) |
|
| 54 | |||
| 55 | /** |
||
| 56 | * {@inheritdoc} |
||
| 57 | */ |
||
| 58 | 20 | public function exists($key) |
|
| 62 | |||
| 63 | /** |
||
| 64 | * {@inheritdoc} |
||
| 65 | */ |
||
| 66 | 1 | public function delete($key) |
|
| 72 | } |
||
| 73 |