]> git.mxchange.org Git - friendica.git/blob - static/dependencies.config.php
Merge pull request #11363 from annando/api-route
[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\Factory;
47 use Friendica\Core\Storage\Capability\ICanWriteToStorage;
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         Config\Util\ConfigFileLoader::class => [
77                 'instanceOf' => Config\Factory\Config::class,
78                 'call'       => [
79                         ['createConfigFileLoader', [
80                                 [Dice::INSTANCE => '$basepath'],
81                                 $_SERVER,
82                         ], Dice::CHAIN_CALL],
83                 ],
84         ],
85         Config\ValueObject\Cache::class => [
86                 'instanceOf' => Config\Factory\Config::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\Capability\IManageConfigValues::class => [
98                 'instanceOf' => Config\Factory\Config::class,
99                 'call'       => [
100                         ['create', [], Dice::CHAIN_CALL],
101                 ],
102         ],
103         PConfig\Capability\IManagePersonalConfigValues::class => [
104                 'instanceOf' => PConfig\Factory\PConfig::class,
105                 'call'       => [
106                         ['create', [], 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' => \Friendica\Core\Logger\Factory\Logger::class,
144                 'constructParams' => [
145                         'index',
146                 ],
147                 'call'       => [
148                         ['create', [], Dice::CHAIN_CALL],
149                 ],
150         ],
151         '$devLogger'                    => [
152                 'instanceOf' => \Friendica\Core\Logger\Factory\Logger::class,
153                 'constructParams' => [
154                         'dev',
155                 ],
156                 'call'       => [
157                         ['createDev', [], Dice::CHAIN_CALL],
158                 ]
159         ],
160         Cache\Capability\ICanCache::class => [
161                 'instanceOf' => Cache\Factory\Cache::class,
162                 'call'       => [
163                         ['createLocal', [], Dice::CHAIN_CALL],
164                 ],
165         ],
166         Cache\Capability\ICanCacheInMemory::class => [
167                 'instanceOf' => Cache\Factory\Cache::class,
168                 'call'       => [
169                         ['createLocal', [], Dice::CHAIN_CALL],
170                 ],
171         ],
172         Lock\Capability\ICanLock::class => [
173                 'instanceOf' => Lock\Factory\Lock::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         \Friendica\Core\System::class => [
185                 'constructParams' => [
186                         [Dice::INSTANCE => '$basepath'],
187                 ],
188         ],
189         App\Router::class => [
190                 'constructParams' => [
191                         $_SERVER,
192                         __DIR__ . '/routes.config.php',
193                         [Dice::INSTANCE => Dice::SELF],
194                         null
195                 ],
196         ],
197         L10n::class => [
198                 'constructParams' => [
199                         $_SERVER, $_GET
200                 ],
201         ],
202         IHandleSessions::class => [
203                 'instanceOf' => \Friendica\Core\Session\Factory\Session::class,
204                 'call' => [
205                         ['createSession', [$_SERVER], Dice::CHAIN_CALL],
206                         ['start', [], Dice::CHAIN_CALL],
207                 ],
208         ],
209         Cookie::class => [
210                 'constructParams' => [
211                         $_SERVER, $_COOKIE
212                 ],
213         ],
214         ICanWriteToStorage::class => [
215                 'instanceOf' => StorageManager::class,
216                 'call' => [
217                         ['getBackend', [], Dice::CHAIN_CALL],
218                 ],
219         ],
220         Network\HTTPClient\Capability\ICanSendHttpRequests::class => [
221                 'instanceOf' => Network\HTTPClient\Factory\HttpClient::class,
222                 'call'       => [
223                         ['createClient', [], Dice::CHAIN_CALL],
224                 ],
225         ],
226         Factory\Api\Mastodon\Error::class => [
227                 'constructParams' => [
228                         $_SERVER
229                 ],
230         ],
231         ParsedLogIterator::class => [
232                 'constructParams' => [
233                         [Dice::INSTANCE => Util\ReversedFileReader::class],
234                 ]
235         ],
236         \Friendica\Core\Worker\Repository\Process::class => [
237                 'constructParams' => [
238                         $_SERVER
239                 ],
240         ],
241 ];