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