|
9 | 9 | use UnitPhpSdk\Contracts\{ApplicationStatisticsInterface, |
10 | 10 | Arrayable, |
11 | 11 | ConnectionsStatisticsInterface, |
| 12 | + ModuleStatisticsInterface, |
12 | 13 | RequestsStatisticsInterface, |
13 | | - StatisticsInterface |
14 | | -}; |
| 14 | + StatisticsInterface}; |
15 | 15 | use UnitPhpSdk\Exceptions\UnitParseException; |
16 | 16 |
|
17 | 17 | /** |
|
22 | 22 | */ |
23 | 23 | final readonly class Statistics implements StatisticsInterface |
24 | 24 | { |
| 25 | + /** |
| 26 | + * Modules statistics |
| 27 | + * |
| 28 | + * @var array |
| 29 | + */ |
| 30 | + private array $modules; |
| 31 | + |
25 | 32 | /** |
26 | 33 | * Connections statistics |
27 | 34 | * |
|
48 | 55 | */ |
49 | 56 | public function __construct(array $data) |
50 | 57 | { |
51 | | - // $this->unitInformation = new UnitStatistics($data['unit']); |
| 58 | + $this->modules = array_map(fn ($item) => new ModuleStatistics($item), $data['modules']); |
52 | 59 | $this->connections = new ConnectionsStatistics($data['connections']); |
53 | 60 | $this->requests = new RequestsStatistics($data['requests']); |
54 | 61 | $this->applications = array_map(fn ($item) => new ApplicationStatistics($item), $data['applications']); |
@@ -94,12 +101,33 @@ public function getApplicationStatistics(AbstractApplication|string $application |
94 | 101 | return $this->applications[$application->getName()]; |
95 | 102 | } |
96 | 103 |
|
| 104 | + /** |
| 105 | + * @return array |
| 106 | + */ |
| 107 | + public function getModules(): array |
| 108 | + { |
| 109 | + return $this->modules; |
| 110 | + } |
| 111 | + |
| 112 | + /** |
| 113 | + * @inheritDoc |
| 114 | + */ |
| 115 | + public function getModuleStatistics(string $module): ModuleStatisticsInterface |
| 116 | + { |
| 117 | + if (!array_key_exists($module, $this->modules)) { |
| 118 | + throw new InvalidArgumentException('Module with name ' . $module . ' not found'); |
| 119 | + } |
| 120 | + |
| 121 | + return $this->modules[$module]; |
| 122 | + } |
| 123 | + |
97 | 124 | /** |
98 | 125 | * @inheritDoc |
99 | 126 | */ |
100 | 127 | #[Override] public function toArray(): array |
101 | 128 | { |
102 | 129 | return [ |
| 130 | + 'modules' => array_map(fn ($item) => $item->toArray(), $this->modules), |
103 | 131 | 'connections' => $this->connections->toArray(), |
104 | 132 | 'requests' => $this->requests->toArray(), |
105 | 133 | 'applications' => array_map(fn ($item) => $item->toArray(), $this->applications), |
|
0 commit comments