1
0
Fork 0

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:
Philipp Holzer 2019-07-21 01:22:10 +02:00
commit 55999730e0
No known key found for this signature in database
GPG key ID: D8365C3D36B77D90
28 changed files with 563 additions and 308 deletions

View file

@ -4,36 +4,55 @@ namespace Friendica\Util;
class BasePath
{
/**
* @var string
*/
private $baseDir;
/**
* @var array
*/
private $server;
/**
* @param string|null $baseDir The default base path
* @param array $server server arguments
*/
public function __construct(string $baseDir, array $server = [])
{
$this->baseDir = $baseDir;
$this->server = $server;
}
/**
* @brief Returns the base filesystem path of the App
*
* It first checks for the internal variable, then for DOCUMENT_ROOT and
* finally for PWD
*
* @param string|null $basePath The default base path
* @param array $server server arguments
*
* @return string
*
* @throws \Exception if directory isn't usable
*/
public static function create($basePath, array $server = [])
public function getPath()
{
if ((!$basePath || !is_dir($basePath)) && !empty($server['DOCUMENT_ROOT'])) {
$basePath = $server['DOCUMENT_ROOT'];
$baseDir = $this->baseDir;
$server = $this->server;
if ((!$baseDir || !is_dir($baseDir)) && !empty($server['DOCUMENT_ROOT'])) {
$baseDir = $server['DOCUMENT_ROOT'];
}
if ((!$basePath || !is_dir($basePath)) && !empty($server['PWD'])) {
$basePath = $server['PWD'];
if ((!$baseDir || !is_dir($baseDir)) && !empty($server['PWD'])) {
$baseDir = $server['PWD'];
}
$basePath = self::getRealPath($basePath);
$baseDir = self::getRealPath($baseDir);
if (!is_dir($basePath)) {
throw new \Exception(sprintf('\'%s\' is not a valid basepath', $basePath));
if (!is_dir($baseDir)) {
throw new \Exception(sprintf('\'%s\' is not a valid basepath', $baseDir));
}
return $basePath;
return $baseDir;
}
/**

View file

@ -3,7 +3,6 @@
namespace Friendica\Util;
use Exception;
use Friendica\App;
use Friendica\Core\Addon;
use Friendica\Core\Config\Cache\ConfigCache;
@ -52,10 +51,6 @@ class ConfigFileLoader
*/
const SAMPLE_END = '-sample';
/**
* @var App\Mode
*/
private $appMode;
/**
* @var string
*/
@ -69,12 +64,11 @@ class ConfigFileLoader
*/
private $staticDir;
public function __construct($baseDir, App\Mode $mode)
public function __construct(string $basePath)
{
$this->baseDir = $baseDir;
$this->configDir = $baseDir . DIRECTORY_SEPARATOR . self::CONFIG_DIR;
$this->staticDir = $baseDir . DIRECTORY_SEPARATOR . self::STATIC_DIR;
$this->appMode = $mode;
$this->baseDir = $basePath;
$this->configDir = $this->baseDir . DIRECTORY_SEPARATOR . self::CONFIG_DIR;
$this->staticDir = $this->baseDir . DIRECTORY_SEPARATOR . self::STATIC_DIR;
}
/**
@ -102,7 +96,7 @@ class ConfigFileLoader
$this->loadCoreConfig($config);
// In case of install mode, add the found basepath (because there isn't a basepath set yet
if (!$raw && ($this->appMode->isInstall() || empty($config->get('system', 'basepath')))) {
if (!$raw && empty($config->get('system', 'basepath'))) {
// Setting at least the basepath we know
$config->set('system', 'basepath', $this->baseDir);
}

View file

@ -2,6 +2,8 @@
namespace Friendica\Util;
use Friendica\Core\Config\Cache\ConfigCache;
use Friendica\Core\Config\Configuration;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\ContainerInterface;
use Psr\Container\NotFoundExceptionInterface;
@ -45,23 +47,21 @@ class Profiler implements ContainerInterface
/**
* Updates the enabling of the current profiler
*
* @param bool $enabled
* @param bool $renderTime
* @param Configuration $config
*/
public function update($enabled = false, $renderTime = false)
public function update(Configuration $config)
{
$this->enabled = $enabled;
$this->rendertime = $renderTime;
$this->enabled = $config->get('system', 'profiler');
$this->rendertime = $config->get('rendertime', 'callstack');
}
/**
* @param bool $enabled True, if the Profiler is enabled
* @param bool $renderTime True, if the Profiler should measure the whole rendertime including functions
* @param ConfigCache $configCache The configuration cache
*/
public function __construct($enabled = false, $renderTime = false)
public function __construct(ConfigCache $configCache)
{
$this->enabled = $enabled;
$this->rendertime = $renderTime;
$this->enabled = $configCache->get('system', 'profiler');
$this->rendertime = $configCache->get('rendertime', 'callstack');
$this->reset();
}