3 * @copyright Copyright (C) 2010-2021, the Friendica project
5 * @license GNU AGPL version 3 or any later version
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.
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.
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/>.
20 * The configuration defines "complex" dependencies inside Friendica
21 * So this classes shouldn't be simple or their dependencies are already defined here.
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);
28 * This kind of dependencies SHOULD be defined here:
29 * - $a = new ClassA();
32 * - $a = new ClassA($creationPassedVariable);
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\Storage\Repository\StorageManager;
46 use Friendica\Database\Database;
47 use Friendica\Factory;
48 use Friendica\Core\Storage\Capability\ICanWriteToStorage;
49 use Friendica\Model\User\Cookie;
50 use Friendica\Model\Log\ParsedLogIterator;
51 use Friendica\Network;
53 use Psr\Log\LoggerInterface;
57 // marks all class result as shared for other creations, so there's just
58 // one instance for the whole execution
62 'instanceOf' => Util\BasePath::class,
64 ['getPath', [], Dice::CHAIN_CALL],
66 'constructParams' => [
71 Util\BasePath::class => [
72 'constructParams' => [
77 Config\Util\ConfigFileLoader::class => [
78 'instanceOf' => Config\Factory\Config::class,
80 ['createConfigFileLoader', [
81 [Dice::INSTANCE => '$basepath'],
86 Config\ValueObject\Cache::class => [
87 'instanceOf' => Config\Factory\Config::class,
89 ['createCache', [$_SERVER], Dice::CHAIN_CALL],
94 ['determineRunMode', [true, $_SERVER], Dice::CHAIN_CALL],
95 ['determine', [], Dice::CHAIN_CALL],
98 Config\Capability\IManageConfigValues::class => [
99 'instanceOf' => Config\Factory\Config::class,
101 ['create', [], Dice::CHAIN_CALL],
104 PConfig\Capability\IManagePersonalConfigValues::class => [
105 'instanceOf' => PConfig\Factory\PConfig::class,
107 ['create', [], Dice::CHAIN_CALL],
111 'constructParams' => [
112 [Dice::INSTANCE => \Psr\Log\NullLogger::class],
116 * Creates the App\BaseURL
119 * $baseURL = new App\BaseURL($configuration, $_SERVER);
121 App\BaseURL::class => [
122 'constructParams' => [
127 'constructParams' => [
128 [Dice::INSTANCE => '$basepath'],
132 * Create a Logger, which implements the LoggerInterface
135 * $loggerFactory = new Factory\LoggerFactory();
136 * $logger = $loggerFactory->create($channel, $configuration, $profiler);
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
143 LoggerInterface::class => [
144 'instanceOf' => \Friendica\Core\Logger\Factory\Logger::class,
145 'constructParams' => [
149 ['create', [], Dice::CHAIN_CALL],
153 'instanceOf' => \Friendica\Core\Logger\Factory\Logger::class,
154 'constructParams' => [
158 ['createDev', [], Dice::CHAIN_CALL],
161 Cache\Capability\ICanCache::class => [
162 'instanceOf' => Cache\Factory\Cache::class,
164 ['create', [], Dice::CHAIN_CALL],
167 Cache\Capability\ICanCacheInMemory::class => [
168 'instanceOf' => Cache\Factory\Cache::class,
170 ['create', [], Dice::CHAIN_CALL],
173 Lock\Capability\ICanLock::class => [
174 'instanceOf' => Lock\Factory\Lock::class,
176 ['create', [], Dice::CHAIN_CALL],
179 App\Arguments::class => [
180 'instanceOf' => App\Arguments::class,
182 ['determine', [$_SERVER, $_GET], Dice::CHAIN_CALL],
185 App\Module::class => [
186 'instanceOf' => App\Module::class,
188 ['determineModule', [], Dice::CHAIN_CALL],
191 \Friendica\Core\System::class => [
192 'constructParams' => [
193 [Dice::INSTANCE => '$basepath'],
196 App\Router::class => [
197 'constructParams' => [
199 __DIR__ . '/routes.config.php',
204 'constructParams' => [
208 IHandleSessions::class => [
209 'instanceOf' => \Friendica\Core\Session\Factory\Session::class,
211 ['createSession', [$_SERVER], Dice::CHAIN_CALL],
212 ['start', [], Dice::CHAIN_CALL],
216 'constructParams' => [
220 ICanWriteToStorage::class => [
221 'instanceOf' => StorageManager::class,
223 ['getBackend', [], Dice::CHAIN_CALL],
226 Network\HTTPClient\Capability\ICanSendHttpRequests::class => [
227 'instanceOf' => Network\HTTPClient\Factory\HttpClient::class,
229 ['createClient', [], Dice::CHAIN_CALL],
232 Factory\Api\Mastodon\Error::class => [
233 'constructParams' => [
237 ParsedLogIterator::class => [
238 'constructParams' => [
239 [Dice::INSTANCE => Util\ReversedFileReader::class],