]> git.mxchange.org Git - friendica.git/blob - src/Factory/DependencyFactory.php
041202e6bfde7eedad4dbe9ffba1d0edbbeff41e
[friendica.git] / src / Factory / DependencyFactory.php
1 <?php
2
3 namespace Friendica\Factory;
4
5 use Friendica\App;
6 use Friendica\Core\Config\Cache;
7 use Friendica\Factory;
8 use Friendica\Util\BasePath;
9
10 class DependencyFactory
11 {
12         /**
13          * Setting all default-dependencies of a friendica execution
14          *
15          * @param string $channel   The channel of this execution
16          * @param string $directory The base directory
17          * @param bool   $isBackend True, if it's a backend execution, otherwise false (Default true)
18          *
19          * @return App The application
20          *
21          * @throws \Exception
22          */
23         public static function setUp($channel, $directory, $isBackend = true)
24         {
25                 $basedir = BasePath::create($directory, $_SERVER);
26                 $configLoader = new Cache\ConfigCacheLoader($basedir);
27                 $configCache = Factory\ConfigFactory::createCache($configLoader);
28                 Factory\DBFactory::init($configCache, $_SERVER);
29                 $config = Factory\ConfigFactory::createConfig($configCache);
30                 // needed to call PConfig::init()
31                 Factory\ConfigFactory::createPConfig($configCache);
32                 Factory\LoggerFactory::create($channel, $config);
33
34                 return new App($config, $isBackend);
35         }
36 }