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\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;
52 use Psr\Log\LoggerInterface;
56 // marks all class result as shared for other creations, so there's just
57 // one instance for the whole execution
61 'instanceOf' => Util\BasePath::class,
63 ['getPath', [], Dice::CHAIN_CALL],
65 'constructParams' => [
70 Util\BasePath::class => [
71 'constructParams' => [
76 Util\ConfigFileLoader::class => [
78 'constructParams' => [
79 [Dice::INSTANCE => '$basepath'],
82 Config\Cache::class => [
83 'instanceOf' => Factory\ConfigFactory::class,
85 ['createCache', [$_SERVER], Dice::CHAIN_CALL],
90 ['determineRunMode', [true, $_SERVER], Dice::CHAIN_CALL],
91 ['determine', [], Dice::CHAIN_CALL],
94 Config\IConfig::class => [
95 'instanceOf' => Factory\ConfigFactory::class,
97 ['createConfig', [], Dice::CHAIN_CALL],
100 \Friendica\Core\PConfig\IPConfig::class => [
101 'instanceOf' => Factory\ConfigFactory::class,
103 ['createPConfig', [], Dice::CHAIN_CALL],
107 'constructParams' => [
108 [Dice::INSTANCE => \Psr\Log\NullLogger::class],
112 * Creates the App\BaseURL
115 * $baseURL = new App\BaseURL($configuration, $_SERVER);
117 App\BaseURL::class => [
118 'constructParams' => [
123 'constructParams' => [
124 [Dice::INSTANCE => '$basepath'],
128 * Create a Logger, which implements the LoggerInterface
131 * $loggerFactory = new Factory\LoggerFactory();
132 * $logger = $loggerFactory->create($channel, $configuration, $profiler);
134 * Attention1: We can use DICE for detecting dependencies inside "chained" calls too
135 * Attention2: The variable "$channel" is passed inside the creation of the dependencies per:
136 * $app = $dice->create(App::class, [], ['$channel' => 'index']);
137 * and is automatically passed as an argument with the same name
139 LoggerInterface::class => [
140 'instanceOf' => Factory\LoggerFactory::class,
141 'constructParams' => [
145 ['create', ['index'], Dice::CHAIN_CALL],
149 'instanceOf' => Factory\LoggerFactory::class,
150 'constructParams' => [
154 ['createDev', [], Dice::CHAIN_CALL],
157 Cache\ICache::class => [
158 'instanceOf' => Factory\CacheFactory::class,
160 ['create', [], Dice::CHAIN_CALL],
163 Cache\IMemoryCache::class => [
164 'instanceOf' => Factory\CacheFactory::class,
166 ['create', [], Dice::CHAIN_CALL],
170 'instanceOf' => Factory\LockFactory::class,
172 ['create', [], Dice::CHAIN_CALL],
175 App\Arguments::class => [
176 'instanceOf' => App\Arguments::class,
178 ['determine', [$_SERVER, $_GET], Dice::CHAIN_CALL],
181 App\Module::class => [
182 'instanceOf' => App\Module::class,
184 ['determineModule', [], Dice::CHAIN_CALL],
188 'constructParams' => [
189 [Dice::INSTANCE => '$basepath'],
193 App\Router::class => [
194 'constructParams' => [
196 __DIR__ . '/routes.config.php',
201 'constructParams' => [
206 'instanceOf' => Factory\SessionFactory::class,
208 ['createSession', [$_SERVER], Dice::CHAIN_CALL],
209 ['start', [], Dice::CHAIN_CALL],
213 'constructParams' => [
217 IWritableStorage::class => [
218 'instanceOf' => StorageManager::class,
220 ['getBackend', [], Dice::CHAIN_CALL],
223 Network\IHTTPClient::class => [
224 'instanceOf' => Factory\HTTPClientFactory::class,
226 ['createClient', [], Dice::CHAIN_CALL],
229 Factory\Api\Mastodon\Error::class => [
230 'constructParams' => [
234 ParsedLogIterator::class => [
235 'constructParams' => [
236 [Dice::INSTANCE => Util\ReversedFileReader::class],