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