]> git.mxchange.org Git - friendica.git/blob - static/dependencies.config.php
Add the possibility to use a different configuration directory
[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                 'shared'          => true,
78                 'constructParams' => [
79                         [Dice::INSTANCE => '$basepath'],
80                         $_SERVER,
81                 ],
82         ],
83         Config\Cache::class          => [
84                 'instanceOf' => Factory\ConfigFactory::class,
85                 'call'       => [
86                         ['createCache', [$_SERVER], Dice::CHAIN_CALL],
87                 ],
88         ],
89         App\Mode::class              => [
90                 'call' => [
91                         ['determineRunMode', [true, $_SERVER], Dice::CHAIN_CALL],
92                         ['determine', [], Dice::CHAIN_CALL],
93                 ],
94         ],
95         Config\IConfig::class                   => [
96                 'instanceOf' => Factory\ConfigFactory::class,
97                 'call'       => [
98                         ['createConfig', [], Dice::CHAIN_CALL],
99                 ],
100         ],
101         \Friendica\Core\PConfig\IPConfig::class => [
102                 'instanceOf' => Factory\ConfigFactory::class,
103                 'call'       => [
104                         ['createPConfig', [], Dice::CHAIN_CALL],
105                 ]
106         ],
107         Database::class                         => [
108                 'constructParams' => [
109                         [Dice::INSTANCE => \Psr\Log\NullLogger::class],
110                 ],
111         ],
112         /**
113          * Creates the App\BaseURL
114          *
115          * Same as:
116          *   $baseURL = new App\BaseURL($configuration, $_SERVER);
117          */
118         App\BaseURL::class             => [
119                 'constructParams' => [
120                         $_SERVER,
121                 ],
122         ],
123         App\Page::class => [
124                 'constructParams' => [
125                         [Dice::INSTANCE => '$basepath'],
126                 ],
127         ],
128         /**
129          * Create a Logger, which implements the LoggerInterface
130          *
131          * Same as:
132          *   $loggerFactory = new Factory\LoggerFactory();
133          *   $logger = $loggerFactory->create($channel, $configuration, $profiler);
134          *
135          * Attention1: We can use DICE for detecting dependencies inside "chained" calls too
136          * Attention2: The variable "$channel" is passed inside the creation of the dependencies per:
137          *    $app = $dice->create(App::class, [], ['$channel' => 'index']);
138          *    and is automatically passed as an argument with the same name
139          */
140         LoggerInterface::class          => [
141                 'instanceOf' => Factory\LoggerFactory::class,
142                 'constructParams' => [
143                         'index',
144                 ],
145                 'call'       => [
146                         ['create', ['index'], Dice::CHAIN_CALL],
147                 ],
148         ],
149         '$devLogger'                    => [
150                 'instanceOf' => Factory\LoggerFactory::class,
151                 'constructParams' => [
152                         'dev',
153                 ],
154                 'call'       => [
155                         ['createDev', [], Dice::CHAIN_CALL],
156                 ]
157         ],
158         Cache\ICache::class             => [
159                 'instanceOf' => Factory\CacheFactory::class,
160                 'call'       => [
161                         ['create', [], Dice::CHAIN_CALL],
162                 ],
163         ],
164         Cache\IMemoryCache::class       => [
165                 'instanceOf' => Factory\CacheFactory::class,
166                 'call'       => [
167                         ['create', [], Dice::CHAIN_CALL],
168                 ],
169         ],
170         ILock::class                    => [
171                 'instanceOf' => Factory\LockFactory::class,
172                 'call'       => [
173                         ['create', [], Dice::CHAIN_CALL],
174                 ],
175         ],
176         App\Arguments::class => [
177                 'instanceOf' => App\Arguments::class,
178                 'call' => [
179                         ['determine', [$_SERVER, $_GET], Dice::CHAIN_CALL],
180                 ],
181         ],
182         App\Module::class => [
183                 'instanceOf' => App\Module::class,
184                 'call' => [
185                         ['determineModule', [], Dice::CHAIN_CALL],
186                 ],
187         ],
188         Process::class => [
189                 'constructParams' => [
190                         [Dice::INSTANCE => '$basepath'],
191                         getmypid(),
192                 ],
193         ],
194         App\Router::class => [
195                 'constructParams' => [
196                         $_SERVER,
197                         __DIR__ . '/routes.config.php',
198                         null
199                 ],
200         ],
201         L10n::class => [
202                 'constructParams' => [
203                         $_SERVER, $_GET
204                 ],
205         ],
206         ISession::class => [
207                 'instanceOf' => Factory\SessionFactory::class,
208                 'call' => [
209                         ['createSession', [$_SERVER], Dice::CHAIN_CALL],
210                         ['start', [], Dice::CHAIN_CALL],
211                 ],
212         ],
213         Cookie::class => [
214                 'constructParams' => [
215                         $_SERVER, $_COOKIE
216                 ],
217         ],
218         IWritableStorage::class => [
219                 'instanceOf' => StorageManager::class,
220                 'call' => [
221                         ['getBackend', [], Dice::CHAIN_CALL],
222                 ],
223         ],
224         Network\IHTTPClient::class => [
225                 'instanceOf' => Factory\HTTPClientFactory::class,
226                 'call'       => [
227                         ['createClient', [], Dice::CHAIN_CALL],
228                 ],
229         ],
230         Factory\Api\Mastodon\Error::class => [
231                 'constructParams' => [
232                         $_SERVER
233                 ],
234         ],
235         ParsedLogIterator::class => [
236                 'constructParams' => [
237                         [Dice::INSTANCE => Util\ReversedFileReader::class],
238                 ]
239         ],
240 ];