mirror of
https://github.com/friendica/friendica
synced 2024-11-10 00:23:00 +00:00
Move AppMode
This commit is contained in:
parent
d03dedee63
commit
1a2527cdba
7 changed files with 49 additions and 31 deletions
33
src/App.php
33
src/App.php
|
@ -165,6 +165,16 @@ class App
|
||||||
return $this->profiler;
|
return $this->profiler;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the Mode of the Application
|
||||||
|
*
|
||||||
|
* @return App\Mode The Application Mode
|
||||||
|
*/
|
||||||
|
public function getMode()
|
||||||
|
{
|
||||||
|
return $this->mode;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register a stylesheet file path to be included in the <head> tag of every page.
|
* Register a stylesheet file path to be included in the <head> tag of every page.
|
||||||
* Inclusion is done in App->initHead().
|
* Inclusion is done in App->initHead().
|
||||||
|
@ -208,19 +218,21 @@ class App
|
||||||
*
|
*
|
||||||
* @param string $basePath The basedir of the app
|
* @param string $basePath The basedir of the app
|
||||||
* @param Configuration $config The Configuration
|
* @param Configuration $config The Configuration
|
||||||
|
* @param App\Mode $mode The mode of this Friendica app
|
||||||
* @param LoggerInterface $logger The current app logger
|
* @param LoggerInterface $logger The current app logger
|
||||||
* @param Profiler $profiler The profiler of this application
|
* @param Profiler $profiler The profiler of this application
|
||||||
* @param bool $isBackend Whether it is used for backend or frontend (Default true=backend)
|
* @param bool $isBackend Whether it is used for backend or frontend (Default true=backend)
|
||||||
*
|
*
|
||||||
* @throws Exception if the Basepath is not usable
|
* @throws Exception if the Basepath is not usable
|
||||||
*/
|
*/
|
||||||
public function __construct($basePath, Configuration $config, LoggerInterface $logger, Profiler $profiler, $isBackend = true)
|
public function __construct($basePath, Configuration $config, App\Mode $mode, LoggerInterface $logger, Profiler $profiler, $isBackend = true)
|
||||||
{
|
{
|
||||||
BaseObject::setApp($this);
|
BaseObject::setApp($this);
|
||||||
|
|
||||||
$this->logger = $logger;
|
$this->logger = $logger;
|
||||||
$this->config = $config;
|
$this->config = $config;
|
||||||
$this->profiler = $profiler;
|
$this->profiler = $profiler;
|
||||||
|
$this->mode = $mode;
|
||||||
$cfgBasePath = $this->config->get('system', 'basepath');
|
$cfgBasePath = $this->config->get('system', 'basepath');
|
||||||
$this->basePath = !empty($cfgBasePath) ? $cfgBasePath : $basePath;
|
$this->basePath = !empty($cfgBasePath) ? $cfgBasePath : $basePath;
|
||||||
|
|
||||||
|
@ -234,8 +246,6 @@ class App
|
||||||
|
|
||||||
$this->profiler->reset();
|
$this->profiler->reset();
|
||||||
|
|
||||||
$this->mode = new App\Mode($this->basePath);
|
|
||||||
|
|
||||||
$this->reload();
|
$this->reload();
|
||||||
|
|
||||||
set_time_limit(0);
|
set_time_limit(0);
|
||||||
|
@ -335,22 +345,6 @@ class App
|
||||||
Core\Renderer::registerTemplateEngine('Friendica\Render\FriendicaSmartyEngine');
|
Core\Renderer::registerTemplateEngine('Friendica\Render\FriendicaSmartyEngine');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the Mode of the Application
|
|
||||||
*
|
|
||||||
* @return App\Mode The Application Mode
|
|
||||||
*
|
|
||||||
* @throws InternalServerErrorException when the mode isn't created
|
|
||||||
*/
|
|
||||||
public function getMode()
|
|
||||||
{
|
|
||||||
if (empty($this->mode)) {
|
|
||||||
throw new InternalServerErrorException('Mode of the Application is not defined');
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->mode;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reloads the whole app instance
|
* Reloads the whole app instance
|
||||||
*/
|
*/
|
||||||
|
@ -369,6 +363,7 @@ class App
|
||||||
$this->config->get('rendertime', 'callstack', false));
|
$this->config->get('rendertime', 'callstack', false));
|
||||||
|
|
||||||
Core\Hook::loadHooks();
|
Core\Hook::loadHooks();
|
||||||
|
$loader = new ConfigCacheLoader($this->basePath, $this->mode);
|
||||||
Core\Hook::callAll('load_config', $loader);
|
Core\Hook::callAll('load_config', $loader);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace Friendica\Core\Config\Cache;
|
namespace Friendica\Core\Config\Cache;
|
||||||
|
|
||||||
|
use Friendica\App;
|
||||||
use Friendica\Core\Addon;
|
use Friendica\Core\Addon;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -23,8 +24,14 @@ class ConfigCacheLoader
|
||||||
private $baseDir;
|
private $baseDir;
|
||||||
private $configDir;
|
private $configDir;
|
||||||
|
|
||||||
public function __construct($baseDir)
|
/**
|
||||||
|
* @var App\Mode
|
||||||
|
*/
|
||||||
|
private $appMode;
|
||||||
|
|
||||||
|
public function __construct($baseDir, App\Mode $mode)
|
||||||
{
|
{
|
||||||
|
$this->appMode = $mode;
|
||||||
$this->baseDir = $baseDir;
|
$this->baseDir = $baseDir;
|
||||||
$this->configDir = $baseDir . DIRECTORY_SEPARATOR . self::SUBDIRECTORY;
|
$this->configDir = $baseDir . DIRECTORY_SEPARATOR . self::SUBDIRECTORY;
|
||||||
}
|
}
|
||||||
|
@ -34,8 +41,12 @@ class ConfigCacheLoader
|
||||||
*
|
*
|
||||||
* First loads the default value for all the configuration keys, then the legacy configuration files, then the
|
* First loads the default value for all the configuration keys, then the legacy configuration files, then the
|
||||||
* expected local.config.php
|
* expected local.config.php
|
||||||
|
*
|
||||||
|
* @param IConfigCache The config cache to load to
|
||||||
|
*
|
||||||
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
public function loadConfigFiles(ConfigCache $config)
|
public function loadConfigFiles(IConfigCache $config)
|
||||||
{
|
{
|
||||||
$config->load($this->loadCoreConfig('defaults'));
|
$config->load($this->loadCoreConfig('defaults'));
|
||||||
$config->load($this->loadCoreConfig('settings'));
|
$config->load($this->loadCoreConfig('settings'));
|
||||||
|
@ -44,6 +55,12 @@ class ConfigCacheLoader
|
||||||
$config->load($this->loadLegacyConfig('htconfig'), true);
|
$config->load($this->loadLegacyConfig('htconfig'), true);
|
||||||
|
|
||||||
$config->load($this->loadCoreConfig('local'), true);
|
$config->load($this->loadCoreConfig('local'), true);
|
||||||
|
|
||||||
|
// In case of install mode, add the found basepath (because there isn't a basepath set yet
|
||||||
|
if ($this->appMode->isInstall()) {
|
||||||
|
// Setting at least the basepath we know
|
||||||
|
$config->set('system', 'basepath', $this->baseDir);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -23,7 +23,8 @@ class DependencyFactory
|
||||||
public static function setUp($channel, $directory, $isBackend = true)
|
public static function setUp($channel, $directory, $isBackend = true)
|
||||||
{
|
{
|
||||||
$basePath = BasePath::create($directory, $_SERVER);
|
$basePath = BasePath::create($directory, $_SERVER);
|
||||||
$configLoader = new Cache\ConfigCacheLoader($basePath);
|
$mode = new App\Mode($basePath);
|
||||||
|
$configLoader = new Cache\ConfigCacheLoader($basePath, $mode);
|
||||||
$configCache = Factory\ConfigFactory::createCache($configLoader);
|
$configCache = Factory\ConfigFactory::createCache($configLoader);
|
||||||
$profiler = Factory\ProfilerFactory::create($configCache);
|
$profiler = Factory\ProfilerFactory::create($configCache);
|
||||||
Factory\DBFactory::init($basePath, $configCache, $profiler, $_SERVER);
|
Factory\DBFactory::init($basePath, $configCache, $profiler, $_SERVER);
|
||||||
|
@ -31,8 +32,8 @@ class DependencyFactory
|
||||||
// needed to call PConfig::init()
|
// needed to call PConfig::init()
|
||||||
Factory\ConfigFactory::createPConfig($configCache);
|
Factory\ConfigFactory::createPConfig($configCache);
|
||||||
$logger = Factory\LoggerFactory::create($channel, $config, $profiler);
|
$logger = Factory\LoggerFactory::create($channel, $config, $profiler);
|
||||||
Factory\LoggerFactory::createDev($channel, $config);
|
Factory\LoggerFactory::createDev($channel, $config, $profiler);
|
||||||
|
|
||||||
return new App($basePath, $config, $logger, $profiler, $isBackend);
|
return new App($basePath, $config, $mode, $logger, $profiler, $isBackend);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
|
|
||||||
namespace Friendica\Test;
|
namespace Friendica\Test;
|
||||||
|
|
||||||
|
use Friendica\App;
|
||||||
use Friendica\Core\Config\Cache;
|
use Friendica\Core\Config\Cache;
|
||||||
use Friendica\Database\DBA;
|
use Friendica\Database\DBA;
|
||||||
use Friendica\Factory;
|
use Friendica\Factory;
|
||||||
|
@ -41,7 +42,8 @@ abstract class DatabaseTest extends MockedTest
|
||||||
}
|
}
|
||||||
|
|
||||||
$basePath = BasePath::create(dirname(__DIR__));
|
$basePath = BasePath::create(dirname(__DIR__));
|
||||||
$configLoader = new Cache\ConfigCacheLoader($basePath);
|
$mode = new App\Mode($basePath);
|
||||||
|
$configLoader = new Cache\ConfigCacheLoader($basePath, $mode);
|
||||||
$config = Factory\ConfigFactory::createCache($configLoader);
|
$config = Factory\ConfigFactory::createCache($configLoader);
|
||||||
|
|
||||||
$profiler = \Mockery::mock(Profiler::class);
|
$profiler = \Mockery::mock(Profiler::class);
|
||||||
|
|
|
@ -37,14 +37,15 @@ class ApiTest extends DatabaseTest
|
||||||
public function setUp()
|
public function setUp()
|
||||||
{
|
{
|
||||||
$basePath = BasePath::create(dirname(__DIR__) . '/../');
|
$basePath = BasePath::create(dirname(__DIR__) . '/../');
|
||||||
$configLoader = new Cache\ConfigCacheLoader($basePath);
|
$mode = new App\Mode($basePath);
|
||||||
|
$configLoader = new Cache\ConfigCacheLoader($basePath, $mode);
|
||||||
$configCache = Factory\ConfigFactory::createCache($configLoader);
|
$configCache = Factory\ConfigFactory::createCache($configLoader);
|
||||||
$profiler = Factory\ProfilerFactory::create($configCache);
|
$profiler = Factory\ProfilerFactory::create($configCache);
|
||||||
Factory\DBFactory::init($basePath, $configCache, $profiler, $_SERVER);
|
Factory\DBFactory::init($basePath, $configCache, $profiler, $_SERVER);
|
||||||
$config = Factory\ConfigFactory::createConfig($configCache);
|
$config = Factory\ConfigFactory::createConfig($configCache);
|
||||||
Factory\ConfigFactory::createPConfig($configCache);
|
Factory\ConfigFactory::createPConfig($configCache);
|
||||||
$logger = Factory\LoggerFactory::create('test', $config, $profiler);
|
$logger = Factory\LoggerFactory::create('test', $config, $profiler);
|
||||||
$this->app = new App($basePath, $config, $logger, $profiler, false);
|
$this->app = new App($basePath, $config, $mode, $logger, $profiler, false);
|
||||||
|
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
|
|
|
@ -14,14 +14,15 @@ class DBATest extends DatabaseTest
|
||||||
public function setUp()
|
public function setUp()
|
||||||
{
|
{
|
||||||
$basePath = BasePath::create(dirname(__DIR__) . '/../../');
|
$basePath = BasePath::create(dirname(__DIR__) . '/../../');
|
||||||
$configLoader = new Cache\ConfigCacheLoader($basePath);
|
$mode = new App\Mode($basePath);
|
||||||
|
$configLoader = new Cache\ConfigCacheLoader($basePath, $mode);
|
||||||
$configCache = Factory\ConfigFactory::createCache($configLoader);
|
$configCache = Factory\ConfigFactory::createCache($configLoader);
|
||||||
$profiler = Factory\ProfilerFactory::create($configCache);
|
$profiler = Factory\ProfilerFactory::create($configCache);
|
||||||
Factory\DBFactory::init($basePath, $configCache, $profiler, $_SERVER);
|
Factory\DBFactory::init($basePath, $configCache, $profiler, $_SERVER);
|
||||||
$config = Factory\ConfigFactory::createConfig($configCache);
|
$config = Factory\ConfigFactory::createConfig($configCache);
|
||||||
Factory\ConfigFactory::createPConfig($configCache);
|
Factory\ConfigFactory::createPConfig($configCache);
|
||||||
$logger = Factory\LoggerFactory::create('test', $config, $profiler);
|
$logger = Factory\LoggerFactory::create('test', $config, $profiler);
|
||||||
$this->app = new App($basePath, $config, $logger, $profiler, false);
|
$this->app = new App($basePath, $config, $mode, $logger, $profiler, false);
|
||||||
|
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
|
|
|
@ -14,14 +14,15 @@ class DBStructureTest extends DatabaseTest
|
||||||
public function setUp()
|
public function setUp()
|
||||||
{
|
{
|
||||||
$basePath = BasePath::create(dirname(__DIR__) . '/../../');
|
$basePath = BasePath::create(dirname(__DIR__) . '/../../');
|
||||||
$configLoader = new Cache\ConfigCacheLoader($basePath);
|
$mode = new App\Mode($basePath);
|
||||||
|
$configLoader = new Cache\ConfigCacheLoader($basePath, $mode);
|
||||||
$configCache = Factory\ConfigFactory::createCache($configLoader);
|
$configCache = Factory\ConfigFactory::createCache($configLoader);
|
||||||
$profiler = Factory\ProfilerFactory::create($configCache);
|
$profiler = Factory\ProfilerFactory::create($configCache);
|
||||||
Factory\DBFactory::init($basePath, $configCache, $profiler, $_SERVER);
|
Factory\DBFactory::init($basePath, $configCache, $profiler, $_SERVER);
|
||||||
$config = Factory\ConfigFactory::createConfig($configCache);
|
$config = Factory\ConfigFactory::createConfig($configCache);
|
||||||
Factory\ConfigFactory::createPConfig($configCache);
|
Factory\ConfigFactory::createPConfig($configCache);
|
||||||
$logger = Factory\LoggerFactory::create('test', $config, $profiler);
|
$logger = Factory\LoggerFactory::create('test', $config, $profiler);
|
||||||
$this->app = new App($basePath, $config, $logger, $profiler, false);
|
$this->app = new App($basePath, $config, $mode, $logger, $profiler, false);
|
||||||
|
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue