Using method-chaining for DICE

This commit is contained in:
Philipp Holzer 2019-08-05 09:02:55 +02:00
parent a66580444f
commit 9682cc440c
No known key found for this signature in database
GPG Key ID: D8365C3D36B77D90
9 changed files with 27 additions and 25 deletions

View File

@ -32,6 +32,7 @@
* *
*/ */
use Dice\Dice;
use Friendica\App\Mode; use Friendica\App\Mode;
use Friendica\BaseObject; use Friendica\BaseObject;
use Friendica\Util\ExAuth; use Friendica\Util\ExAuth;
@ -52,8 +53,7 @@ chdir($directory);
require dirname(__DIR__) . '/vendor/autoload.php'; require dirname(__DIR__) . '/vendor/autoload.php';
$dice = new \Dice\Dice(); $dice = (new Dice())->addRules(include __DIR__ . '/../static/dependencies.config.php');
$dice = $dice->addRules(include __DIR__ . '/../static/dependencies.config.php');
BaseObject::setDependencyInjection($dice); BaseObject::setDependencyInjection($dice);
$appMode = $dice->create(Mode::class); $appMode = $dice->create(Mode::class);

View File

@ -1,9 +1,10 @@
#!/usr/bin/env php #!/usr/bin/env php
<?php <?php
use Dice\Dice;
require dirname(__DIR__) . '/vendor/autoload.php'; require dirname(__DIR__) . '/vendor/autoload.php';
$dice = new \Dice\Dice(); $dice = (new Dice())->addRules(include __DIR__ . '/../static/dependencies.config.php');
$dice = $dice->addRules(include __DIR__ . '/../static/dependencies.config.php');
(new Friendica\Core\Console($dice, $argv))->execute(); (new Friendica\Core\Console($dice, $argv))->execute();

View File

