|
- <?php
-
- namespace domain\Setting;
-
- use domain\Setting\SettingDetails\Admin\AdminSettingDefinition;
- use domain\Setting\SettingDetails\Producer\ProducerSettingDefinition;
- use domain\_\AbstractDefinition;
-
- class SettingDefinition extends AbstractDefinition
- {
- public function getEntityFqcn(): string
- {
- return Setting::class;
- }
-
- public function getSettingDetailByName(string $name)
- {
- $adminSettingDefinition = AdminSettingDefinition::getInstance();
- $producerSettingDefinition = ProducerSettingDefinition::getInstance();
-
- $settingDetail = $this->findSettingDetailInArray($name, $adminSettingDefinition->getSettingDetails());
- if(!$settingDetail) {
- $this->findSettingDetailInArray($name, $producerSettingDefinition->getSettingDetails());
- }
-
- if(!$settingDetail) {
- throw new \Exception('SettingDetail non trouvé');
- }
-
- return $settingDetail;
- }
-
- public function findSettingDetailInArray(string $name, array $settingDetailsArray)
- {
- foreach($settingDetailsArray as $section => $subsectionsArray) {
- foreach($subsectionsArray as $subsection => $settingDetailsArray) {
- foreach($settingDetailsArray as $settingDetail) {
- if($name == $settingDetail->getName()) {
- return $settingDetail;
- }
- }
- }
- }
-
- return null;
- }
- }
|