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