mirror of https://github.com/friendica/friendica
Move AppMode
This commit is contained in:
parent
c567328ab2
commit
505d8c18d0
34
src/App.php
34
src/App.php
|
@ -163,6 +163,16 @@ class App
|
|||
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.
|
||||
* Inclusion is done in App->initHead().
|
||||
|
@ -206,19 +216,21 @@ class App
|
|||
* @brief App constructor.
|
||||
*
|
||||
* @param Configuration $config The Configuration
|
||||
* @param App\Mode $mode The mode of this Friendica app
|
||||
* @param LoggerInterface $logger The current app logger
|
||||
* @param Profiler $profiler The profiler of this application
|
||||
* @param bool $isBackend Whether it is used for backend or frontend (Default true=backend)
|
||||
*
|
||||
* @throws Exception if the Basepath is not usable
|
||||
*/
|
||||
public function __construct(Configuration $config, LoggerInterface $logger, Profiler $profiler, $isBackend = true)
|
||||
public function __construct(Configuration $config, App\Mode $mode, LoggerInterface $logger, Profiler $profiler, $isBackend = true)
|
||||
{
|
||||
BaseObject::setApp($this);
|
||||
|
||||
$this->logger = $logger;
|
||||
$this->config = $config;
|
||||
$this->profiler = $profiler;
|
||||
$this->mode = $mode;
|
||||
$this->basePath = $this->config->get('system', 'basepath');
|
||||
|
||||
if (!Core\System::isDirectoryUsable($this->basePath, false)) {
|
||||
|
@ -231,8 +243,6 @@ class App
|
|||
|
||||
$this->profiler->reset();
|
||||
|
||||
$this->mode = new App\Mode($this->basePath);
|
||||
|
||||
$this->reload();
|
||||
|
||||
set_time_limit(0);
|
||||
|
@ -332,22 +342,6 @@ class App
|
|||
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
|
||||
*/
|
||||
|
@ -359,7 +353,7 @@ class App
|
|||
|
||||
if ($this->getMode()->has(App\Mode::DBAVAILABLE)) {
|
||||
Core\Hook::loadHooks();
|
||||
$loader = new ConfigCacheLoader($this->basePath);
|
||||
$loader = new ConfigCacheLoader($this->basePath, $this->mode);
|
||||
Core\Hook::callAll('load_config', $loader);
|
||||
$this->config->getCache()->load($loader->loadCoreConfig('addon'), true);
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Friendica\Core\Config\Cache;
|
||||
|
||||
use Friendica\App;
|
||||
use Friendica\Core\Addon;
|
||||
|
||||
/**
|
||||
|
@ -23,8 +24,14 @@ class ConfigCacheLoader
|
|||
private $baseDir;
|
||||
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->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
|
||||
* expected local.config.php
|
||||
*
|
||||
* @param IConfigCache The config cache to load to
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function loadConfigFiles(ConfigCache $config)
|
||||
public function loadConfigFiles(IConfigCache $config)
|
||||
{
|
||||
// Setting at least the basepath we know
|
||||
$config->set('system', 'basepath', $this->baseDir);
|
||||
|
@ -47,6 +58,12 @@ class ConfigCacheLoader
|
|||
$config->load($this->loadLegacyConfig('htconfig'), 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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -22,8 +22,9 @@ class DependencyFactory
|
|||
*/
|
||||
public static function setUp($channel, $directory, $isBackend = true)
|
||||
{
|
||||
$basedir = BasePath::create($directory, $_SERVER);
|
||||
$configLoader = new Cache\ConfigCacheLoader($basedir);
|
||||
$basePath = BasePath::create($directory, $_SERVER);
|
||||
$mode = new App\Mode($basePath);
|
||||
$configLoader = new Cache\ConfigCacheLoader($basePath, $mode);
|
||||
$configCache = Factory\ConfigFactory::createCache($configLoader);
|
||||
$profiler = Factory\ProfilerFactory::create($configCache);
|
||||
Factory\DBFactory::init($configCache, $profiler, $_SERVER);
|
||||
|
@ -32,6 +33,6 @@ class DependencyFactory
|
|||
Factory\ConfigFactory::createPConfig($configCache);
|
||||
$logger = Factory\LoggerFactory::create($channel, $config, $profiler);
|
||||
|
||||
return new App($config, $logger, $profiler, $isBackend);
|
||||
return new App($config, $mode, $logger, $profiler, $isBackend);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -222,6 +222,7 @@ class LoggerFactory
|
|||
if (!is_int($loglevel)) {
|
||||
$loglevel = LogLevel::NOTICE;
|
||||
}
|
||||
|
||||
$fileHandler = new Monolog\Handler\StreamHandler($stream, $loglevel);
|
||||
|
||||
$formatter = new Monolog\Formatter\LineFormatter("%datetime% %channel% [%level_name%]: %message% %context% %extra%\n");
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
namespace Friendica\Test;
|
||||
|
||||
use Friendica\App;
|
||||
use Friendica\Core\Config\Cache;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\Factory;
|
||||
|
@ -40,8 +41,9 @@ abstract class DatabaseTest extends MockedTest
|
|||
$this->markTestSkipped('Please set the MYSQL_* environment variables to your test database credentials.');
|
||||
}
|
||||
|
||||
$basedir = BasePath::create(dirname(__DIR__));
|
||||
$configLoader = new Cache\ConfigCacheLoader($basedir);
|
||||
$basepath = BasePath::create(dirname(__DIR__));
|
||||
$mode = new App\Mode($basepath);
|
||||
$configLoader = new Cache\ConfigCacheLoader($basepath, $mode);
|
||||
$config = Factory\ConfigFactory::createCache($configLoader);
|
||||
|
||||
$profiler = \Mockery::mock(Profiler::class);
|
||||
|
|
|
@ -36,15 +36,16 @@ class ApiTest extends DatabaseTest
|
|||
*/
|
||||
public function setUp()
|
||||
{
|
||||
$basedir = BasePath::create(dirname(__DIR__) . '/../');
|
||||
$configLoader = new Cache\ConfigCacheLoader($basedir);
|
||||
$basePath = BasePath::create(dirname(__DIR__) . '/../');
|
||||
$mode = new App\Mode($basePath);
|
||||
$configLoader = new Cache\ConfigCacheLoader($basePath, $mode);
|
||||
$configCache = Factory\ConfigFactory::createCache($configLoader);
|
||||
$profiler = Factory\ProfilerFactory::create($configCache);
|
||||
Factory\DBFactory::init($configCache, $profiler, $_SERVER);
|
||||
$config = Factory\ConfigFactory::createConfig($configCache);
|
||||
Factory\ConfigFactory::createPConfig($configCache);
|
||||
$logger = Factory\LoggerFactory::create('test', $config, $profiler);
|
||||
$this->app = new App($config, $logger, $profiler, false);
|
||||
$this->app = new App($config, $mode, $logger, $profiler, false);
|
||||
|
||||
parent::setUp();
|
||||
|
||||
|
|
|
@ -13,15 +13,16 @@ class DBATest extends DatabaseTest
|
|||
{
|
||||
public function setUp()
|
||||
{
|
||||
$basedir = BasePath::create(dirname(__DIR__) . '/../../');
|
||||
$configLoader = new Cache\ConfigCacheLoader($basedir);
|
||||
$basePath = BasePath::create(dirname(__DIR__) . '/../../');
|
||||
$mode = new App\Mode($basePath);
|
||||
$configLoader = new Cache\ConfigCacheLoader($basePath, $mode);
|
||||
$configCache = Factory\ConfigFactory::createCache($configLoader);
|
||||
$profiler = Factory\ProfilerFactory::create($configCache);
|
||||
Factory\DBFactory::init($configCache, $profiler, $_SERVER);
|
||||
$config = Factory\ConfigFactory::createConfig($configCache);
|
||||
Factory\ConfigFactory::createPConfig($configCache);
|
||||
$logger = Factory\LoggerFactory::create('test', $config, $profiler);
|
||||
$this->app = new App($config, $logger, $profiler, false);
|
||||
$this->app = new App($config, $mode, $logger, $profiler, false);
|
||||
|
||||
parent::setUp();
|
||||
|
||||
|
|
|
@ -13,15 +13,16 @@ class DBStructureTest extends DatabaseTest
|
|||
{
|
||||
public function setUp()
|
||||
{
|
||||
$basedir = BasePath::create(dirname(__DIR__) . '/../../');
|
||||
$configLoader = new Cache\ConfigCacheLoader($basedir);
|
||||
$basePath = BasePath::create(dirname(__DIR__) . '/../../');
|
||||
$mode = new App\Mode($basePath);
|
||||
$configLoader = new Cache\ConfigCacheLoader($basePath, $mode);
|
||||
$configCache = Factory\ConfigFactory::createCache($configLoader);
|
||||
$profiler = Factory\ProfilerFactory::create($configCache);
|
||||
Factory\DBFactory::init($configCache, $profiler, $_SERVER);
|
||||
$config = Factory\ConfigFactory::createConfig($configCache);
|
||||
Factory\ConfigFactory::createPConfig($configCache);
|
||||
$logger = Factory\LoggerFactory::create('test', $config, $profiler);
|
||||
$this->app = new App($config, $logger, $profiler, false);
|
||||
$this->app = new App($config, $mode, $logger, $profiler, false);
|
||||
|
||||
parent::setUp();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue