]> git.mxchange.org Git - friendica.git/blob - src/Factory/DependencyFactory.php
Create own base URL class which holds the whole base url business logic
[friendica.git] / src / Factory / DependencyFactory.php
1 <?php
2
3 namespace Friendica\Factory;
4
5 use Friendica\App;
6 use Friendica\Factory;
7 use Friendica\Util\BasePath;
8 use Friendica\Util\BaseURL;
9 use Friendica\Util\Config;
10
11 class DependencyFactory
12 {
13         /**
14          * Setting all default-dependencies of a friendica execution
15          *
16          * @param string $channel   The channel of this execution
17          * @param string $directory The base directory
18          * @param bool   $isBackend True, if it's a backend execution, otherwise false (Default true)
19          *
20          * @return App The application
21          *
22          * @throws \Exception
23          */
24         public static function setUp($channel, $directory, $isBackend = true)
25         {
26                 $basePath = BasePath::create($directory, $_SERVER);
27                 $mode = new App\Mode($basePath);
28                 $router = new App\Router();
29                 $configLoader = new Config\ConfigFileLoader($basePath, $mode);
30                 $configCache = Factory\ConfigFactory::createCache($configLoader);
31                 $profiler = Factory\ProfilerFactory::create($configCache);
32                 Factory\DBFactory::init($basePath, $configCache, $profiler, $_SERVER);
33                 $config = Factory\ConfigFactory::createConfig($configCache);
34                 // needed to call PConfig::init()
35                 Factory\ConfigFactory::createPConfig($configCache);
36                 $logger = Factory\LoggerFactory::create($channel, $config, $profiler);
37                 Factory\LoggerFactory::createDev($channel, $config, $profiler);
38                 $baseURL = new BaseURL($config, $_SERVER);
39
40                 return new App($config, $mode, $router, $baseURL, $logger, $profiler, $isBackend);
41         }
42 }