Merge remote-tracking branch 'upstream/develop' into inverted
[friendica.git/.git] / static / dependencies.config.php
1 <?php
2
3 use Dice\Dice;
4 use Friendica\App;
5 use Friendica\Core\Cache;
6 use Friendica\Core\Config;
7 use Friendica\Core\L10n\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;
16 use Friendica\Util;
17 use Psr\Log\LoggerInterface;
18
19 /**
20  * The configuration defines "complex" dependencies inside Friendica
21  * So this classes shouldn't be simple or their dependencies are already defined here.
22  *
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);
27  *
28  * This kind of dependencies SHOULD be defined here:
29  *   - $a = new ClassA();
30  *     $b = $a->create();
31  *
32  *   - $a = new ClassA($creationPassedVariable);
33  *
34  */
35 return [
36         '*'                             => [
37                 // marks all class result as shared for other creations, so there's just
38                 // one instance for the whole execution
39                 'shared' => true,
40         ],
41         '$basepath'                     => [
42                 'instanceOf'      => Util\BasePath::class,
43                 'call'            => [
44                         ['getPath', [], Dice::CHAIN_CALL],
45                 ],
46                 'constructParams' => [
47                         dirname(__FILE__, 2),
48                         $_SERVER
49                 ]
50         ],
51         Util\BasePath::class            => [
52                 'constructParams' => [
53                         dirname(__FILE__, 2),
54                         $_SERVER
55                 ]
56         ],
57         Util\ConfigFileLoader::class    => [
58                 'shared'          => true,
59                 'constructParams' => [
60                         [Dice::INSTANCE => '$basepath'],
61                 ],
62         ],
63         Config\Cache\ConfigCache::class => [
64                 'instanceOf' => Factory\ConfigFactory::class,
65                 'call'       => [
66                         ['createCache', [], Dice::CHAIN_CALL],
67                 ],
68         ],
69         App\Mode::class                 => [
70                 'call' => [
71                         ['determineRunMode', [true, $_SERVER], Dice::CHAIN_CALL],
72                         ['determine', [], Dice::CHAIN_CALL],
73                 ],
74         ],
75         Config\IConfiguration::class     => [
76                 'instanceOf' => Factory\ConfigFactory::class,
77                 'call'       => [
78                         ['createConfig', [], Dice::CHAIN_CALL],
79                 ],
80         ],
81         Config\IPConfiguration::class    => [
82                 'instanceOf' => Factory\ConfigFactory::class,
83                 'call'       => [
84                         ['createPConfig', [], Dice::CHAIN_CALL],
85                 ]
86         ],
87         Database::class                 => [
88                 'constructParams' => [
89                         [Dice::INSTANCE => \Psr\Log\NullLogger::class],
90                         $_SERVER,
91                 ],
92         ],
93         /**
94          * Creates the App\BaseURL
95          *
96          * Same as:
97          *   $baseURL = new App\BaseURL($configuration, $_SERVER);
98          */
99         App\BaseURL::class             => [
100                 'constructParams' => [
101                         $_SERVER,
102                 ],
103         ],
104         App\Page::class => [
105                 'constructParams' => [
106                         [Dice::INSTANCE => '$basepath'],
107                 ],
108         ],
109         /**
110          * Create a Logger, which implements the LoggerInterface
111          *
112          * Same as:
113          *   $loggerFactory = new Factory\LoggerFactory();
114          *   $logger = $loggerFactory->create($channel, $configuration, $profiler);
115          *
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
120          */
121         LoggerInterface::class          => [
122                 'instanceOf' => Factory\LoggerFactory::class,
123                 'constructParams' => [
124                         'index',
125                 ],
126                 'call'       => [
127                         ['create', ['index'], Dice::CHAIN_CALL],
128                 ],
129         ],
130         '$devLogger'                    => [
131                 'instanceOf' => Factory\LoggerFactory::class,
132                 'constructParams' => [
133                         'dev',
134                 ],
135                 'call'       => [
136                         ['createDev', [], Dice::CHAIN_CALL],
137                 ]
138         ],
139         Cache\ICache::class             => [
140                 'instanceOf' => Factory\CacheFactory::class,
141                 'call'       => [
142                         ['create', [], Dice::CHAIN_CALL],
143                 ],
144         ],
145         Cache\IMemoryCache::class       => [
146                 'instanceOf' => Factory\CacheFactory::class,
147                 'call'       => [
148                         ['create', [], Dice::CHAIN_CALL],
149                 ],
150         ],
151         ILock::class                    => [
152                 'instanceOf' => Factory\LockFactory::class,
153                 'call'       => [
154                         ['create', [], Dice::CHAIN_CALL],
155                 ],
156         ],
157         App\Arguments::class => [
158                 'instanceOf' => App\Arguments::class,
159                 'call' => [
160                         ['determine', [$_SERVER, $_GET], Dice::CHAIN_CALL],
161                 ],
162         ],
163         App\Module::class => [
164                 'instanceOf' => App\Module::class,
165                 'call' => [
166                         ['determineModule', [], Dice::CHAIN_CALL],
167                 ],
168         ],
169         Process::class => [
170                 'constructParams' => [
171                         [Dice::INSTANCE => '$basepath'],
172                 ],
173         ],
174         App\Router::class => [
175                 'constructParams' => [
176                         $_SERVER, null
177                 ],
178                 'call' => [
179                         ['loadRoutes', [include __DIR__ . '/routes.config.php'], Dice::CHAIN_CALL],
180                 ],
181         ],
182         L10n::class => [
183                 'constructParams' => [
184                         $_SERVER, $_GET
185                 ],
186         ],
187         ISession::class => [
188                 'instanceOf' => Factory\SessionFactory::class,
189                 'call' => [
190                         ['createSession', [$_SERVER], Dice::CHAIN_CALL],
191                         ['start', [], Dice::CHAIN_CALL],
192                 ],
193         ],
194         Cookie::class => [
195                 'constructParams' => [
196                         $_SERVER, $_COOKIE
197                 ],
198         ],
199         IStorage::class => [
200                 'instanceOf' => StorageManager::class,
201                 'call' => [
202                         ['getBackend', [], Dice::CHAIN_CALL],
203                 ],
204         ],
205 ];