Remove DependencyFactory

- Include all necessary classes in `dependencies.config.php`
- Add DI-reference to BaseObject (acts as a global registry)
- Refactor all static "init()" methods to use the global registry

- Refactor Logging for Worker-Logger a little bit
This commit is contained in:
Philipp Holzer 2019-07-21 20:24:16 +02:00
parent 8b344141da
commit 6c2cf494b5
No known key found for this signature in database
GPG key ID: D8365C3D36B77D90
21 changed files with 188 additions and 280 deletions

View file

@ -6,19 +6,32 @@ namespace Friendica;
require_once __DIR__ . '/../boot.php';
use Dice\Dice;
use Friendica\Network\HTTPException\InternalServerErrorException;
/**
* Basic object
*
* Contains what is useful to any object
*
* Act's like a global registry for classes
*/
class BaseObject
{
/**
* @var App
* @var Dice The Dependency Injection library
*/
private static $app = null;
private static $dice;
/**
* Set's the dependency injection library for a global usage
*
* @param Dice $dice The dependency injection library
*/
public static function setDependencyInjection(Dice $dice)
{
self::$dice = $dice;
}
/**
* Get the app
@ -26,26 +39,27 @@ class BaseObject
* Same as get_app from boot.php
*
* @return App
* @throws \Exception
*/
public static function getApp()
{
if (empty(self::$app)) {
throw new InternalServerErrorException('App isn\'t initialized.');
}
return self::$app;
return self::$dice->create(App::class);
}
/**
* Set the app
* Returns the initialized class based on it's name
*
* @param App $app App
* @param string $name The name of the class
*
* @return void
* @return object The initialized name
*
* @throws InternalServerErrorException
*/
public static function setApp(App $app)
public static function getClass(string $name)
{
self::$app = $app;
if (class_exists($name) || interface_exists($name )) {
return self::$dice->create($name);
} else {
throw new InternalServerErrorException('Class \'' . $name . '\' isn\'t valid.');
}
}
}