1
0
Fork 0

Introduce new DI container

- Adding Friendica\DI class for getting dynamic classes
- Replacing BaseObject::getApp() with this class
This commit is contained in:
Philipp Holzer 2019-12-15 22:34:11 +01:00
commit 1de3f186d7
No known key found for this signature in database
GPG key ID: D8365C3D36B77D90
132 changed files with 377 additions and 270 deletions

View file

@ -9,6 +9,7 @@ namespace Friendica\Core;
use Friendica\App\Page;
use Friendica\BaseObject;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\Contact;
use Friendica\Model\Group;
@ -35,7 +36,7 @@ class ACL extends BaseObject
*/
public static function getSuggestContactSelectHTML($selname, $selclass, array $options = [], array $preselected = [])
{
$a = self::getApp();
$a = DI::app();
$networks = null;
@ -145,7 +146,7 @@ class ACL extends BaseObject
*/
public static function getMessageContactSelectHTML($selname, $selclass, array $preselected = [], $size = 4, $tabindex = null)
{
$a = self::getApp();
$a = DI::app();
$o = '';

View file

@ -7,6 +7,7 @@ namespace Friendica\Core;
use Friendica\BaseObject;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Util\Strings;
/**
@ -177,7 +178,7 @@ class Addon extends BaseObject
@include_once('addon/' . $addon . '/' . $addon . '.php');
if (function_exists($addon . '_install')) {
$func = $addon . '_install';
$func(self::getApp());
$func(DI::app());
$addon_admin = (function_exists($addon . "_addon_admin") ? 1 : 0);
@ -234,11 +235,11 @@ class Addon extends BaseObject
if (function_exists($addon . '_uninstall')) {
$func = $addon . '_uninstall';
$func(self::getApp());
$func(DI::app());
}
if (function_exists($addon . '_install')) {
$func = $addon . '_install';
$func(self::getApp());
$func(DI::app());
}
DBA::update('addon', ['timestamp' => $t], ['id' => $i['id']]);
}
@ -267,7 +268,7 @@ class Addon extends BaseObject
*/
public static function getInfo($addon)
{
$a = self::getApp();
$a = DI::app();
$addon = Strings::sanitizeFilePathItem($addon);

View file

@ -7,6 +7,7 @@ namespace Friendica\Core;
use Friendica\App;
use Friendica\BaseObject;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Util\Strings;
/**
@ -75,7 +76,7 @@ class Hook extends BaseObject
*/
public static function register($hook, $file, $function, $priority = 0)
{
$file = str_replace(self::getApp()->getBasePath() . DIRECTORY_SEPARATOR, '', $file);
$file = str_replace(DI::app()->getBasePath() . DIRECTORY_SEPARATOR, '', $file);
$condition = ['hook' => $hook, 'file' => $file, 'function' => $function];
if (DBA::exists('hook', $condition)) {
@ -98,7 +99,7 @@ class Hook extends BaseObject
*/
public static function unregister($hook, $file, $function)
{
$relative_file = str_replace(self::getApp()->getBasePath() . DIRECTORY_SEPARATOR, '', $file);
$relative_file = str_replace(DI::app()->getBasePath() . DIRECTORY_SEPARATOR, '', $file);
// This here is only needed for fixing a problem that existed on the develop branch
$condition = ['hook' => $hook, 'file' => $file, 'function' => $function];
@ -148,7 +149,7 @@ class Hook extends BaseObject
if ($hook[0] != $fork_hook[0]) {
continue;
}
self::callSingle(self::getApp(), 'hook_fork', $fork_hook, $hookdata);
self::callSingle(DI::app(), 'hook_fork', $fork_hook, $hookdata);
}
if (!$hookdata['execute']) {
@ -175,7 +176,7 @@ class Hook extends BaseObject
{
if (array_key_exists($name, self::$hooks)) {
foreach (self::$hooks[$name] as $hook) {
self::callSingle(self::getApp(), $name, $hook, $data);
self::callSingle(DI::app(), $name, $hook, $data);
}
}
}

View file

@ -7,6 +7,7 @@ namespace Friendica\Core;
use Exception;
use Friendica\BaseObject;
use Friendica\DI;
use Friendica\Render\FriendicaSmarty;
use Friendica\Render\ITemplateEngine;
@ -61,7 +62,7 @@ class Renderer extends BaseObject
public static function replaceMacros($s, array $vars = [])
{
$stamp1 = microtime(true);
$a = self::getApp();
$a = DI::app();
// pass $baseurl to all templates if it isn't set
$vars = array_merge(['$baseurl' => $a->getBaseURL()], $vars);
@ -92,7 +93,7 @@ class Renderer extends BaseObject
public static function getMarkupTemplate($s, $root = '')
{
$stamp1 = microtime(true);
$a = self::getApp();
$a = DI::app();
$t = self::getTemplateEngine();
try {

View file

@ -4,6 +4,7 @@ namespace Friendica\Core;
use Friendica\BaseObject;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\Contact;
use Friendica\Model\GContact;
use Friendica\Network\HTTPException;
@ -92,7 +93,7 @@ class Search extends BaseObject
*/
public static function getContactsFromGlobalDirectory($search, $type = self::TYPE_ALL, $page = 1)
{
$config = self::getApp()->getConfig();
$config = DI::app()->getConfig();
$server = $config->get('system', 'directory', self::DEFAULT_DIRECTORY);
$searchUrl = $server . '/search';
@ -158,7 +159,7 @@ class Search extends BaseObject
*/
public static function getContactsFromLocalDirectory($search, $type = self::TYPE_ALL, $start = 0, $itemPage = 80)
{
$config = self::getApp()->getConfig();
$config = DI::app()->getConfig();
$diaspora = $config->get('system', 'diaspora_enabled') ? Protocol::DIASPORA : Protocol::DFRN;
$ostatus = !$config->get('system', 'ostatus_disabled') ? Protocol::OSTATUS : Protocol::DFRN;

View file

@ -6,6 +6,7 @@ namespace Friendica\Core;
use Friendica\App\BaseURL;
use Friendica\BaseObject;
use Friendica\DI;
use Friendica\Network\HTTPException\InternalServerErrorException;
use Friendica\Util\XML;
@ -43,7 +44,7 @@ class System extends BaseObject
*/
public static function removedBaseUrl(string $orig_url)
{
return self::getApp()->removeBaseURL($orig_url);
return DI::app()->removeBaseURL($orig_url);
}
/**
@ -184,7 +185,7 @@ class System extends BaseObject
if (is_bool($prefix) && !$prefix) {
$prefix = '';
} elseif (empty($prefix)) {
$prefix = hash('crc32', self::getApp()->getHostName());
$prefix = hash('crc32', DI::app()->getHostName());
}
while (strlen($prefix) < ($size - 13)) {

View file

@ -7,6 +7,7 @@
namespace Friendica\Core;
use Friendica\BaseObject;
use Friendica\DI;
use Friendica\Model\Profile;
use Friendica\Util\Strings;
@ -194,7 +195,7 @@ class Theme
*/
public static function getPathForFile($file)
{
$a = BaseObject::getApp();
$a = DI::app();
$theme = $a->getCurrentTheme();
@ -232,7 +233,7 @@ class Theme
return 'view/theme/' . $theme . '/style.css';
}
$a = BaseObject::getApp();
$a = DI::app();
$query_params = [];

View file

@ -7,6 +7,7 @@ namespace Friendica\Core;
use Friendica\BaseObject;
use Friendica\Core;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\Process;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Network;
@ -1232,11 +1233,11 @@ class Worker
*/
public static function defer()
{
if (empty(BaseObject::getApp()->queue)) {
if (empty(DI::app()->queue)) {
return false;
}
$queue = BaseObject::getApp()->queue;
$queue = DI::app()->queue;
$retrial = $queue['retrial'];
$id = $queue['id'];