3 * @copyright Copyright (C) 2020, Friendica
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\IStorage;
48 use Friendica\Model\User\Cookie;
49 use Friendica\Network;
51 use Psr\Log\LoggerInterface;
55 // marks all class result as shared for other creations, so there's just
56 // one instance for the whole execution
60 'instanceOf' => Util\BasePath::class,
62 ['getPath', [], Dice::CHAIN_CALL],
64 'constructParams' => [
69 Util\BasePath::class => [
70 'constructParams' => [
75 Util\ConfigFileLoader::class => [
77 'constructParams' => [
78 [Dice::INSTANCE => '$basepath'],
81 Config\Cache::class => [
82 'instanceOf' => Factory\ConfigFactory::class,
84 ['createCache', [$_SERVER], Dice::CHAIN_CALL],
89 ['determineRunMode', [true, $_SERVER], Dice::CHAIN_CALL],
90 ['determine', [], Dice::CHAIN_CALL],
93 Config\IConfig::class => [
94 'instanceOf' => Factory\ConfigFactory::class,
96 ['createConfig', [], Dice::CHAIN_CALL],
99 \Friendica\Core\PConfig\IPConfig::class => [
100 'instanceOf' => Factory\ConfigFactory::class,
102 ['createPConfig', [], Dice::CHAIN_CALL],
106 'constructParams' => [
107 [Dice::INSTANCE => \Psr\Log\NullLogger::class],
111 * Creates the App\BaseURL
114 * $baseURL = new App\BaseURL($configuration, $_SERVER);
116 App\BaseURL::class => [
117 'constructParams' => [
122 'constructParams' => [
123 [Dice::INSTANCE => '$basepath'],
127 * Create a Logger, which implements the LoggerInterface
130 * $loggerFactory = new Factory\LoggerFactory();
131 * $logger = $loggerFactory->create($channel, $configuration, $profiler);
133 * Attention1: We can use DICE for detecting dependencies inside "chained" calls too
134 * Attention2: The variable "$channel" is passed inside the creation of the dependencies per:
135 * $app = $dice->create(App::class, [], ['$channel' => 'index']);
136 * and is automatically passed as an argument with the same name
138 LoggerInterface::class => [
139 'instanceOf' => Factory\LoggerFactory::class,
140 'constructParams' => [
144 ['create', ['index'], Dice::CHAIN_CALL],
148 'instanceOf' => Factory\LoggerFactory::class,
149 'constructParams' => [
153 ['createDev', [], Dice::CHAIN_CALL],
156 Cache\ICache::class => [
157 'instanceOf' => Factory\CacheFactory::class,
159 ['create', [], Dice::CHAIN_CALL],
162 Cache\IMemoryCache::class => [
163 'instanceOf' => Factory\CacheFactory::class,
165 ['create', [], Dice::CHAIN_CALL],
169 'instanceOf' => Factory\LockFactory::class,
171 ['create', [], Dice::CHAIN_CALL],
174 App\Arguments::class => [
175 'instanceOf' => App\Arguments::class,
177 ['determine', [$_SERVER, $_GET], Dice::CHAIN_CALL],
180 App\Module::class => [
181 'instanceOf' => App\Module::class,
183 ['determineModule', [], Dice::CHAIN_CALL],
187 'constructParams' => [
188 [Dice::INSTANCE => '$basepath'],
192 App\Router::class => [
193 'constructParams' => [
195 __DIR__ . '/routes.config.php',
200 'constructParams' => [
205 'instanceOf' => Factory\SessionFactory::class,
207 ['createSession', [$_SERVER], Dice::CHAIN_CALL],
208 ['start', [], Dice::CHAIN_CALL],
212 'constructParams' => [
217 'instanceOf' => StorageManager::class,
219 ['getBackend', [], Dice::CHAIN_CALL],
222 Network\IHTTPRequest::class => [
223 'instanceOf' => Network\HTTPRequest::class,