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