From 9682cc440ce8ac227079dde81631eac1b7141b83 Mon Sep 17 00:00:00 2001 From: Philipp Holzer Date: Mon, 5 Aug 2019 09:02:55 +0200 Subject: [PATCH] Using method-chaining for DICE --- bin/auth_ejabberd.php | 4 ++-- bin/console.php | 5 +++-- bin/daemon.php | 4 ++-- bin/worker.php | 9 +++++---- index.php | 5 +++-- tests/functional/DependencyCheckTest.php | 7 +++---- tests/include/ApiTest.php | 6 +++--- tests/src/Database/DBATest.php | 6 +++--- tests/src/Database/DBStructureTest.php | 6 +++--- 9 files changed, 27 insertions(+), 25 deletions(-) diff --git a/bin/auth_ejabberd.php b/bin/auth_ejabberd.php index a097febbc..206e48447 100755 --- a/bin/auth_ejabberd.php +++ b/bin/auth_ejabberd.php @@ -32,6 +32,7 @@ * */ +use Dice\Dice; use Friendica\App\Mode; use Friendica\BaseObject; use Friendica\Util\ExAuth; @@ -52,8 +53,7 @@ chdir($directory); require dirname(__DIR__) . '/vendor/autoload.php'; -$dice = new \Dice\Dice(); -$dice = $dice->addRules(include __DIR__ . '/../static/dependencies.config.php'); +$dice = (new Dice())->addRules(include __DIR__ . '/../static/dependencies.config.php'); BaseObject::setDependencyInjection($dice); $appMode = $dice->create(Mode::class); diff --git a/bin/console.php b/bin/console.php index 3a64d1d2a..4c396854d 100755 --- a/bin/console.php +++ b/bin/console.php @@ -1,9 +1,10 @@ #!/usr/bin/env php addRules(include __DIR__ . '/../static/dependencies.config.php'); +$dice = (new Dice())->addRules(include __DIR__ . '/../static/dependencies.config.php'); (new Friendica\Core\Console($dice, $argv))->execute(); diff --git a/bin/daemon.php b/bin/daemon.php index ac6385cbb..8ea60fa9a 100755 --- a/bin/daemon.php +++ b/bin/daemon.php @@ -7,6 +7,7 @@ * This script was taken from http://php.net/manual/en/function.pcntl-fork.php */ +use Dice\Dice; use Friendica\Core\Config; use Friendica\Core\Logger; use Friendica\Core\Worker; @@ -31,8 +32,7 @@ if (!file_exists("boot.php") && (sizeof($_SERVER["argv"]) != 0)) { require dirname(__DIR__) . '/vendor/autoload.php'; -$dice = new \Dice\Dice(); -$dice = $dice->addRules(include __DIR__ . '/../static/dependencies.config.php'); +$dice = (new Dice())->addRules(include __DIR__ . '/../static/dependencies.config.php'); \Friendica\BaseObject::setDependencyInjection($dice); $a = \Friendica\BaseObject::getApp(); diff --git a/bin/worker.php b/bin/worker.php index e630ee234..f6b2d90a5 100755 --- a/bin/worker.php +++ b/bin/worker.php @@ -5,7 +5,9 @@ * @brief Starts the background processing */ +use Dice\Dice; use Friendica\App; +use Friendica\BaseObject; use Friendica\Core\Config; use Friendica\Core\Update; use Friendica\Core\Worker; @@ -29,11 +31,10 @@ if (!file_exists("boot.php") && (sizeof($_SERVER["argv"]) != 0)) { require dirname(__DIR__) . '/vendor/autoload.php'; -$dice = new \Dice\Dice(); -$dice = $dice->addRules(include __DIR__ . '/../static/dependencies.config.php'); +$dice = (new Dice())->addRules(include __DIR__ . '/../static/dependencies.config.php'); -\Friendica\BaseObject::setDependencyInjection($dice); -$a = \Friendica\BaseObject::getApp(); +BaseObject::setDependencyInjection($dice); +$a = BaseObject::getApp(); // Check the database structure and possibly fixes it Update::check($a->getBasePath(), true, $a->getMode()); diff --git a/index.php b/index.php index 3e5609708..50e553bcd 100644 --- a/index.php +++ b/index.php @@ -4,14 +4,15 @@ * Friendica */ +use Dice\Dice; + 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.'); } require __DIR__ . '/vendor/autoload.php'; -$dice = new \Dice\Dice(); -$dice = $dice->addRules(include __DIR__ . '/static/dependencies.config.php'); +$dice = (new Dice())->addRules(include __DIR__ . '/static/dependencies.config.php'); \Friendica\BaseObject::setDependencyInjection($dice); diff --git a/tests/functional/DependencyCheckTest.php b/tests/functional/DependencyCheckTest.php index bc8d256a7..2a3eed597 100644 --- a/tests/functional/DependencyCheckTest.php +++ b/tests/functional/DependencyCheckTest.php @@ -32,8 +32,8 @@ class dependencyCheck extends TestCase $this->setUpVfsDir(); - $this->dice = new Dice(); - $this->dice = $this->dice->addRules(include __DIR__ . '/../../static/dependencies.config.php'); + $this->dice = (new Dice()) + ->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) - $this->dice = new Dice(include __DIR__ . '/../../static/dependencies.config.php'); - $profiler = $this->dice->create(Profiler::class, [$configCache]); + $this->dice = (new Dice())->create(Profiler::class, [$configCache]); $this->assertInstanceOf(Profiler::class, $profiler); $this->assertTrue($profiler->isRendertime()); diff --git a/tests/include/ApiTest.php b/tests/include/ApiTest.php index 098337aab..3410f3049 100644 --- a/tests/include/ApiTest.php +++ b/tests/include/ApiTest.php @@ -57,9 +57,9 @@ class ApiTest extends DatabaseTest { parent::setUp(); - $this->dice = new Dice(); - $this->dice = $this->dice->addRules(include __DIR__ . '/../../static/dependencies.config.php'); - $this->dice = $this->dice->addRule(Database::class, ['instanceOf' => StaticDatabase::class, 'shared' => true]); + $this->dice = (new Dice()) + ->addRules(include __DIR__ . '/../../static/dependencies.config.php') + ->addRule(Database::class, ['instanceOf' => StaticDatabase::class, 'shared' => true]); BaseObject::setDependencyInjection($this->dice); /** @var Database $dba */ diff --git a/tests/src/Database/DBATest.php b/tests/src/Database/DBATest.php index 6d52581a9..9b2a2f122 100644 --- a/tests/src/Database/DBATest.php +++ b/tests/src/Database/DBATest.php @@ -15,9 +15,9 @@ class DBATest extends DatabaseTest { parent::setUp(); - $dice = new Dice(); - $dice = $dice->addRules(include __DIR__ . '/../../../static/dependencies.config.php'); - $dice = $dice->addRule(Database::class, ['instanceOf' => StaticDatabase::class, 'shared' => true]); + $dice = (new Dice()) + ->addRules(include __DIR__ . '/../../../static/dependencies.config.php') + ->addRule(Database::class, ['instanceOf' => StaticDatabase::class, 'shared' => true]); BaseObject::setDependencyInjection($dice); // Default config diff --git a/tests/src/Database/DBStructureTest.php b/tests/src/Database/DBStructureTest.php index e2938e304..38c621d4c 100644 --- a/tests/src/Database/DBStructureTest.php +++ b/tests/src/Database/DBStructureTest.php @@ -15,9 +15,9 @@ class DBStructureTest extends DatabaseTest { parent::setUp(); - $dice = new Dice(); - $dice = $dice->addRules(include __DIR__ . '/../../../static/dependencies.config.php'); - $dice = $dice->addRule(Database::class, ['instanceOf' => StaticDatabase::class, 'shared' => true]); + $dice = (new Dice()) + ->addRules(include __DIR__ . '/../../../static/dependencies.config.php') + ->addRule(Database::class, ['instanceOf' => StaticDatabase::class, 'shared' => true]); BaseObject::setDependencyInjection($dice); }