5 use Friendica\Core\Cache;
6 use Friendica\Core\Config;
7 use Friendica\Core\L10n;
8 use Friendica\Core\Lock\ILock;
9 use Friendica\Core\Process;
10 use Friendica\Core\Session\ISession;
11 use Friendica\Core\StorageManager;
12 use Friendica\Database\Database;
13 use Friendica\Factory;
14 use Friendica\Model\Storage\IStorage;
15 use Friendica\Model\User\Cookie;
17 use Psr\Log\LoggerInterface;
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);
37 // marks all class result as shared for other creations, so there's just
38 // one instance for the whole execution
42 'instanceOf' => Util\BasePath::class,
44 ['getPath', [], Dice::CHAIN_CALL],
46 'constructParams' => [
51 Util\BasePath::class => [
52 'constructParams' => [
57 Util\ConfigFileLoader::class => [
59 'constructParams' => [
60 [Dice::INSTANCE => '$basepath'],
63 Config\Cache::class => [
64 'instanceOf' => Factory\ConfigFactory::class,
66 ['createCache', [], Dice::CHAIN_CALL],
71 ['determineRunMode', [true, $_SERVER], Dice::CHAIN_CALL],
72 ['determine', [], Dice::CHAIN_CALL],
75 Config\IConfig::class => [
76 'instanceOf' => Factory\ConfigFactory::class,
78 ['createConfig', [], Dice::CHAIN_CALL],
81 \Friendica\Core\PConfig\IPConfig::class => [
82 'instanceOf' => Factory\ConfigFactory::class,
84 ['createPConfig', [], Dice::CHAIN_CALL],
88 'constructParams' => [
89 [Dice::INSTANCE => \Psr\Log\NullLogger::class],
94 * Creates the App\BaseURL
97 * $baseURL = new App\BaseURL($configuration, $_SERVER);
99 App\BaseURL::class => [
100 'constructParams' => [
105 'constructParams' => [
106 [Dice::INSTANCE => '$basepath'],
110 * Create a Logger, which implements the LoggerInterface
113 * $loggerFactory = new Factory\LoggerFactory();
114 * $logger = $loggerFactory->create($channel, $configuration, $profiler);
116 * Attention1: We can use DICE for detecting dependencies inside "chained" calls too
117 * Attention2: The variable "$channel" is passed inside the creation of the dependencies per:
118 * $app = $dice->create(App::class, [], ['$channel' => 'index']);
119 * and is automatically passed as an argument with the same name
121 LoggerInterface::class => [
122 'instanceOf' => Factory\LoggerFactory::class,
123 'constructParams' => [
127 ['create', ['index'], Dice::CHAIN_CALL],
131 'instanceOf' => Factory\LoggerFactory::class,
132 'constructParams' => [
136 ['createDev', [], Dice::CHAIN_CALL],
139 Cache\ICache::class => [
140 'instanceOf' => Factory\CacheFactory::class,
142 ['create', [], Dice::CHAIN_CALL],
145 Cache\IMemoryCache::class => [
146 'instanceOf' => Factory\CacheFactory::class,
148 ['create', [], Dice::CHAIN_CALL],
152 'instanceOf' => Factory\LockFactory::class,
154 ['create', [], Dice::CHAIN_CALL],
157 App\Arguments::class => [
158 'instanceOf' => App\Arguments::class,
160 ['determine', [$_SERVER, $_GET], Dice::CHAIN_CALL],
163 App\Module::class => [
164 'instanceOf' => App\Module::class,
166 ['determineModule', [], Dice::CHAIN_CALL],
170 'constructParams' => [
171 [Dice::INSTANCE => '$basepath'],
174 App\Router::class => [
175 'constructParams' => [
179 ['loadRoutes', [include __DIR__ . '/routes.config.php'], Dice::CHAIN_CALL],
183 'constructParams' => [
188 'instanceOf' => Factory\SessionFactory::class,
190 ['createSession', [$_SERVER], Dice::CHAIN_CALL],
191 ['start', [], Dice::CHAIN_CALL],
195 'constructParams' => [
200 'instanceOf' => StorageManager::class,
202 ['getBackend', [], Dice::CHAIN_CALL],