@@ 21-77 (lines=57) @@ | ||
18 | * |
|
19 | * @author Tobias Nyholm <[email protected]> |
|
20 | */ |
|
21 | final class ConfigurationManager |
|
22 | { |
|
23 | /** |
|
24 | * @var Configuration[] |
|
25 | */ |
|
26 | private $configuration = []; |
|
27 | ||
28 | /** |
|
29 | * @param string $name |
|
30 | * @param Configuration $configuration |
|
31 | */ |
|
32 | public function addConfiguration($name, Configuration $configuration) |
|
33 | { |
|
34 | $this->configuration[$name] = $configuration; |
|
35 | } |
|
36 | ||
37 | /** |
|
38 | * @param string $name |
|
39 | * |
|
40 | * @return null|Configuration |
|
41 | */ |
|
42 | public function getConfiguration($name = null) |
|
43 | { |
|
44 | if (empty($name)) { |
|
45 | return $this->getConfiguration('default'); |
|
46 | } |
|
47 | ||
48 | if (isset($this->configuration[$name])) { |
|
49 | return $this->configuration[$name]; |
|
50 | } |
|
51 | ||
52 | if ('default' === $name) { |
|
53 | $name = $this->getFirstName(); |
|
54 | if (isset($this->configuration[$name])) { |
|
55 | return $this->configuration[$name]; |
|
56 | } |
|
57 | } |
|
58 | } |
|
59 | ||
60 | /** |
|
61 | * @return string |
|
62 | */ |
|
63 | public function getFirstName() |
|
64 | { |
|
65 | foreach ($this->configuration as $name => $config) { |
|
66 | return $name; |
|
67 | } |
|
68 | } |
|
69 | ||
70 | /** |
|
71 | * @return array |
|
72 | */ |
|
73 | public function getNames() |
|
74 | { |
|
75 | return array_keys($this->configuration); |
|
76 | } |
|
77 | } |
|
78 |
@@ 19-75 (lines=57) @@ | ||
16 | * |
|
17 | * @author Tobias Nyholm <[email protected]> |
|
18 | */ |
|
19 | final class StorageManager |
|
20 | { |
|
21 | /** |
|
22 | * @var StorageService[] |
|
23 | */ |
|
24 | private $storages = []; |
|
25 | ||
26 | /** |
|
27 | * @param string $name |
|
28 | * @param StorageService $storage |
|
29 | */ |
|
30 | public function addStorage($name, StorageService $storage) |
|
31 | { |
|
32 | $this->storages[$name] = $storage; |
|
33 | } |
|
34 | ||
35 | /** |
|
36 | * @param string $name |
|
37 | * |
|
38 | * @return null|StorageService |
|
39 | */ |
|
40 | public function getStorage($name = null) |
|
41 | { |
|
42 | if (empty($name)) { |
|
43 | return $this->getStorage('default'); |
|
44 | } |
|
45 | ||
46 | if (isset($this->storages[$name])) { |
|
47 | return $this->storages[$name]; |
|
48 | } |
|
49 | ||
50 | if ('default' === $name) { |
|
51 | $name = $this->getFirstName(); |
|
52 | if (isset($this->storages[$name])) { |
|
53 | return $this->storages[$name]; |
|
54 | } |
|
55 | } |
|
56 | } |
|
57 | ||
58 | /** |
|
59 | * @return string|null |
|
60 | */ |
|
61 | public function getFirstName() |
|
62 | { |
|
63 | foreach ($this->storages as $name => $config) { |
|
64 | return $name; |
|
65 | } |
|
66 | } |
|
67 | ||
68 | /** |
|
69 | * @return array |
|
70 | */ |
|
71 | public function getNames() |
|
72 | { |
|
73 | return array_keys($this->storages); |
|
74 | } |
|
75 | } |
|
76 |