3 * @copyright Copyright (C) 2010-2022, 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\Session\Capability\IHandleSessions;
44 use Friendica\Core\Storage\Repository\StorageManager;
45 use Friendica\Database\Database;
46 use Friendica\Database\Definition\DbaDefinition;
47 use Friendica\Database\Definition\ViewDefinition;
48 use Friendica\Factory;
49 use Friendica\Core\Storage\Capability\ICanWriteToStorage;
50 use Friendica\Model\User\Cookie;
51 use Friendica\Model\Log\ParsedLogIterator;
52 use Friendica\Network;
54 use Psr\Log\LoggerInterface;
58 // marks all class result as shared for other creations, so there's just
59 // one instance for the whole execution
63 'instanceOf' => Util\BasePath::class,
65 ['getPath', [], Dice::CHAIN_CALL],
67 'constructParams' => [
72 Util\BasePath::class => [
73 'constructParams' => [
78 Config\Util\ConfigFileLoader::class => [
79 'instanceOf' => Config\Factory\Config::class,
81 ['createConfigFileLoader', [
82 [Dice::INSTANCE => '$basepath'],
87 Config\ValueObject\Cache::class => [
88 'instanceOf' => Config\Factory\Config::class,
90 ['createCache', [$_SERVER], Dice::CHAIN_CALL],
95 ['determineRunMode', [true, $_SERVER], Dice::CHAIN_CALL],
96 ['determine', [], Dice::CHAIN_CALL],
99 Config\Capability\IManageConfigValues::class => [
100 'instanceOf' => Config\Factory\Config::class,
102 ['create', [], Dice::CHAIN_CALL],
105 PConfig\Capability\IManagePersonalConfigValues::class => [
106 'instanceOf' => PConfig\Factory\PConfig::class,
108 ['create', [], Dice::CHAIN_CALL],
111 DbaDefinition::class => [
112 'constructParams' => [
113 [Dice::INSTANCE => '$basepath'],
116 ['load', [false], Dice::CHAIN_CALL],
119 ViewDefinition::class => [
120 'constructParams' => [
121 [Dice::INSTANCE => '$basepath'],
124 ['load', [false], Dice::CHAIN_CALL],
128 'constructParams' => [
129 [Dice::INSTANCE => \Psr\Log\NullLogger::class],
133 * Creates the App\BaseURL
136 * $baseURL = new App\BaseURL($configuration, $_SERVER);
138 App\BaseURL::class => [
139 'constructParams' => [
144 'constructParams' => [
145 [Dice::INSTANCE => '$basepath'],
149 * Create a Logger, which implements the LoggerInterface
152 * $loggerFactory = new Factory\LoggerFactory();
153 * $logger = $loggerFactory->create($channel, $configuration, $profiler);
155 * Attention1: We can use DICE for detecting dependencies inside "chained" calls too
156 * Attention2: The variable "$channel" is passed inside the creation of the dependencies per:
157 * $app = $dice->create(App::class, [], ['$channel' => 'index']);
158 * and is automatically passed as an argument with the same name
160 LoggerInterface::class => [
161 'instanceOf' => \Friendica\Core\Logger\Factory\Logger::class,
162 'constructParams' => [
166 ['create', [], Dice::CHAIN_CALL],
170 'instanceOf' => \Friendica\Core\Logger\Factory\Logger::class,
171 'constructParams' => [
175 ['createDev', [], Dice::CHAIN_CALL],
178 Cache\Capability\ICanCache::class => [
179 'instanceOf' => Cache\Factory\Cache::class,
181 ['createLocal', [], Dice::CHAIN_CALL],
184 Cache\Capability\ICanCacheInMemory::class => [
185 'instanceOf' => Cache\Factory\Cache::class,
187 ['createLocal', [], Dice::CHAIN_CALL],
190 Lock\Capability\ICanLock::class => [
191 'instanceOf' => Lock\Factory\Lock::class,
193 ['create', [], Dice::CHAIN_CALL],
196 App\Arguments::class => [
197 'instanceOf' => App\Arguments::class,
199 ['determine', [$_SERVER, $_GET], Dice::CHAIN_CALL],
202 \Friendica\Core\System::class => [
203 'constructParams' => [
204 [Dice::INSTANCE => '$basepath'],
207 App\Router::class => [
208 'constructParams' => [
210 __DIR__ . '/routes.config.php',
211 [Dice::INSTANCE => Dice::SELF],
216 'constructParams' => [
220 IHandleSessions::class => [
221 'instanceOf' => \Friendica\Core\Session\Factory\Session::class,
223 ['createSession', [$_SERVER], Dice::CHAIN_CALL],
224 ['start', [], Dice::CHAIN_CALL],
228 'constructParams' => [
232 ICanWriteToStorage::class => [
233 'instanceOf' => StorageManager::class,
235 ['getBackend', [], Dice::CHAIN_CALL],
238 Network\HTTPClient\Capability\ICanSendHttpRequests::class => [
239 'instanceOf' => Network\HTTPClient\Factory\HttpClient::class,
241 ['createClient', [], Dice::CHAIN_CALL],
244 Factory\Api\Mastodon\Error::class => [
245 'constructParams' => [
249 ParsedLogIterator::class => [
250 'constructParams' => [
251 [Dice::INSTANCE => Util\ReversedFileReader::class],
254 \Friendica\Core\Worker\Repository\Process::class => [
255 'constructParams' => [
259 App\Request::class => [
260 'constructParams' => [