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\Session\Capability\IHandleUserSessions;
45 use Friendica\Core\Storage\Repository\StorageManager;
46 use Friendica\Database\Database;
47 use Friendica\Database\Definition\DbaDefinition;
48 use Friendica\Database\Definition\ViewDefinition;
49 use Friendica\Factory;
50 use Friendica\Core\Storage\Capability\ICanWriteToStorage;
51 use Friendica\Model\User\Cookie;
52 use Friendica\Model\Log\ParsedLogIterator;
53 use Friendica\Network;
55 use Psr\Log\LoggerInterface;
59 // marks all class result as shared for other creations, so there's just
60 // one instance for the whole execution
64 'instanceOf' => Util\BasePath::class,
66 ['getPath', [], Dice::CHAIN_CALL],
68 'constructParams' => [
73 Util\BasePath::class => [
74 'constructParams' => [
79 Config\Util\ConfigFileLoader::class => [
80 'instanceOf' => Config\Factory\Config::class,
82 ['createConfigFileLoader', [
83 [Dice::INSTANCE => '$basepath'],
88 Config\ValueObject\Cache::class => [
89 'instanceOf' => Config\Factory\Config::class,
91 ['createCache', [$_SERVER], Dice::CHAIN_CALL],
96 ['determineRunMode', [true, $_SERVER], Dice::CHAIN_CALL],
97 ['determine', [], Dice::CHAIN_CALL],
100 Config\Capability\IManageConfigValues::class => [
101 'instanceOf' => Config\Factory\Config::class,
103 ['create', [], Dice::CHAIN_CALL],
106 PConfig\Capability\IManagePersonalConfigValues::class => [
107 'instanceOf' => PConfig\Factory\PConfig::class,
109 ['create', [], Dice::CHAIN_CALL],
112 DbaDefinition::class => [
113 'constructParams' => [
114 [Dice::INSTANCE => '$basepath'],
117 ['load', [false], Dice::CHAIN_CALL],
120 ViewDefinition::class => [
121 'constructParams' => [
122 [Dice::INSTANCE => '$basepath'],
125 ['load', [false], Dice::CHAIN_CALL],
129 'constructParams' => [
130 [Dice::INSTANCE => \Psr\Log\NullLogger::class],
134 * Creates the App\BaseURL
137 * $baseURL = new App\BaseURL($configuration, $_SERVER);
139 App\BaseURL::class => [
140 'constructParams' => [
145 'constructParams' => [
146 [Dice::INSTANCE => '$basepath'],
150 * Create a Logger, which implements the LoggerInterface
153 * $loggerFactory = new Factory\LoggerFactory();
154 * $logger = $loggerFactory->create($channel, $configuration, $profiler);
156 * Attention1: We can use DICE for detecting dependencies inside "chained" calls too
157 * Attention2: The variable "$channel" is passed inside the creation of the dependencies per:
158 * $app = $dice->create(App::class, [], ['$channel' => 'index']);
159 * and is automatically passed as an argument with the same name
161 LoggerInterface::class => [
162 'instanceOf' => \Friendica\Core\Logger\Factory\Logger::class,
163 'constructParams' => [
167 ['create', [], Dice::CHAIN_CALL],
171 'instanceOf' => \Friendica\Core\Logger\Factory\Logger::class,
172 'constructParams' => [
176 ['createDev', [], Dice::CHAIN_CALL],
179 Cache\Capability\ICanCache::class => [
180 'instanceOf' => Cache\Factory\Cache::class,
182 ['createLocal', [], Dice::CHAIN_CALL],
185 Cache\Capability\ICanCacheInMemory::class => [
186 'instanceOf' => Cache\Factory\Cache::class,
188 ['createLocal', [], Dice::CHAIN_CALL],
191 Lock\Capability\ICanLock::class => [
192 'instanceOf' => Lock\Factory\Lock::class,
194 ['create', [], Dice::CHAIN_CALL],
197 App\Arguments::class => [
198 'instanceOf' => App\Arguments::class,
200 ['determine', [$_SERVER, $_GET], Dice::CHAIN_CALL],
203 \Friendica\Core\System::class => [
204 'constructParams' => [
205 [Dice::INSTANCE => '$basepath'],
208 App\Router::class => [
209 'constructParams' => [
211 __DIR__ . '/routes.config.php',
212 [Dice::INSTANCE => Dice::SELF],
217 'constructParams' => [
221 IHandleSessions::class => [
222 'instanceOf' => \Friendica\Core\Session\Factory\Session::class,
224 ['createSession', [$_SERVER], Dice::CHAIN_CALL],
225 ['start', [], Dice::CHAIN_CALL],
228 IHandleUserSessions::class => [
229 'instanceOf' => \Friendica\Core\Session\Model\UserSession::class,
232 'constructParams' => [
236 ICanWriteToStorage::class => [
237 'instanceOf' => StorageManager::class,
239 ['getBackend', [], Dice::CHAIN_CALL],
242 Network\HTTPClient\Capability\ICanSendHttpRequests::class => [
243 'instanceOf' => Network\HTTPClient\Factory\HttpClient::class,
245 ['createClient', [], Dice::CHAIN_CALL],
248 Factory\Api\Mastodon\Error::class => [
249 'constructParams' => [
253 ParsedLogIterator::class => [
254 'constructParams' => [
255 [Dice::INSTANCE => Util\ReversedFileReader::class],
258 \Friendica\Core\Worker\Repository\Process::class => [
259 'constructParams' => [
263 App\Request::class => [
264 'constructParams' => [