]> git.mxchange.org Git - friendica.git/blob - static/dependencies.config.php
c1ce4f3b56473c5a5c2df4fe18de4aabac4933a8
[friendica.git] / static / dependencies.config.php
1 <?php
2
3 use Dice\Dice;
4 use Friendica\App;
5 use Friendica\Core\Config;
6 use Friendica\Database\Database;
7 use Friendica\Factory;
8 use Friendica\Util;
9 use Psr\Log\LoggerInterface;
10
11 /**
12  * The configuration defines "complex" dependencies inside Friendica
13  * So this classes shouldn't be simple or their dependencies are already defined here.
14  *
15  * This kind of dependencies are NOT required to be defined here:
16  *   - $a = new ClassA(new ClassB());
17  *   - $a = new ClassA();
18  *   - $a = new ClassA(Configuration $configuration);
19  *
20  * This kind of dependencies SHOULD be defined here:
21  *   - $a = new ClassA();
22  *     $b = $a->create();
23  *
24  *   - $a = new ClassA($creationPassedVariable);
25  *
26  */
27 return [
28         '$basepath' => [
29                 'instanceOf' => Util\BasePath::class,
30                 'call' => [
31                         ['getPath', [], Dice::CHAIN_CALL],
32                 ],
33                 'constructParams' => [
34                         dirname(__FILE__, 2),
35                         $_SERVER
36                 ]
37         ],
38         Util\BasePath::class => [
39                 'shared'          => true,
40                 'constructParams' => [
41                         dirname(__FILE__, 2),
42                         $_SERVER
43                 ]
44         ],
45         Util\ConfigFileLoader::class => [
46                 'shared' => true,
47                 'constructParams' => [
48                         [Dice::INSTANCE => '$basepath'],
49                 ],
50         ],
51         Config\Cache\ConfigCache::class => [
52                 'instanceOf' => Factory\ConfigFactory::class,
53                 'call'       => [
54                         ['createCache', [], Dice::CHAIN_CALL],
55                 ],
56                 'shared'     => true,
57         ],
58         App\Mode::class => [
59                 'call'   => [
60                         ['determine', [], Dice::CHAIN_CALL],
61                 ],
62                 // marks the result as shared for other creations, so there's just
63                 // one instance for the whole execution
64                 'shared' => true,
65         ],
66         Config\Configuration::class => [
67                 'shared' => true,
68                 'instanceOf' => Factory\ConfigFactory::class,
69                 'call' => [
70                         ['createConfig', [], Dice::CHAIN_CALL],
71                 ],
72         ],
73         Config\PConfiguration::class => [
74                 'shared' => true,
75                 'instanceOf' => Factory\ConfigFactory::class,
76                 'call' => [
77                         ['createPConfig', [], Dice::CHAIN_CALL],
78                 ]
79         ],
80         Database::class => [
81                 'shared' => true,
82                 'constructParams' => [
83                         [DICE::INSTANCE => \Psr\Log\NullLogger::class],
84                         $_SERVER,
85                 ],
86         ],
87         /**
88          * Creates the Util\BaseURL
89          *
90          * Same as:
91          *   $baseURL = new Util\BaseURL($configuration, $_SERVER);
92          */
93         Util\BaseURL::class => [
94                 'shared'          => true,
95                 'constructParams' => [
96                         $_SERVER,
97                 ],
98         ],
99         /**
100          * Create a Logger, which implements the LoggerInterface
101          *
102          * Same as:
103          *   $loggerFactory = new Factory\LoggerFactory();
104          *   $logger = $loggerFactory->create($channel, $configuration, $profiler);
105          *
106          * Attention1: We can use DICE for detecting dependencies inside "chained" calls too
107          * Attention2: The variable "$channel" is passed inside the creation of the dependencies per:
108          *    $app = $dice->create(App::class, [], ['$channel' => 'index']);
109          *    and is automatically passed as an argument with the same name
110          */
111         LoggerInterface::class => [
112                 'shared'     => true,
113                 'instanceOf' => Factory\LoggerFactory::class,
114                 'call'       => [
115                         ['create', [], Dice::CHAIN_CALL],
116                 ],
117         ],
118         '$devLogger' => [
119                 'shared'     => true,
120                 'instanceOf' => Factory\LoggerFactory::class,
121                 'call'       => [
122                         ['createDev', [], Dice::CHAIN_CALL],
123                 ]
124         ]
125 ];