1 | <?php |
||
2 | |||
3 | namespace Apps\Model\Admin\Main; |
||
4 | |||
5 | use Ffcms\Core\App; |
||
6 | use Ffcms\Core\Arch\Model; |
||
7 | use Ffcms\Core\Helper\FileSystem\Directory; |
||
8 | use Ffcms\Core\Helper\FileSystem\File; |
||
9 | use Ffcms\Core\Helper\Type\Any; |
||
10 | use Ffcms\Core\Helper\Type\Arr; |
||
11 | |||
12 | /** |
||
13 | * Class FormSettings. Admin system settings business logic |
||
14 | * @package Apps\Model\Admin\Main |
||
15 | */ |
||
16 | class FormSettings extends Model |
||
17 | { |
||
18 | // base cfg |
||
19 | public $baseProto; |
||
20 | public $baseDomain; |
||
21 | public $basePath; |
||
22 | public $timezone; |
||
23 | public $adminEmail; |
||
24 | public $debug; |
||
25 | public $userCron; |
||
26 | public $testSuite; |
||
27 | |||
28 | // theme & database configs |
||
29 | public $theme; |
||
30 | public $database; |
||
31 | |||
32 | // mail configs |
||
33 | public $mail; |
||
34 | |||
35 | // lang cfgs |
||
36 | public $baseLanguage = 'en'; |
||
37 | public $multiLanguage; |
||
38 | public $singleLanguage; |
||
39 | public $languages; |
||
40 | |||
41 | public $languageDomainAlias; |
||
42 | |||
43 | // other |
||
44 | public $trustedProxy; |
||
45 | |||
46 | public $_name = 'formAdminConfig'; |
||
47 | |||
48 | /** |
||
49 | * Set property values from configurations |
||
50 | */ |
||
51 | public function before() |
||
52 | { |
||
53 | $properties = App::$Properties->getAll(); |
||
54 | if (!$properties || !Any::isArray($properties)) { |
||
55 | return; |
||
56 | } |
||
57 | |||
58 | // set default values |
||
59 | foreach (App::$Properties->getAll() as $key => $value) { |
||
60 | if (property_exists($this, $key)) { |
||
61 | $this->{$key} = $value; |
||
62 | } |
||
63 | } |
||
64 | } |
||
65 | |||
66 | /** |
||
67 | * Set form display labels |
||
68 | * @return array |
||
69 | */ |
||
70 | public function labels(): array |
||
71 | { |
||
72 | return [ |
||
73 | 'baseDomain' => __('Base domain'), |
||
74 | 'baseProto' => __('Base protocol'), |
||
75 | 'basePath' => __('Base path'), |
||
76 | 'adminEmail' => __('Admin email'), |
||
77 | 'timezone' => __('Timezone'), |
||
78 | 'userCron' => __('User run cron'), |
||
79 | 'debug.all' => __('Debug for all'), |
||
80 | 'testSuite' => __('Test suite'), |
||
81 | 'singleLanguage' => __('Default language'), |
||
82 | 'languages' => __('Available languages'), |
||
83 | 'multiLanguage' => __('Multi-languages'), |
||
84 | 'theme.Front' => __('User theme'), |
||
85 | 'theme.Admin' => __('Admin theme'), |
||
86 | 'database.driver' => __('Database driver'), |
||
87 | 'database.host' => __('Database host'), |
||
88 | 'database.database' => __('Database name'), |
||
89 | 'database.username' => __('Database user'), |
||
90 | 'database.password' => __('Database user pass'), |
||
91 | 'database.charset' => __('Charset'), |
||
92 | 'database.collation' => __('Collation'), |
||
93 | 'database.prefix' => __('Tables prefix'), |
||
94 | 'mail.enable' => __('Use mail features'), |
||
95 | 'mail.host' => __('Host'), |
||
96 | 'mail.port' => __('Port'), |
||
97 | 'mail.encrypt' => __('Encryption'), |
||
98 | 'mail.user' => __('User'), |
||
99 | 'mail.password' => __('Password'), |
||
100 | 'debug.cookie.key' => __('Debug cookie key'), |
||
101 | 'debug.cookie.value' => __('Debug cookie value'), |
||
102 | 'trustedProxy' => __('Proxy list'), |
||
103 | ]; |
||
104 | } |
||
105 | |||
106 | /** |
||
107 | * Config validation rules |
||
108 | * @return array |
||
109 | */ |
||
110 | public function rules(): array |
||
111 | { |
||
112 | return [ |
||
113 | [['debug.all', 'multiLanguage', 'trustedProxy', 'languages', 'userCron'], 'used'], |
||
114 | [['baseProto', 'baseDomain', 'basePath', 'singleLanguage', 'timezone', 'testSuite'], 'required'], |
||
115 | [['debug.cookie.key', 'debug.cookie.value'], 'required'], |
||
116 | [['theme.Front', 'theme.Admin'], 'required'], |
||
117 | [['database.driver', 'database.database', 'database.host', 'database.username', 'database.password', 'database.prefix'], 'required'], |
||
118 | [['database.charset', 'database.collation'], 'used'], |
||
119 | ['mail.enable', 'required'], |
||
120 | ['mail.enable', 'int'], |
||
121 | [['mail.host', 'mail.port', 'mail.user', 'mail.encrypt', 'mail.password'], 'used'], |
||
122 | ['mail.user', 'email'], |
||
123 | ['mail.port', 'int'], |
||
124 | ['mail.encrypt', 'in', ['ssl', 'tls', 'none']], |
||
125 | ['timezone', 'string'], |
||
126 | ['baseProto', 'in', ['http', 'https']], |
||
127 | [['userCron', 'testSuite'], 'boolean'], |
||
128 | ]; |
||
129 | } |
||
130 | |||
131 | /** |
||
132 | * Get available themes for environment |
||
133 | * @param $env_name |
||
134 | * @return array |
||
135 | */ |
||
136 | public function getAvailableThemes($env_name) |
||
137 | { |
||
138 | $path = root . '/Apps/View/' . $env_name . '/'; |
||
139 | if (!Directory::exist($path)) { |
||
140 | return []; |
||
141 | } |
||
142 | |||
143 | $scan = Directory::scan($path); |
||
144 | $response = []; |
||
145 | |||
146 | foreach ($scan as $object) { |
||
147 | $response[] = substr(strrchr($object, '/'), 1); |
||
148 | } |
||
149 | |||
150 | return $response; |
||
151 | } |
||
152 | |||
153 | /** |
||
154 | * Save model properties as configurations |
||
155 | * @return bool |
||
156 | */ |
||
157 | public function makeSave() |
||
158 | { |
||
159 | $toSave = App::$Security->strip_php_tags($this->getAllProperties()); |
||
0 ignored issues
–
show
|
|||
160 | $stringSave = '<?php return ' . Arr::exportVar($toSave, null, true) . ';'; |
||
161 | |||
162 | $cfgPath = '/Private/Config/Default.php'; |
||
163 | if (File::exist($cfgPath) && File::writable($cfgPath)) { |
||
164 | File::write($cfgPath, $stringSave); |
||
165 | return true; |
||
166 | } |
||
167 | |||
168 | return false; |
||
169 | } |
||
170 | } |
||
171 |
This check looks for function or method calls that always return null and whose return value is used.
The method
getObject()
can return nothing but null, so it makes no sense to use the return value.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.