Browse Source

Using method-chaining for DICE

pull/7465/head
Philipp Holzer 2 weeks ago
parent
commit
9682cc440c
No account linked to committer's email address

+ 2
- 2
bin/auth_ejabberd.php View File

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

+ 3
- 2
bin/console.php View File

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

+ 2
- 2
bin/daemon.php View File

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

+ 5
- 4
bin/worker.php View File

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

+ 3
- 2
index.php View File

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

+ 3
- 4
tests/functional/DependencyCheckTest.php View File

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

+ 3
- 3
tests/include/ApiTest.php View File

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

+ 3
- 3
tests/src/Database/DBATest.php View File

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

+ 3
- 3
tests/src/Database/DBStructureTest.php View File

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

Loading…
Cancel
Save