3
3
4
4
namespace OnixSystemsPHP \HyperfAppSettings \Service ;
5
5
6
- use OnixSystemsPHP \HyperfAppSettings \Constants \AppSettings ;
7
- use OnixSystemsPHP \HyperfAppSettings \DTO \UpdateAppSettingDTO ;
6
+ use Hyperf \Contract \ConfigInterface ;
7
+ use Hyperf \DbConnection \Annotation \Transactional ;
8
+ use Hyperf \Validation \Contract \ValidatorFactoryInterface ;
8
9
use OnixSystemsPHP \HyperfActionsLog \Event \Action ;
9
- use OnixSystemsPHP \HyperfCore \ Exception \ BusinessException ;
10
+ use OnixSystemsPHP \HyperfAppSettings \ DTO \ UpdateAppSettingDTO ;
10
11
use OnixSystemsPHP \HyperfAppSettings \Model \AppSetting ;
11
12
use OnixSystemsPHP \HyperfAppSettings \Repository \AppSettingsRepository ;
13
+ use OnixSystemsPHP \HyperfCore \Exception \BusinessException ;
12
14
use OnixSystemsPHP \HyperfCore \Service \Service ;
13
- use Hyperf \DbConnection \Annotation \Transactional ;
14
- use Hyperf \Validation \Contract \ValidatorFactoryInterface ;
15
15
use Psr \EventDispatcher \EventDispatcherInterface ;
16
16
17
17
#[Service]
@@ -21,6 +21,7 @@ class UpdateAppSettingsService
21
21
22
22
public function __construct (
23
23
private ValidatorFactoryInterface $ vf ,
24
+ private ConfigInterface $ config ,
24
25
private AppSettingsRepository $ rAppSettings ,
25
26
private AppSettingsService $ appSettingsService ,
26
27
private EventDispatcherInterface $ eventDispatcher ,
@@ -48,15 +49,17 @@ public function run(UpdateAppSettingDTO $updateAppSettingDTO): ?AppSetting
48
49
49
50
private function validate (UpdateAppSettingDTO $ userData ): array
50
51
{
51
- if (!isset (AppSettings::SETTINGS_DATA [$ userData ->name ])) {
52
- throw new BusinessException (422 , __ ('exceptions.update_app_settings.wrong_type ' ));
52
+ $ settingsList = $ this ->config ->get ('app_settings.fields ' );
53
+ $ settingsTypes = $ this ->config ->get ('app_settings.types ' );
54
+ if (!array_key_exists ($ userData ->name , $ settingsList )) {
55
+ throw new BusinessException (422 , __ ('exceptions.app_settings.update_wrong_type ' ));
53
56
}
54
- $ type = AppSettings:: SETTINGS_DATA [$ userData ->name ]['type ' ];
55
- $ category = AppSettings:: SETTINGS_DATA [$ userData ->name ]['category ' ];
57
+ $ type = $ settingsList [$ userData ->name ]['type ' ];
58
+ $ category = $ settingsList [$ userData ->name ]['category ' ];
56
59
$ result = $ this ->vf
57
60
->make ($ userData ->toArray (), array_merge ([
58
- 'name ' => 'in: ' . implode (', ' , AppSettings:: SETTINGS_LIST ),
59
- ], AppSettings:: TYPES_VALIDATION [$ type ]))
61
+ 'name ' => 'in: ' . implode (', ' , array_keys ( $ settingsList ) ),
62
+ ], $ settingsTypes [$ type ]))
60
63
->validate ();
61
64
$ result ['type ' ] = $ type ;
62
65
$ result ['category ' ] = $ category ;
0 commit comments