]> git.mxchange.org Git - friendica.git/blob - static/dependencies.config.php
Merge pull request #7963 from annando/issue-7659-a
[friendica.git] / static / dependencies.config.php
1 <?php
2
3 use Dice\Dice;
4 use Friendica\App;
5 use Friendica\Core\Cache;
6 use Friendica\Core\Config;
7 use Friendica\Core\L10n\L10n;
8 use Friendica\Core\Lock\ILock;
9 use Friendica\Database\Database;
10 use Friendica\Factory;
11 use Friendica\Util;
12 use Psr\Log\LoggerInterface;
13
14 /**
15  * The configuration defines "complex" dependencies inside Friendica
16  * So this classes shouldn't be simple or their dependencies are already defined here.
17  *
18  * This kind of dependencies are NOT required to be defined here:
19  *   - $a = new ClassA(new ClassB());
20  *   - $a = new ClassA();
21  *   - $a = new ClassA(Configuration $configuration);
22  *
23  * This kind of dependencies SHOULD be defined here:
24  *   - $a = new ClassA();
25  *     $b = $a->create();
26  *
27  *   - $a = new ClassA($creationPassedVariable);
28  *
29  */
30 return [
31         '*'                             => [
32                 // marks all class result as shared for other creations, so there's just
33                 // one instance for the whole execution
34                 'shared' => true,
35         ],
36         '$basepath'                     => [
37                 'instanceOf'      => Util\BasePath::class,
38                 'call'            => [
39                         ['getPath', [], Dice::CHAIN_CALL],
40                 ],
41                 'constructParams' => [
42                         dirname(__FILE__, 2),
43                         $_SERVER
44                 ]
45         ],
46         Util\BasePath::class            => [
47                 'constructParams' => [
48                         dirname(__FILE__, 2),
49                         $_SERVER
50                 ]
51         ],
52         Util\ConfigFileLoader::class    => [
53                 'shared'          => true,
54                 'constructParams' => [
55                         [Dice::INSTANCE => '$basepath'],
56                 ],
57         ],
58         Config\Cache\ConfigCache::class => [
59                 'instanceOf' => Factory\ConfigFactory::class,
60                 'call'       => [
61                         ['createCache', [], Dice::CHAIN_CALL],
62                 ],
63         ],
64         App\Mode::class                 => [
65                 'call' => [
66                         ['determineRunMode', [true, $_SERVER], Dice::CHAIN_CALL],
67                         ['determine', [], Dice::CHAIN_CALL],
68                 ],
69         ],
70         Config\Configuration::class     => [
71                 'instanceOf' => Factory\ConfigFactory::class,
72                 'call'       => [
73                         ['createConfig', [], Dice::CHAIN_CALL],
74                 ],
75         ],
76         Config\PConfiguration::class    => [
77                 'instanceOf' => Factory\ConfigFactory::class,
78                 'call'       => [
79                         ['createPConfig', [], Dice::CHAIN_CALL],
80                 ]
81         ],
82         Database::class                 => [
83                 'constructParams' => [
84                         [DICE::INSTANCE => \Psr\Log\NullLogger::class],
85                         $_SERVER,
86                 ],
87         ],
88         /**
89          * Creates the App\BaseURL
90          *
91          * Same as:
92          *   $baseURL = new App\BaseURL($configuration, $_SERVER);
93          */
94         App\BaseURL::class             => [
95                 'constructParams' => [
96                         $_SERVER,
97                 ],
98         ],
99         App\Page::class => [
100                 'constructParams' => [
101                         [Dice::INSTANCE => '$basepath'],
102                 ],
103         ],
104         /**
105          * Create a Logger, which implements the LoggerInterface
106          *
107          * Same as:
108          *   $loggerFactory = new Factory\LoggerFactory();
109          *   $logger = $loggerFactory->create($channel, $configuration, $profiler);
110          *
111          * Attention1: We can use DICE for detecting dependencies inside "chained" calls too
112          * Attention2: The variable "$channel" is passed inside the creation of the dependencies per:
113          *    $app = $dice->create(App::class, [], ['$channel' => 'index']);
114          *    and is automatically passed as an argument with the same name
115          */
116         LoggerInterface::class          => [
117                 'instanceOf' => Factory\LoggerFactory::class,
118                 'constructParams' => [
119                         'index',
120                 ],
121                 'call'       => [
122                         ['create', ['index'], Dice::CHAIN_CALL],
123                 ],
124         ],
125         '$devLogger'                    => [
126                 'instanceOf' => Factory\LoggerFactory::class,
127                 'constructParams' => [
128                         'dev',
129                 ],
130                 'call'       => [
131                         ['createDev', [], Dice::CHAIN_CALL],
132                 ]
133         ],
134         Cache\ICache::class             => [
135                 'instanceOf' => Factory\CacheFactory::class,
136                 'call'       => [
137                         ['create', [], Dice::CHAIN_CALL],
138                 ],
139         ],
140         Cache\IMemoryCache::class       => [
141                 'instanceOf' => Factory\CacheFactory::class,
142                 'call'       => [
143                         ['create', [], Dice::CHAIN_CALL],
144                 ],
145         ],
146         ILock::class                    => [
147                 'instanceOf' => Factory\LockFactory::class,
148                 'call'       => [
149                         ['create', [], Dice::CHAIN_CALL],
150                 ],
151         ],
152         App\Arguments::class => [
153                 'instanceOf' => App\Arguments::class,
154                 'call' => [
155                         ['determine', [$_SERVER, $_GET], Dice::CHAIN_CALL],
156                 ],
157         ],
158         App\Module::class => [
159                 'instanceOf' => App\Module::class,
160                 'call' => [
161                         ['determineModule', [], Dice::CHAIN_CALL],
162                 ],
163         ],
164         Friendica\Core\Process::class => [
165                 'constructParams' => [
166                         [Dice::INSTANCE => '$basepath'],
167                 ],
168         ],
169         App\Router::class => [
170                 'constructParams' => [
171                         $_SERVER, null
172                 ],
173                 'call' => [
174                         ['loadRoutes', [include __DIR__ . '/routes.config.php'], Dice::CHAIN_CALL],
175                 ],
176         ],
177         L10n::class => [
178                 'constructParams' => [
179                         $_SERVER, $_GET
180                 ],
181         ],
182 ];