Merge pull request #8269 from MrPetovan/bug/frio-more-actions
[friendica.git/.git] / static / dependencies.config.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2020, Friendica
4  *
5  * @license GNU AGPL version 3 or any later version
6  *
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.
11  *
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.
16  *
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/>.
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
36 use Dice\Dice;
37 use Friendica\App;
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\Util;
50 use Psr\Log\LoggerInterface;
51
52 return [
53         '*'                             => [
54                 // marks all class result as shared for other creations, so there's just
55                 // one instance for the whole execution
56                 'shared' => true,
57         ],
58         '$basepath'                     => [
59                 'instanceOf'      => Util\BasePath::class,
60                 'call'            => [
61                         ['getPath', [], Dice::CHAIN_CALL],
62                 ],
63                 'constructParams' => [
64                         dirname(__FILE__, 2),
65                         $_SERVER
66                 ]
67         ],
68         Util\BasePath::class         => [
69                 'constructParams' => [
70                         dirname(__FILE__, 2),
71                         $_SERVER
72                 ]
73         ],
74         Util\ConfigFileLoader::class => [
75                 'shared'          => true,
76                 'constructParams' => [
77                         [Dice::INSTANCE => '$basepath'],
78                 ],
79         ],
80         Config\Cache::class          => [
81                 'instanceOf' => Factory\ConfigFactory::class,
82                 'call'       => [
83                         ['createCache', [], Dice::CHAIN_CALL],
84                 ],
85         ],
86         App\Mode::class              => [
87                 'call' => [
88                         ['determineRunMode', [true, $_SERVER], Dice::CHAIN_CALL],
89                         ['determine', [], Dice::CHAIN_CALL],
90                 ],
91         ],
92         Config\IConfig::class                   => [
93                 'instanceOf' => Factory\ConfigFactory::class,
94                 'call'       => [
95                         ['createConfig', [], Dice::CHAIN_CALL],
96                 ],
97         ],
98         \Friendica\Core\PConfig\IPConfig::class => [
99                 'instanceOf' => Factory\ConfigFactory::class,
100                 'call'       => [
101                         ['createPConfig', [], Dice::CHAIN_CALL],
102                 ]
103         ],
104         Database::class                         => [
105                 'constructParams' => [
106                         [Dice::INSTANCE => \Psr\Log\NullLogger::class],
107                         $_SERVER,
108                 ],
109         ],
110         /**
111          * Creates the App\BaseURL
112          *
113          * Same as:
114          *   $baseURL = new App\BaseURL($configuration, $_SERVER);
115          */
116         App\BaseURL::class             => [
117                 'constructParams' => [
118                         $_SERVER,
119                 ],
120         ],
121         App\Page::class => [
122                 'constructParams' => [
123                         [Dice::INSTANCE => '$basepath'],
124                 ],
125         ],
126         /**
127          * Create a Logger, which implements the LoggerInterface
128          *
129          * Same as:
130          *   $loggerFactory = new Factory\LoggerFactory();
131          *   $logger = $loggerFactory->create($channel, $configuration, $profiler);
132          *
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
137          */
138         LoggerInterface::class          => [
139                 'instanceOf' => Factory\LoggerFactory::class,
140                 'constructParams' => [
141                         'index',
142                 ],
143                 'call'       => [
144                         ['create', ['index'], Dice::CHAIN_CALL],
145                 ],
146         ],
147         '$devLogger'                    => [
148                 'instanceOf' => Factory\LoggerFactory::class,
149                 'constructParams' => [
150                         'dev',
151                 ],
152                 'call'       => [
153                         ['createDev', [], Dice::CHAIN_CALL],
154                 ]
155         ],
156         Cache\ICache::class             => [
157                 'instanceOf' => Factory\CacheFactory::class,
158                 'call'       => [
159                         ['create', [], Dice::CHAIN_CALL],
160                 ],
161         ],
162         Cache\IMemoryCache::class       => [
163                 'instanceOf' => Factory\CacheFactory::class,
164                 'call'       => [
165                         ['create', [], Dice::CHAIN_CALL],
166                 ],
167         ],
168         ILock::class                    => [
169                 'instanceOf' => Factory\LockFactory::class,
170                 'call'       => [
171                         ['create', [], Dice::CHAIN_CALL],
172                 ],
173         ],
174         App\Arguments::class => [
175                 'instanceOf' => App\Arguments::class,
176                 'call' => [
177                         ['determine', [$_SERVER, $_GET], Dice::CHAIN_CALL],
178                 ],
179         ],
180         App\Module::class => [
181                 'instanceOf' => App\Module::class,
182                 'call' => [
183                         ['determineModule', [], Dice::CHAIN_CALL],
184                 ],
185         ],
186         Process::class => [
187                 'constructParams' => [
188                         [Dice::INSTANCE => '$basepath'],
189                 ],
190         ],
191         App\Router::class => [
192                 'constructParams' => [
193                         $_SERVER, null
194                 ],
195                 'call' => [
196                         ['loadRoutes', [include __DIR__ . '/routes.config.php'], Dice::CHAIN_CALL],
197                 ],
198         ],
199         L10n::class => [
200                 'constructParams' => [
201                         $_SERVER, $_GET
202                 ],
203         ],
204         ISession::class => [
205                 'instanceOf' => Factory\SessionFactory::class,
206                 'call' => [
207                         ['createSession', [$_SERVER], Dice::CHAIN_CALL],
208                         ['start', [], Dice::CHAIN_CALL],
209                 ],
210         ],
211         Cookie::class => [
212                 'constructParams' => [
213                         $_SERVER, $_COOKIE
214                 ],
215         ],
216         IStorage::class => [
217                 'instanceOf' => StorageManager::class,
218                 'call' => [
219                         ['getBackend', [], Dice::CHAIN_CALL],
220                 ],
221         ],
222 ];