]> git.mxchange.org Git - friendica.git/blob - src/Factory/ConfigFactory.php
Merge pull request #8142 from nupplaphil/task/di_config
[friendica.git] / src / Factory / ConfigFactory.php
1 <?php
2
3 namespace Friendica\Factory;
4
5 use Exception;
6 use Friendica\Core\Config;
7 use Friendica\Core\Config\Cache;
8 use Friendica\Model\Config\Config as ConfigModel;
9 use Friendica\Model\Config\PConfig as PConfigModel;
10 use Friendica\Util\ConfigFileLoader;
11
12 class ConfigFactory
13 {
14         /**
15          * @param ConfigFileLoader $loader The Config Cache loader (INI/config/.htconfig)
16          *
17          * @return Cache
18          *
19          * @throws Exception
20          */
21         public function createCache(ConfigFileLoader $loader)
22         {
23                 $configCache = new Cache();
24                 $loader->setupCache($configCache);
25
26                 return $configCache;
27         }
28
29         /**
30          * @param Cache       $configCache The config cache of this adapter
31          * @param ConfigModel $configModel The configuration model
32          *
33          * @return Config\IConfig
34          */
35         public function createConfig(Cache $configCache, ConfigModel $configModel)
36         {
37                 if ($configCache->get('system', 'config_adapter') === 'preload') {
38                         $configuration = new Config\PreloadConfig($configCache, $configModel);
39                 } else {
40                         $configuration = new Config\JitConfig($configCache, $configModel);
41                 }
42
43
44                 return $configuration;
45         }
46
47         /**
48          * @param Cache                         $configCache  The config cache
49          * @param \Friendica\Core\PConfig\Cache $pConfigCache The personal config cache
50          * @param PConfigModel                  $configModel  The configuration model
51          *
52          * @return \Friendica\Core\PConfig\IPConfig
53          */
54         public function createPConfig(Cache $configCache, \Friendica\Core\PConfig\Cache $pConfigCache, PConfigModel $configModel)
55         {
56                 if ($configCache->get('system', 'config_adapter') === 'preload') {
57                         $configuration = new \Friendica\Core\PConfig\PreloadPConfig($pConfigCache, $configModel);
58                 } else {
59                         $configuration = new \Friendica\Core\PConfig\JitPConfig($pConfigCache, $configModel);
60                 }
61
62                 return $configuration;
63         }
64 }