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 / Factories / StorageFactory.php

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

32 lines 950 B
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\Factories;
6
7 use Metricool\Features\UserSettings\Storage\AbstractStorage;
8
9 class StorageFactory
10 {
11 private const STORAGE_NAMESPACE = '\\Metricool\\Features\\UserSettings\\Storage\\';
12
13 /**
14 * Creates a storage from the user_settings configuration
15 * @see config/user_settings.php
16 */
17 public static function createFromConfig(string $name, array $options): AbstractStorage
18 {
19 if (!isset($options['class'])) {
20 throw new \InvalidArgumentException('Class for "' . esc_html($name) . '" not mapped, please add it to the config');
21 }
22
23 $storageClass = self::STORAGE_NAMESPACE . ucfirst($options['class']);
24
25 if (!class_exists($storageClass)) {
26 throw new \InvalidArgumentException('Storage "' . esc_html($storageClass) . '" not found');
27 }
28
29 return new $storageClass($name, $options);
30 }
31 }
32