3 * @copyright Copyright (C) 2010-2023, 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\Hooks\Capabilities\ICanManageInstances;
41 use Friendica\Core\Hooks\Model\InstanceManager;
42 use Friendica\Core\PConfig;
43 use Friendica\Core\L10n;
44 use Friendica\Core\Lock;
45 use Friendica\Core\Session\Capability\IHandleSessions;
46 use Friendica\Core\Session\Capability\IHandleUserSessions;
47 use Friendica\Core\Storage\Repository\StorageManager;
48 use Friendica\Database\Database;
49 use Friendica\Database\Definition\DbaDefinition;
50 use Friendica\Database\Definition\ViewDefinition;
51 use Friendica\Factory;
52 use Friendica\Core\Storage\Capability\ICanWriteToStorage;
53 use Friendica\Model\User\Cookie;
54 use Friendica\Model\Log\ParsedLogIterator;
55 use Friendica\Network;
57 use Psr\Log\LoggerInterface;
61 // marks all class result as shared for other creations, so there's just
62 // one instance for the whole execution
66 'instanceOf' => Util\BasePath::class,
68 ['getPath', [], Dice::CHAIN_CALL],
70 'constructParams' => [
75 Util\BasePath::class => [
76 'constructParams' => [
81 ICanManageInstances::class => [
82 'instanceOf' => InstanceManager::class,
83 'constructParams' => [
84 [Dice::INSTANCE => Dice::SELF],
87 Config\Util\ConfigFileManager::class => [
88 'instanceOf' => Config\Factory\Config::class,
90 ['createConfigFileManager', [
91 [Dice::INSTANCE => '$basepath'],
96 Config\ValueObject\Cache::class => [
97 'instanceOf' => Config\Factory\Config::class,
99 ['createCache', [], Dice::CHAIN_CALL],
104 ['determineRunMode', [true, $_SERVER], Dice::CHAIN_CALL],
106 [Dice::INSTANCE => '$basepath']
107 ], Dice::CHAIN_CALL],
110 Config\Capability\IManageConfigValues::class => [
111 'instanceOf' => Config\Model\DatabaseConfig::class,
112 'constructParams' => [
116 PConfig\Capability\IManagePersonalConfigValues::class => [
117 'instanceOf' => PConfig\Factory\PConfig::class,
119 ['create', [], Dice::CHAIN_CALL],
122 DbaDefinition::class => [
123 'constructParams' => [
124 [Dice::INSTANCE => '$basepath'],
127 ['load', [false], Dice::CHAIN_CALL],
130 ViewDefinition::class => [
131 'constructParams' => [
132 [Dice::INSTANCE => '$basepath'],
135 ['load', [false], Dice::CHAIN_CALL],
139 'constructParams' => [
140 [Dice::INSTANCE => Config\Model\ReadOnlyFileConfig::class],
144 * Creates the App\BaseURL
147 * $baseURL = new App\BaseURL($configuration, $_SERVER);
149 App\BaseURL::class => [
150 'constructParams' => [
155 'constructParams' => [
156 [Dice::INSTANCE => '$basepath'],
160 * Create a Logger, which implements the LoggerInterface
163 * $loggerFactory = new Factory\LoggerFactory();
164 * $logger = $loggerFactory->create($channel, $configuration, $profiler);
166 * Attention1: We can use DICE for detecting dependencies inside "chained" calls too
167 * Attention2: The variable "$channel" is passed inside the creation of the dependencies per:
168 * $app = $dice->create(App::class, [], ['$channel' => 'index']);
169 * and is automatically passed as an argument with the same name
171 LoggerInterface::class => [
172 'instanceOf' => \Friendica\Core\Logger\Factory\Logger::class,
173 'constructParams' => [
177 ['create', [], Dice::CHAIN_CALL],
181 'instanceOf' => \Friendica\Core\Logger\Factory\Logger::class,
182 'constructParams' => [
186 ['createDev', [], Dice::CHAIN_CALL],
189 \Friendica\Core\Logger\Capabilities\IHaveCallIntrospections::class => [
190 'instanceOf' => \Friendica\Core\Logger\Util\Introspection::class,
191 'constructParams' => [
192 \Friendica\Core\Logger\Util\Introspection::IGNORE_CLASS_LIST,
195 Cache\Capability\ICanCache::class => [
196 'instanceOf' => Cache\Factory\Cache::class,
198 ['createLocal', [], Dice::CHAIN_CALL],
201 Cache\Capability\ICanCacheInMemory::class => [
202 'instanceOf' => Cache\Factory\Cache::class,
204 ['createLocal', [], Dice::CHAIN_CALL],
207 Lock\Capability\ICanLock::class => [
208 'instanceOf' => Lock\Factory\Lock::class,
210 ['create', [], Dice::CHAIN_CALL],
213 App\Arguments::class => [
214 'instanceOf' => App\Arguments::class,
216 ['determine', [$_SERVER, $_GET], Dice::CHAIN_CALL],
219 \Friendica\Core\System::class => [
220 'constructParams' => [
221 [Dice::INSTANCE => '$basepath'],
224 App\Router::class => [
225 'constructParams' => [
227 __DIR__ . '/routes.config.php',
228 [Dice::INSTANCE => Dice::SELF],
233 'constructParams' => [
237 IHandleSessions::class => [
238 'instanceOf' => \Friendica\Core\Session\Factory\Session::class,
240 ['create', [$_SERVER], Dice::CHAIN_CALL],
241 ['start', [], Dice::CHAIN_CALL],
244 IHandleUserSessions::class => [
245 'instanceOf' => \Friendica\Core\Session\Model\UserSession::class,
248 'constructParams' => [
252 ICanWriteToStorage::class => [
253 'instanceOf' => StorageManager::class,
255 ['getBackend', [], Dice::CHAIN_CALL],
258 \Friendica\Core\KeyValueStorage\Capabilities\IManageKeyValuePairs::class => [
259 'instanceOf' => \Friendica\Core\KeyValueStorage\Type\DBKeyValueStorage::class,
261 Network\HTTPClient\Capability\ICanSendHttpRequests::class => [
262 'instanceOf' => Network\HTTPClient\Factory\HttpClient::class,
264 ['createClient', [], Dice::CHAIN_CALL],
267 Factory\Api\Mastodon\Error::class => [
268 'constructParams' => [
272 ParsedLogIterator::class => [
273 'constructParams' => [
274 [Dice::INSTANCE => Util\ReversedFileReader::class],
277 \Friendica\Core\Worker\Repository\Process::class => [
278 'constructParams' => [
282 App\Request::class => [
283 'constructParams' => [
287 \Psr\Clock\ClockInterface::class => [
288 'instanceOf' => Util\Clock\SystemClock::class
290 \Friendica\Module\Special\HTTPException::class => [
291 'constructParams' => [