← All changes
|
app/Features/UserSettings/UserSettingsController.php
+46
-0
2.0.1
→
2.1.1
View file →
| @@ -1,0 +1,46 @@ | ||
| 1 | +<?php | |
| 2 | + | |
| 3 | +declare(strict_types=1); | |
| 4 | + | |
| 5 | +namespace Metricool\Features\UserSettings; | |
| 6 | + | |
| 7 | +use Metricool\Support\Helpers\Collection; | |
| 8 | +use Metricool\Interfaces\FeatureInterface; | |
| 9 | +use Metricool\Support\Helpers\Storages\UserSettingsConfig; | |
| 10 | +use Metricool\Features\UserSettings\Factories\FieldsFactory; | |
| 11 | +use Metricool\Features\UserSettings\Exceptions\StorageNotFoundException; | |
| 12 | + | |
| 13 | +class UserSettingsController implements FeatureInterface | |
| 14 | +{ | |
| 15 | + private UserSettingsEndpoint $endpoints; | |
| 16 | + | |
| 17 | + /** | |
| 18 | + * @throws \Exception | |
| 19 | + */ | |
| 20 | + public function __construct(UserSettingsConfig $config) | |
| 21 | + { | |
| 22 | + $fields = $this->getFieldsFromConfig($config); | |
| 23 | + $this->endpoints = new UserSettingsEndpoint( | |
| 24 | + new UserSettingsService($fields) | |
| 25 | + ); | |
| 26 | + } | |
| 27 | + | |
| 28 | + public function register(): void | |
| 29 | + { | |
| 30 | + $this->endpoints->register(); | |
| 31 | + } | |
| 32 | + | |
| 33 | + /** | |
| 34 | + * Retrieve the fields from the configuration file and convert them into | |
| 35 | + * Field instances. | |
| 36 | + * @throws StorageNotFoundException When the config file is not correctly | |
| 37 | + * set up. | |
| 38 | + */ | |
| 39 | + private function getFieldsFromConfig(UserSettingsConfig $config): Collection | |
| 40 | + { | |
| 41 | + $factory = new FieldsFactory( | |
| 42 | + $config->all(), | |
| 43 | + ); | |
| 44 | + return $factory->createFromConfig(); | |
| 45 | + } | |
| 46 | +} | |