friendica/src/Factory/DependencyFactory.php

46 lines
1.6 KiB
PHP
Raw Normal View History

2019-02-12 20:12:25 +01:00
<?php
namespace Friendica\Factory;
use Friendica\App;
use Friendica\Core\Config\Cache\PConfigCache;
2019-02-12 20:12:25 +01:00
use Friendica\Factory;
use Friendica\Util\BasePath;
use Friendica\Util\BaseURL;
use Friendica\Util\ConfigFileLoader;
2019-02-12 20:12:25 +01:00
class DependencyFactory
{
/**
* Setting all default-dependencies of a friendica execution
*
* @param string $channel The channel of this execution
* @param string $directory The base directory
* @param bool $isBackend True, if it's a backend execution, otherwise false (Default true)
*
* @return App The application
*
* @throws \Exception
*/
public static function setUp($channel, $directory, $isBackend = true)
{
$basePath = BasePath::create($directory, $_SERVER);
2019-03-14 02:36:49 +01:00
$mode = new App\Mode($basePath);
$router = new App\Router();
$configLoader = new ConfigFileLoader($basePath, $mode);
2019-02-12 20:12:25 +01:00
$configCache = Factory\ConfigFactory::createCache($configLoader);
$profiler = Factory\ProfilerFactory::create($configCache);
2019-06-07 00:10:45 +02:00
$database = Factory\DBFactory::init($configCache, $profiler, $_SERVER);
2019-07-12 23:01:01 +02:00
$configModel = new \Friendica\Model\Config\Config($database);
$config = Factory\ConfigFactory::createConfig($configCache, $configModel);
2019-02-12 20:12:25 +01:00
// needed to call PConfig::init()
2019-07-15 20:13:53 +02:00
$pconfigModel = new \Friendica\Model\Config\PConfig($database);
Factory\ConfigFactory::createPConfig($configCache, new PConfigCache(), $pconfigModel);
2019-06-07 00:10:45 +02:00
$logger = Factory\LoggerFactory::create($channel, $database, $config, $profiler);
2019-03-14 02:36:49 +01:00
Factory\LoggerFactory::createDev($channel, $config, $profiler);
$baseURL = new BaseURL($config, $_SERVER);
2019-02-12 20:12:25 +01:00
2019-06-07 00:10:45 +02:00
return new App($database, $config, $mode, $router, $baseURL, $logger, $profiler, $isBackend);
2019-02-12 20:12:25 +01:00
}
}