]> git.mxchange.org Git - friendica.git/blob - static/dependencies.config.php
1836a44dd5cccf053dd1aca0ca29f4cdce6efa1f
[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                         ['createConfigFileManager', [
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', [], Dice::CHAIN_CALL],
92                 ],
93         ],
94         App\Mode::class              => [
95                 'call' => [
96                         ['determineRunMode', [true, $_SERVER], Dice::CHAIN_CALL],
97                         ['determine', [
98                                 [Dice::INSTANCE => '$basepath']
99                         ], Dice::CHAIN_CALL],
100                 ],
101         ],
102         Config\Capability\IManageConfigValues::class => [
103                 'instanceOf' => Config\Model\Config::class,
104                 'constructParams' => [
105                         $_SERVER,
106                 ],
107         ],
108         PConfig\Capability\IManagePersonalConfigValues::class => [
109                 'instanceOf' => PConfig\Factory\PConfig::class,
110                 'call'       => [
111                         ['create', [], Dice::CHAIN_CALL],
112                 ]
113         ],
114         DbaDefinition::class => [
115                 'constructParams' => [
116                         [Dice::INSTANCE => '$basepath'],
117                 ],
118                 'call' => [
119                         ['load', [false], Dice::CHAIN_CALL],
120                 ],
121         ],
122         ViewDefinition::class => [
123                 'constructParams' => [
124                         [Dice::INSTANCE => '$basepath'],
125                 ],
126                 'call' => [
127                         ['load', [false], Dice::CHAIN_CALL],
128                 ],
129         ],
130         Database::class                         => [
131                 'constructParams' => [
132                         [Dice::INSTANCE => \Psr\Log\NullLogger::class],
133                 ],
134         ],
135         /**
136          * Creates the App\BaseURL
137          *
138          * Same as:
139          *   $baseURL = new App\BaseURL($configuration, $_SERVER);
140          */
141         App\BaseURL::class             => [
142                 'constructParams' => [
143                         $_SERVER,
144                 ],
145         ],
146         App\Page::class => [
147                 'constructParams' => [
148                         [Dice::INSTANCE => '$basepath'],
149                 ],
150         ],
151         /**
152          * Create a Logger, which implements the LoggerInterface
153          *
154          * Same as:
155          *   $loggerFactory = new Factory\LoggerFactory();
156          *   $logger = $loggerFactory->create($channel, $configuration, $profiler);
157          *
158          * Attention1: We can use DICE for detecting dependencies inside "chained" calls too
159          * Attention2: The variable "$channel" is passed inside the creation of the dependencies per:
160          *    $app = $dice->create(App::class, [], ['$channel' => 'index']);
161          *    and is automatically passed as an argument with the same name
162          */
163         LoggerInterface::class          => [
164                 'instanceOf' => \Friendica\Core\Logger\Factory\Logger::class,
165                 'constructParams' => [
166                         'index',
167                 ],
168                 'call'       => [
169                         ['create', [], Dice::CHAIN_CALL],
170                 ],
171         ],
172         '$devLogger'                    => [
173                 'instanceOf' => \Friendica\Core\Logger\Factory\Logger::class,
174                 'constructParams' => [
175                         'dev',
176                 ],
177                 'call'       => [
178                         ['createDev', [], Dice::CHAIN_CALL],
179                 ]
180         ],
181         \Friendica\Core\Logger\Capabilities\IHaveCallIntrospections::class => [
182                 'instanceOf' => \Friendica\Core\Logger\Util\Introspection::class,
183                 'constructParams' => [
184                         \Friendica\Core\Logger\Util\Introspection::IGNORE_CLASS_LIST,
185                 ],
186         ],
187         Cache\Capability\ICanCache::class => [
188                 'instanceOf' => Cache\Factory\Cache::class,
189                 'call'       => [
190                         ['createLocal', [], Dice::CHAIN_CALL],
191                 ],
192         ],
193         Cache\Capability\ICanCacheInMemory::class => [
194                 'instanceOf' => Cache\Factory\Cache::class,
195                 'call'       => [
196                         ['createLocal', [], Dice::CHAIN_CALL],
197                 ],
198         ],
199         Lock\Capability\ICanLock::class => [
200                 'instanceOf' => Lock\Factory\Lock::class,
201                 'call'       => [
202                         ['create', [], Dice::CHAIN_CALL],
203                 ],
204         ],
205         App\Arguments::class => [
206                 'instanceOf' => App\Arguments::class,
207                 'call' => [
208                         ['determine', [$_SERVER, $_GET], Dice::CHAIN_CALL],
209                 ],
210         ],
211         \Friendica\Core\System::class => [
212                 'constructParams' => [
213                         [Dice::INSTANCE => '$basepath'],
214                 ],
215         ],
216         App\Router::class => [
217                 'constructParams' => [
218                         $_SERVER,
219                         __DIR__ . '/routes.config.php',
220                         [Dice::INSTANCE => Dice::SELF],
221                         null
222                 ],
223         ],
224         L10n::class => [
225                 'constructParams' => [
226                         $_SERVER, $_GET
227                 ],
228         ],
229         IHandleSessions::class => [
230                 'instanceOf' => \Friendica\Core\Session\Factory\Session::class,
231                 'call' => [
232                         ['createSession', [$_SERVER], Dice::CHAIN_CALL],
233                         ['start', [], Dice::CHAIN_CALL],
234                 ],
235         ],
236         IHandleUserSessions::class => [
237                 'instanceOf' => \Friendica\Core\Session\Model\UserSession::class,
238         ],
239         Cookie::class => [
240                 'constructParams' => [
241                         $_COOKIE
242                 ],
243         ],
244         ICanWriteToStorage::class => [
245                 'instanceOf' => StorageManager::class,
246                 'call' => [
247                         ['getBackend', [], Dice::CHAIN_CALL],
248                 ],
249         ],
250         \Friendica\Core\KeyValueStorage\Capabilities\IManageKeyValuePairs::class => [
251                 'instanceOf' => \Friendica\Core\KeyValueStorage\Type\DBKeyValueStorage::class,
252         ],
253         Network\HTTPClient\Capability\ICanSendHttpRequests::class => [
254                 'instanceOf' => Network\HTTPClient\Factory\HttpClient::class,
255                 'call'       => [
256                         ['createClient', [], Dice::CHAIN_CALL],
257                 ],
258         ],
259         Factory\Api\Mastodon\Error::class => [
260                 'constructParams' => [
261                         $_SERVER
262                 ],
263         ],
264         ParsedLogIterator::class => [
265                 'constructParams' => [
266                         [Dice::INSTANCE => Util\ReversedFileReader::class],
267                 ]
268         ],
269         \Friendica\Core\Worker\Repository\Process::class => [
270                 'constructParams' => [
271                         $_SERVER
272                 ],
273         ],
274         App\Request::class => [
275                 'constructParams' => [
276                         $_SERVER
277                 ],
278         ],
279         \Psr\Clock\ClockInterface::class => [
280                 'instanceOf' => Util\Clock\SystemClock::class
281         ],
282         \Friendica\Module\Special\HTTPException::class => [
283                 'constructParams' => [
284                         $_SERVER
285                 ],
286         ],
287 ];