mirror of
https://git.sekbaer.de/Friendica/friendica.git
synced 2025-06-17 04:15:15 +02:00
Introduce DICE
- Adding dice library - Adding dependency config - Removing Factories - Refactoring App\Mode constructor - Refactoring App\Router constructor - Refactoring BasePath for DI usage - Refactoring ConfigFileLoader constructor - Refactoring Profiler constructor - Adjust entrypoints (index, console, worker, ..) - Adding functional test for DI - Fix tests because of refactorings
This commit is contained in:
parent
5887b9c499
commit
55999730e0
28 changed files with 563 additions and 308 deletions
|
@ -2,8 +2,9 @@
|
|||
|
||||
namespace Friendica\App;
|
||||
|
||||
use Friendica\Core\Config;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\Core\Config\Cache\ConfigCache;
|
||||
use Friendica\Database\Database;
|
||||
use Friendica\Util\BasePath;
|
||||
|
||||
/**
|
||||
* Mode of the current Friendica Node
|
||||
|
@ -28,10 +29,22 @@ class Mode
|
|||
*/
|
||||
private $basepath;
|
||||
|
||||
public function __construct($basepath = '')
|
||||
/**
|
||||
* @var Database
|
||||
*/
|
||||
private $database;
|
||||
|
||||
/**
|
||||
* @var ConfigCache
|
||||
*/
|
||||
private $configCache;
|
||||
|
||||
public function __construct(BasePath $basepath, Database $database, ConfigCache $configCache)
|
||||
{
|
||||
$this->basepath = $basepath;
|
||||
$this->mode = 0;
|
||||
$this->basepath = $basepath->getPath();
|
||||
$this->database = $database;
|
||||
$this->configCache = $configCache;
|
||||
$this->mode = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -41,42 +54,48 @@ class Mode
|
|||
* - App::MODE_MAINTENANCE: The maintenance mode has been set
|
||||
* - App::MODE_NORMAL : Normal run with all features enabled
|
||||
*
|
||||
* @param string $basepath the Basepath of the Application
|
||||
* @param string $basePath the Basepath of the Application
|
||||
*
|
||||
* @return Mode returns itself
|
||||
*
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
*/
|
||||
public function determine($basepath = null)
|
||||
public function determine($basePath = null)
|
||||
{
|
||||
if (!empty($basepath)) {
|
||||
$this->basepath = $basepath;
|
||||
if (!empty($basePath)) {
|
||||
$this->basepath = $basePath;
|
||||
}
|
||||
|
||||
$this->mode = 0;
|
||||
|
||||
if (!file_exists($this->basepath . '/config/local.config.php')
|
||||
&& !file_exists($this->basepath . '/config/local.ini.php')
|
||||
&& !file_exists($this->basepath . '/.htconfig.php')) {
|
||||
return;
|
||||
&& !file_exists($this->basepath . '/config/local.ini.php')
|
||||
&& !file_exists($this->basepath . '/.htconfig.php')) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
$this->mode |= Mode::LOCALCONFIGPRESENT;
|
||||
|
||||
if (!DBA::connected()) {
|
||||
return;
|
||||
if (!$this->database->connected()) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
$this->mode |= Mode::DBAVAILABLE;
|
||||
|
||||
if (DBA::fetchFirst("SHOW TABLES LIKE 'config'") === false) {
|
||||
return;
|
||||
if ($this->database->fetchFirst("SHOW TABLES LIKE 'config'") === false) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
$this->mode |= Mode::DBCONFIGAVAILABLE;
|
||||
|
||||
if (Config::get('system', 'maintenance')) {
|
||||
return;
|
||||
if ($this->configCache->get('system', 'maintenance') ||
|
||||
$this->database->selectFirst('config', ['v'], ['cat' => 'system', 'k' => 'maintenance'])) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
$this->mode |= Mode::MAINTENANCEDISABLED;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -100,7 +119,7 @@ class Mode
|
|||
public function isInstall()
|
||||
{
|
||||
return !$this->has(Mode::LOCALCONFIGPRESENT) ||
|
||||
!$this->has(MODE::DBCONFIGAVAILABLE);
|
||||
!$this->has(MODE::DBCONFIGAVAILABLE);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -111,8 +130,8 @@ class Mode
|
|||
public function isNormal()
|
||||
{
|
||||
return $this->has(Mode::LOCALCONFIGPRESENT) &&
|
||||
$this->has(Mode::DBAVAILABLE) &&
|
||||
$this->has(Mode::DBCONFIGAVAILABLE) &&
|
||||
$this->has(Mode::MAINTENANCEDISABLED);
|
||||
$this->has(Mode::DBAVAILABLE) &&
|
||||
$this->has(Mode::DBCONFIGAVAILABLE) &&
|
||||
$this->has(Mode::MAINTENANCEDISABLED);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue