mirror of
https://github.com/friendica/friendica
synced 2025-04-26 16:30:12 +00:00
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:
parent
8b344141da
commit
6c2cf494b5
21 changed files with 188 additions and 280 deletions
|
@ -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.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue