]> git.mxchange.org Git - friendica.git/blob - src/Factory/ConfigFactory.php
Config FollowUp
[friendica.git] / src / Factory / ConfigFactory.php
1 <?php
2
3 namespace Friendica\Factory;
4
5 use Friendica\Core;
6 use Friendica\Core\Config;
7 use Friendica\Core\Config\Adapter;
8 use Friendica\Core\Config\Cache;
9
10 class ConfigFactory
11 {
12         /**
13          * @param Cache\ConfigCacheLoader $loader The Config Cache loader (INI/config/.htconfig)
14          *
15          * @return Cache\ConfigCache
16          */
17         public static function createCache(Cache\ConfigCacheLoader $loader)
18         {
19                 $configCache = new Cache\ConfigCache();
20                 $loader->loadConfigFiles($configCache);
21
22                 return $configCache;
23         }
24
25         /**
26          * @param Cache\ConfigCache $configCache The config cache of this adapter
27          *
28          * @return Config\Configuration
29          */
30         public static function createConfig(Cache\ConfigCache $configCache)
31         {
32                 if ($configCache->get('system', 'config_adapter') === 'preload') {
33                         $configAdapter = new Adapter\PreloadConfigAdapter();
34                 } else {
35                         $configAdapter = new Adapter\JITConfigAdapter();
36                 }
37
38                 $configuration = new Config\Configuration($configCache, $configAdapter);
39
40                 // Set the config in the static container for legacy usage
41                 Core\Config::init($configuration);
42
43                 return $configuration;
44         }
45
46         /**
47          * @param Cache\ConfigCache  $configCache The config cache of this adapter
48          * @param int                $uid         The UID of the current user
49          *
50          * @return Config\PConfiguration
51          */
52         public static function createPConfig(Cache\ConfigCache $configCache, $uid = null)
53         {
54                 if ($configCache->get('system', 'config_adapter') === 'preload') {
55                         $configAdapter = new Adapter\PreloadPConfigAdapter($uid);
56                 } else {
57                         $configAdapter = new Adapter\JITPConfigAdapter();
58                 }
59
60                 $configuration = new Config\PConfiguration($configCache, $configAdapter);
61
62                 // Set the config in the static container for legacy usage
63                 Core\PConfig::init($configuration);
64
65                 return $configuration;
66         }
67 }