PluginProbe
Metricool – Social media and site statistics / trunk
Metricool – Social media and site statistics vtrunk
2.1.0 2.0.2 2.0.1 2.0.0 1.27 trunk
metricool / app / Features / UserSettings / UserSettingsController.php

UserSettingsController.php in Metricool – Social media and site statistics trunk, at app/Features/UserSettings/UserSettingsController.php

47 lines 1.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 }
47