]> git.mxchange.org Git - friendica.git/blob - static/dependencies.config.php
90f01feede02ecfdc68cc29b85a3c47a69299863
[friendica.git] / static / dependencies.config.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2023, the Friendica project
4  *
5  * @license GNU AGPL version 3 or any later version
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Affero General Public License as
9  * published by the Free Software Foundation, either version 3 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU Affero General Public License for more details.
16  *
17  * You should have received a copy of the GNU Affero General Public License
18  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
19  *
20  * The configuration defines "complex" dependencies inside Friendica
21  * So this classes shouldn't be simple or their dependencies are already defined here.
22  *
23  * This kind of dependencies are NOT required to be defined here:
24  *   - $a = new ClassA(new ClassB());
25  *   - $a = new ClassA();
26  *   - $a = new ClassA(Configuration $configuration);
27  *
28  * This kind of dependencies SHOULD be defined here:
29  *   - $a = new ClassA();
30  *     $b = $a->create();
31  *
32  *   - $a = new ClassA($creationPassedVariable);
33  *
34  */
35
36 use Dice\Dice;
37 use Friendica\App;
38 use Friendica\Core\Cache;
39 use Friendica\Core\Config;
40 use Friendica\Core\PConfig;
41 use Friendica\Core\L10n;
42 use Friendica\Core\Lock;
43 use Friendica\Core\Session\Capability\IHandleSessions;
44 use Friendica\Core\Session\Capability\IHandleUserSessions;
45 use Friendica\Core\Storage\Repository\StorageManager;
46 use Friendica\Database\Database;
47 use Friendica\Database\Definition\DbaDefinition;
48 use Friendica\Database\Definition\ViewDefinition;
49 use Friendica\Factory;
50 use Friendica\Core\Storage\Capability\ICanWriteToStorage;
51 use Friendica\Model\User\Cookie;
52 use Friendica\Model\Log\ParsedLogIterator;
53 use Friendica\Network;
54 use Friendica\Util;
55 use Psr\Log\LoggerInterface;
56
57 return [
58         '*'                             => [
59                 // marks all class result as shared for other creations, so there's just
60                 // one instance for the whole execution
61                 'shared' => true,
62         ],
63         '$basepath'                     => [
64                 'instanceOf'      => Util\BasePath::class,
65                 'call'            => [
66                         ['getPath', [], Dice::CHAIN_CALL],
67                 ],
68                 'constructParams' => [
69                         dirname(__FILE__, 2),
70                         $_SERVER
71                 ]
72         ],
73         Util\BasePath::class         => [
74                 'constructParams' => [
75                         dirname(__FILE__, 2),
76                         $_SERVER
77                 ]
78         ],
79         Config\Util\ConfigFileManager::class => [
80                 'instanceOf' => Config\Factory\Config::class,
81                 'call'       => [
82                         ['createConfigFileLoader', [
83                                 [Dice::INSTANCE => '$basepath'],
84                                 $_SERVER,
85                         ], Dice::CHAIN_CALL],
86                 ],
87         ],
88         Config\ValueObject\Cache::class => [
89                 'instanceOf' => Config\Factory\Config::class,
90                 'call'       => [
91                         ['createCache', [$_SERVER], Dice::CHAIN_CALL],
92                 ],
93         ],
94         App\Mode::class              => [
95                 'call' => [
96                         ['determineRunMode', [true, $_SERVER], Dice::CHAIN_CALL],
97                         ['determine', [], Dice::CHAIN_CALL],
98                 ],
99         ],
100         Config\Capability\IManageConfigValues::class => [
101                 'instanceOf' => Config\Model\Config::class,
102         ],
103         PConfig\Capability\IManagePersonalConfigValues::class => [
104                 'instanceOf' => PConfig\Factory\PConfig::class,
105                 'call'       => [
106                         ['create', [], Dice::CHAIN_CALL],
107                 ]
108         ],
109         DbaDefinition::class => [
110                 'constructParams' => [
111                         [Dice::INSTANCE => '$basepath'],
112                 ],
113                 'call' => [
114                         ['load', [false], Dice::CHAIN_CALL],
115                 ],
116         ],
117         ViewDefinition::class => [
118                 'constructParams' => [
119                         [Dice::INSTANCE => '$basepath'],
120                 ],
121                 'call' => [
122                         ['load', [false], Dice::CHAIN_CALL],
123                 ],
124         ],
125         Database::class                         => [
126                 'constructParams' => [
127                         [Dice::INSTANCE => \Psr\Log\NullLogger::class],
128                 ],
129         ],
130         /**
131          * Creates the App\BaseURL
132          *
133          * Same as:
134          *   $baseURL = new App\BaseURL($configuration, $_SERVER);
135          */
136         App\BaseURL::class             => [
137                 'constructParams' => [
138                         $_SERVER,
139                 ],
140         ],
141         App\Page::class => [
142                 'constructParams' => [
143                         [Dice::INSTANCE => '$basepath'],
144                 ],
145         ],
146         /**
147          * Create a Logger, which implements the LoggerInterface
148          *
149          * Same as:
150          *   $loggerFactory = new Factory\LoggerFactory();
151          *   $logger = $loggerFactory->create($channel, $configuration, $profiler);
152          *
153          * Attention1: We can use DICE for detecting dependencies inside "chained" calls too
154          * Attention2: The variable "$channel" is passed inside the creation of the dependencies per:
155          *    $app = $dice->create(App::class, [], ['$channel' => 'index']);
156          *    and is automatically passed as an argument with the same name
157          */
158         LoggerInterface::class          => [
159                 'instanceOf' => \Friendica\Core\Logger\Factory\Logger::class,
160                 'constructParams' => [
161                         'index',
162                 ],
163                 'call'       => [
164                         ['create', [], Dice::CHAIN_CALL],
165                 ],
166         ],
167         '$devLogger'                    => [
168                 'instanceOf' => \Friendica\Core\Logger\Factory\Logger::class,
169                 'constructParams' => [
170                         'dev',
171                 ],
172                 'call'       => [
173                         ['createDev', [], Dice::CHAIN_CALL],
174                 ]
175         ],
176         \Friendica\Core\Logger\Capabilities\IHaveCallIntrospections::class => [
177                 'instanceOf' => \Friendica\Core\Logger\Util\Introspection::class,
178                 'constructParams' => [
179                         \Friendica\Core\Logger\Util\Introspection::IGNORE_CLASS_LIST,
180                 ],
181         ],
182         Cache\Capability\ICanCache::class => [
183                 'instanceOf' => Cache\Factory\Cache::class,
184                 'call'       => [
185                         ['createLocal', [], Dice::CHAIN_CALL],
186                 ],
187         ],
188         Cache\Capability\ICanCacheInMemory::class => [
189                 'instanceOf' => Cache\Factory\Cache::class,
190                 'call'       => [
191                         ['createLocal', [], Dice::CHAIN_CALL],
192                 ],
193         ],
194         Lock\Capability\ICanLock::class => [
195                 'instanceOf' => Lock\Factory\Lock::class,
196                 'call'       => [
197                         ['create', [], Dice::CHAIN_CALL],
198                 ],
199         ],
200         App\Arguments::class => [
201                 'instanceOf' => App\Arguments::class,
202                 'call' => [
203                         ['determine', [$_SERVER, $_GET], Dice::CHAIN_CALL],
204                 ],
205         ],
206         \Friendica\Core\System::class => [
207                 'constructParams' => [
208                         [Dice::INSTANCE => '$basepath'],
209                 ],
210         ],
211         App\Router::class => [
212                 'constructParams' => [
213                         $_SERVER,
214                         __DIR__ . '/routes.config.php',
215                         [Dice::INSTANCE => Dice::SELF],
216                         null
217                 ],
218         ],
219         L10n::class => [
220                 'constructParams' => [
221                         $_SERVER, $_GET
222                 ],
223         ],
224         IHandleSessions::class => [
225                 'instanceOf' => \Friendica\Core\Session\Factory\Session::class,
226                 'call' => [
227                         ['createSession', [$_SERVER], Dice::CHAIN_CALL],
228                         ['start', [], Dice::CHAIN_CALL],
229                 ],
230         ],
231         IHandleUserSessions::class => [
232                 'instanceOf' => \Friendica\Core\Session\Model\UserSession::class,
233         ],
234         Cookie::class => [
235                 'constructParams' => [
236                         $_COOKIE
237                 ],
238         ],
239         ICanWriteToStorage::class => [
240                 'instanceOf' => StorageManager::class,
241                 'call' => [
242                         ['getBackend', [], Dice::CHAIN_CALL],
243                 ],
244         ],
245         \Friendica\Core\KeyValueStorage\Capabilities\IManageKeyValuePairs::class => [
246                 'instanceOf' => \Friendica\Core\KeyValueStorage\Type\DBKeyValueStorage::class,
247         ],
248         Network\HTTPClient\Capability\ICanSendHttpRequests::class => [
249                 'instanceOf' => Network\HTTPClient\Factory\HttpClient::class,
250                 'call'       => [
251                         ['createClient', [], Dice::CHAIN_CALL],
252                 ],
253         ],
254         Factory\Api\Mastodon\Error::class => [
255                 'constructParams' => [
256                         $_SERVER
257                 ],
258         ],
259         ParsedLogIterator::class => [
260                 'constructParams' => [
261                         [Dice::INSTANCE => Util\ReversedFileReader::class],
262                 ]
263         ],
264         \Friendica\Core\Worker\Repository\Process::class => [
265                 'constructParams' => [
266                         $_SERVER
267                 ],
268         ],
269         App\Request::class => [
270                 'constructParams' => [
271                         $_SERVER
272                 ],
273         ],
274         \Psr\Clock\ClockInterface::class => [
275                 'instanceOf' => Util\Clock\SystemClock::class
276         ],
277         \Friendica\Module\Special\HTTPException::class => [
278                 'constructParams' => [
279                         $_SERVER
280                 ],
281         ],
282 ];