]> git.mxchange.org Git - friendica.git/blob - static/dependencies.config.php
spelling: preview
[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\Hooks\Capabilities\ICanManageInstances;
41 use Friendica\Core\Hooks\Model\InstanceManager;
42 use Friendica\Core\PConfig;
43 use Friendica\Core\L10n;
44 use Friendica\Core\Lock;
45 use Friendica\Core\Session\Capability\IHandleSessions;
46 use Friendica\Core\Session\Capability\IHandleUserSessions;
47 use Friendica\Core\Storage\Repository\StorageManager;
48 use Friendica\Database\Database;
49 use Friendica\Database\Definition\DbaDefinition;
50 use Friendica\Database\Definition\ViewDefinition;
51 use Friendica\Factory;
52 use Friendica\Core\Storage\Capability\ICanWriteToStorage;
53 use Friendica\Model\User\Cookie;
54 use Friendica\Model\Log\ParsedLogIterator;
55 use Friendica\Network;
56 use Friendica\Util;
57 use Psr\Log\LoggerInterface;
58
59 return [
60         '*'                             => [
61                 // marks all class result as shared for other creations, so there's just
62                 // one instance for the whole execution
63                 'shared' => true,
64         ],
65         '$basepath'                     => [
66                 'instanceOf'      => Util\BasePath::class,
67                 'call'            => [
68                         ['getPath', [], Dice::CHAIN_CALL],
69                 ],
70                 'constructParams' => [
71                         dirname(__FILE__, 2),
72                         $_SERVER
73                 ]
74         ],
75         Util\BasePath::class         => [
76                 'constructParams' => [
77                         dirname(__FILE__, 2),
78                         $_SERVER
79                 ]
80         ],
81         ICanManageInstances::class => [
82                 'instanceOf' => InstanceManager::class,
83                 'constructParams' => [
84                         [Dice::INSTANCE => Dice::SELF],
85                 ],
86         ],
87         Config\Util\ConfigFileManager::class => [
88                 'instanceOf' => Config\Factory\Config::class,
89                 'call'       => [
90                         ['createConfigFileManager', [
91                                 [Dice::INSTANCE => '$basepath'],
92                                 $_SERVER,
93                         ], Dice::CHAIN_CALL],
94                 ],
95         ],
96         Config\ValueObject\Cache::class => [
97                 'instanceOf' => Config\Factory\Config::class,
98                 'call'       => [
99                         ['createCache', [], Dice::CHAIN_CALL],
100                 ],
101         ],
102         App\Mode::class              => [
103                 'call' => [
104                         ['determineRunMode', [true, $_SERVER], Dice::CHAIN_CALL],
105                         ['determine', [
106                                 [Dice::INSTANCE => '$basepath']
107                         ], Dice::CHAIN_CALL],
108                 ],
109         ],
110         Config\Capability\IManageConfigValues::class => [
111                 'instanceOf' => Config\Model\DatabaseConfig::class,
112                 'constructParams' => [
113                         $_SERVER,
114                 ],
115         ],
116         PConfig\Capability\IManagePersonalConfigValues::class => [
117                 'instanceOf' => PConfig\Factory\PConfig::class,
118                 'call'       => [
119                         ['create', [], Dice::CHAIN_CALL],
120                 ]
121         ],
122         DbaDefinition::class => [
123                 'constructParams' => [
124                         [Dice::INSTANCE => '$basepath'],
125                 ],
126                 'call' => [
127                         ['load', [false], Dice::CHAIN_CALL],
128                 ],
129         ],
130         ViewDefinition::class => [
131                 'constructParams' => [
132                         [Dice::INSTANCE => '$basepath'],
133                 ],
134                 'call' => [
135                         ['load', [false], Dice::CHAIN_CALL],
136                 ],
137         ],
138         Database::class                         => [
139                 'constructParams' => [
140                         [Dice::INSTANCE => Config\Model\ReadOnlyFileConfig::class],
141                 ],
142         ],
143         /**
144          * Creates the App\BaseURL
145          *
146          * Same as:
147          *   $baseURL = new App\BaseURL($configuration, $_SERVER);
148          */
149         App\BaseURL::class             => [
150                 'constructParams' => [
151                         $_SERVER,
152                 ],
153         ],
154         App\Page::class => [
155                 'constructParams' => [
156                         [Dice::INSTANCE => '$basepath'],
157                 ],
158         ],
159         /**
160          * Create a Logger, which implements the LoggerInterface
161          *
162          * Same as:
163          *   $loggerFactory = new Factory\LoggerFactory();
164          *   $logger = $loggerFactory->create($channel, $configuration, $profiler);
165          *
166          * Attention1: We can use DICE for detecting dependencies inside "chained" calls too
167          * Attention2: The variable "$channel" is passed inside the creation of the dependencies per:
168          *    $app = $dice->create(App::class, [], ['$channel' => 'index']);
169          *    and is automatically passed as an argument with the same name
170          */
171         LoggerInterface::class          => [
172                 'instanceOf' => \Friendica\Core\Logger\Factory\Logger::class,
173                 'constructParams' => [
174                         'index',
175                 ],
176                 'call'       => [
177                         ['create', [], Dice::CHAIN_CALL],
178                 ],
179         ],
180         '$devLogger'                    => [
181                 'instanceOf' => \Friendica\Core\Logger\Factory\Logger::class,
182                 'constructParams' => [
183                         'dev',
184                 ],
185                 'call'       => [
186                         ['createDev', [], Dice::CHAIN_CALL],
187                 ]
188         ],
189         \Friendica\Core\Logger\Capabilities\IHaveCallIntrospections::class => [
190                 'instanceOf' => \Friendica\Core\Logger\Util\Introspection::class,
191                 'constructParams' => [
192                         \Friendica\Core\Logger\Util\Introspection::IGNORE_CLASS_LIST,
193                 ],
194         ],
195         Cache\Capability\ICanCache::class => [
196                 'instanceOf' => Cache\Factory\Cache::class,
197                 'call'       => [
198                         ['createLocal', [], Dice::CHAIN_CALL],
199                 ],
200         ],
201         Cache\Capability\ICanCacheInMemory::class => [
202                 'instanceOf' => Cache\Factory\Cache::class,
203                 'call'       => [
204                         ['createLocal', [], Dice::CHAIN_CALL],
205                 ],
206         ],
207         Lock\Capability\ICanLock::class => [
208                 'instanceOf' => Lock\Factory\Lock::class,
209                 'call'       => [
210                         ['create', [], Dice::CHAIN_CALL],
211                 ],
212         ],
213         App\Arguments::class => [
214                 'instanceOf' => App\Arguments::class,
215                 'call' => [
216                         ['determine', [$_SERVER, $_GET], Dice::CHAIN_CALL],
217                 ],
218         ],
219         \Friendica\Core\System::class => [
220                 'constructParams' => [
221                         [Dice::INSTANCE => '$basepath'],
222                 ],
223         ],
224         App\Router::class => [
225                 'constructParams' => [
226                         $_SERVER,
227                         __DIR__ . '/routes.config.php',
228                         [Dice::INSTANCE => Dice::SELF],
229                         null
230                 ],
231         ],
232         L10n::class => [
233                 'constructParams' => [
234                         $_SERVER, $_GET
235                 ],
236         ],
237         IHandleSessions::class => [
238                 'instanceOf' => \Friendica\Core\Session\Factory\Session::class,
239                 'call' => [
240                         ['create', [$_SERVER], Dice::CHAIN_CALL],
241                         ['start', [], Dice::CHAIN_CALL],
242                 ],
243         ],
244         IHandleUserSessions::class => [
245                 'instanceOf' => \Friendica\Core\Session\Model\UserSession::class,
246         ],
247         Cookie::class => [
248                 'constructParams' => [
249                         $_COOKIE
250                 ],
251         ],
252         ICanWriteToStorage::class => [
253                 'instanceOf' => StorageManager::class,
254                 'call' => [
255                         ['getBackend', [], Dice::CHAIN_CALL],
256                 ],
257         ],
258         \Friendica\Core\KeyValueStorage\Capabilities\IManageKeyValuePairs::class => [
259                 'instanceOf' => \Friendica\Core\KeyValueStorage\Type\DBKeyValueStorage::class,
260         ],
261         Network\HTTPClient\Capability\ICanSendHttpRequests::class => [
262                 'instanceOf' => Network\HTTPClient\Factory\HttpClient::class,
263                 'call'       => [
264                         ['createClient', [], Dice::CHAIN_CALL],
265                 ],
266         ],
267         Factory\Api\Mastodon\Error::class => [
268                 'constructParams' => [
269                         $_SERVER
270                 ],
271         ],
272         ParsedLogIterator::class => [
273                 'constructParams' => [
274                         [Dice::INSTANCE => Util\ReversedFileReader::class],
275                 ]
276         ],
277         \Friendica\Core\Worker\Repository\Process::class => [
278                 'constructParams' => [
279                         $_SERVER
280                 ],
281         ],
282         App\Request::class => [
283                 'constructParams' => [
284                         $_SERVER
285                 ],
286         ],
287         \Psr\Clock\ClockInterface::class => [
288                 'instanceOf' => Util\Clock\SystemClock::class
289         ],
290         \Friendica\Module\Special\HTTPException::class => [
291                 'constructParams' => [
292                         $_SERVER
293                 ],
294         ],
295 ];