resources = $resources; $this->charges = $charges; } public function getChargesKeys(bool $onlyActive = false): array { return array_map(static function ($element) { return $element['key']; }, $this->getCharges($onlyActive)); } /** * @return array where keys are the resource'key and label the ressource label */ public function getChargesLabels(bool $onlyActive = false) { $charges = []; foreach ($this->getCharges($onlyActive) as $definition) { $charges[$definition['key']] = $this->normalizeLabel($definition['labels']); } return $charges; } public function getResourcesKeys(bool $onlyActive = false): array { return array_map(static function ($element) { return $element['key']; }, $this->getResources($onlyActive)); } /** * @return array where keys are the resource'key and label the ressource label */ public function getResourcesLabels(bool $onlyActive = false) { $resources = []; foreach ($this->getResources($onlyActive) as $definition) { $resources[$definition['key']] = $this->normalizeLabel($definition['labels']); } return $resources; } private function getCharges(bool $onlyActive = false): array { return $onlyActive ? array_filter($this->charges, static function ($el) { return $el['active']; }) : $this->charges; } private function getResources(bool $onlyActive = false): array { return $onlyActive ? array_filter($this->resources, static function ($el) { return $el['active']; }) : $this->resources; } private function normalizeLabel($labels) { $normalizedLabels = []; foreach ($labels as $labelDefinition) { $normalizedLabels[$labelDefinition['lang']] = $labelDefinition['label']; } return $normalizedLabels; } }