@ -7,6 +7,7 @@
* This script was taken from http://php.net/manual/en/function.pcntl-fork.php * This script was taken from http://php.net/manual/en/function.pcntl-fork.php
*/ */
use Dice\Dice;
use Friendica\Core\Config; use Friendica\Core\Config;
use Friendica\Core\Logger; use Friendica\Core\Logger;
use Friendica\Core\Worker; use Friendica\Core\Worker;
@ -31,8 +32,7 @@ if (!file_exists("boot.php") && (sizeof($_SERVER["argv"]) != 0)) {
require dirname(__DIR__) . '/vendor/autoload.php'; require dirname(__DIR__) . '/vendor/autoload.php';
$dice = new \Dice\Dice(); $dice = (new Dice())->addRules(include __DIR__ . '/../static/dependencies.config.php');
$dice = $dice->addRules(include __DIR__ . '/../static/dependencies.config.php');
\Friendica\BaseObject::setDependencyInjection($dice); \Friendica\BaseObject::setDependencyInjection($dice);
$a = \Friendica\BaseObject::getApp(); $a = \Friendica\BaseObject::getApp();

View File

@ -5,7 +5,9 @@
* @brief Starts the background processing * @brief Starts the background processing
*/ */
use Dice\Dice;
use Friendica\App; use Friendica\App;
use Friendica\BaseObject;
use Friendica\Core\Config; use Friendica\Core\Config;
use Friendica\Core\Update; use Friendica\Core\Update;
use Friendica\Core\Worker; use Friendica\Core\Worker;
@ -29,11 +31,10 @@ if (!file_exists("boot.php") && (sizeof($_SERVER["argv"]) != 0)) {
require dirname(__DIR__) . '/vendor/autoload.php'; require dirname(__DIR__) . '/vendor/autoload.php';
$dice = new \Dice\Dice(); $dice = (new Dice())->addRules(include __DIR__ . '/../static/dependencies.config.php');
$dice = $dice->addRules(include __DIR__ . '/../static/dependencies.config.php');
\Friendica\BaseObject::setDependencyInjection($dice); BaseObject::setDependencyInjection($dice);
$a = \Friendica\BaseObject::getApp(); $a = BaseObject::getApp();
// Check the database structure and possibly fixes it // Check the database structure and possibly fixes it
Update::check($a->getBasePath(), true, $a->getMode()); Update::check($a->getBasePath(), true, $a->getMode());

View File

@ -4,14 +4,15 @@
* Friendica * Friendica
*/ */
use Dice\Dice;
if (!file_exists(__DIR__ . '/vendor/autoload.php')) { if (!file_exists(__DIR__ . '/vendor/autoload.php')) {
die('Vendor path not found. Please execute "bin/composer.phar --no-dev install" on the command line in the web root.'); die('Vendor path not found. Please execute "bin/composer.phar --no-dev install" on the command line in the web root.');
} }
require __DIR__ . '/vendor/autoload.php'; require __DIR__ . '/vendor/autoload.php';
$dice = new \Dice\Dice(); $dice = (new Dice())->addRules(include __DIR__ . '/static/dependencies.config.php');
$dice = $dice->addRules(include __DIR__ . '/static/dependencies.config.php');
\Friendica\BaseObject::setDependencyInjection($dice); \Friendica\BaseObject::setDependencyInjection($dice);

View File

@ -32,8 +32,8 @@ class dependencyCheck extends TestCase
$this->setUpVfsDir(); $this->setUpVfsDir();
$this->dice = new Dice(); $this->dice = (new Dice())
$this->dice = $this->dice->addRules(include __DIR__ . '/../../static/dependencies.config.php'); ->addRules(include __DIR__ . '/../../static/dependencies.config.php');
} }
/** /**
@ -87,8 +87,7 @@ class dependencyCheck extends TestCase
]); ]);
// create new DI-library because of shared instance rule (so the Profiler wouldn't get created twice) // create new DI-library because of shared instance rule (so the Profiler wouldn't get created twice)
$this->dice = new Dice(include __DIR__ . '/../../static/dependencies.config.php'); $this->dice = (new Dice())->create(Profiler::class, [$configCache]);
$profiler = $this->dice->create(Profiler::class, [$configCache]);
$this->assertInstanceOf(Profiler::class, $profiler); $this->assertInstanceOf(Profiler::class, $profiler);
$this->assertTrue($profiler->isRendertime()); $this->assertTrue($profiler->isRendertime());

View File

@ -57,9 +57,9 @@ class ApiTest extends DatabaseTest
{ {
parent::setUp(); parent::setUp();
$this->dice = new Dice(); $this->dice = (new Dice())
$this->dice = $this->dice->addRules(include __DIR__ . '/../../static/dependencies.config.php'); ->addRules(include __DIR__ . '/../../static/dependencies.config.php')
$this->dice = $this->dice->addRule(Database::class, ['instanceOf' => StaticDatabase::class, 'shared' => true]); ->addRule(Database::class, ['instanceOf' => StaticDatabase::class, 'shared' => true]);
BaseObject::setDependencyInjection($this->dice); BaseObject::setDependencyInjection($this->dice);
/** @var Database $dba */ /** @var Database $dba */

View File

@ -15,9 +15,9 @@ class DBATest extends DatabaseTest
{ {
parent::setUp(); parent::setUp();
$dice = new Dice(); $dice = (new Dice())
$dice = $dice->addRules(include __DIR__ . '/../../../static/dependencies.config.php'); ->addRules(include __DIR__ . '/../../../static/dependencies.config.php')
$dice = $dice->addRule(Database::class, ['instanceOf' => StaticDatabase::class, 'shared' => true]); ->addRule(Database::class, ['instanceOf' => StaticDatabase::class, 'shared' => true]);
BaseObject::setDependencyInjection($dice); BaseObject::setDependencyInjection($dice);
// Default config // Default config

View File

@ -15,9 +15,9 @@ class DBStructureTest extends DatabaseTest
{ {
parent::setUp(); parent::setUp();
$dice = new Dice(); $dice = (new Dice())
$dice = $dice->addRules(include __DIR__ . '/../../../static/dependencies.config.php'); ->addRules(include __DIR__ . '/../../../static/dependencies.config.php')
$dice = $dice->addRule(Database::class, ['instanceOf' => StaticDatabase::class, 'shared' => true]); ->addRule(Database::class, ['instanceOf' => StaticDatabase::class, 'shared' => true]);
BaseObject::setDependencyInjection($dice); BaseObject::setDependencyInjection($dice);
} }