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