]> git.mxchange.org Git - friendica.git/blob - static/dependencies.config.php
Merge pull request #7907 from nupplaphil/task/reduce_app_deps
[friendica.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\Session\ISession;
10 use Friendica\Database\Database;
11 use Friendica\Factory;
12 use Friendica\Util;
13 use Psr\Log\LoggerInterface;
14
15 /**
16  * The configuration defines "complex" dependencies inside Friendica
17  * So this classes shouldn't be simple or their dependencies are already defined here.
18  *
19  * This kind of dependencies are NOT required to be defined here:
20  *   - $a = new ClassA(new ClassB());
21  *   - $a = new ClassA();
22  *   - $a = new ClassA(Configuration $configuration);
23  *
24  * This kind of dependencies SHOULD be defined here:
25  *   - $a = new ClassA();
26  *     $b = $a->create();
27  *
28  *   - $a = new ClassA($creationPassedVariable);
29  *
30  */
31 return [
32         '*'                             => [
33                 // marks all class result as shared for other creations, so there's just
34                 // one instance for the whole execution
35                 'shared' => true,
36         ],
37         '$basepath'                     => [
38                 'instanceOf'      => Util\BasePath::class,
39                 'call'            => [
40                         ['getPath', [], Dice::CHAIN_CALL],
41                 ],
42                 'constructParams' => [
43                         dirname(__FILE__, 2),
44                         $_SERVER
45                 ]
46         ],
47         Util\BasePath::class            => [
48                 'constructParams' => [
49                         dirname(__FILE__, 2),
50                         $_SERVER
51                 ]
52         ],
53         Util\ConfigFileLoader::class    => [
54                 'shared'          => true,
55                 'constructParams' => [
56                         [Dice::INSTANCE => '$basepath'],
57                 ],
58         ],
59         Config\Cache\ConfigCache::class => [
60                 'instanceOf' => Factory\ConfigFactory::class,
61                 'call'       => [
62                         ['createCache', [], Dice::CHAIN_CALL],
63                 ],
64         ],
65         App\Mode::class                 => [
66                 'call' => [
67                         ['determineRunMode', [true, $_SERVER], Dice::CHAIN_CALL],
68                         ['determine', [], Dice::CHAIN_CALL],
69                 ],
70         ],
71         Config\Configuration::class     => [
72                 'instanceOf' => Factory\ConfigFactory::class,
73                 'call'       => [
74                         ['createConfig', [], Dice::CHAIN_CALL],
75                 ],
76         ],
77         Config\PConfiguration::class    => [
78                 'instanceOf' => Factory\ConfigFactory::class,
79                 'call'       => [
80                         ['createPConfig', [], Dice::CHAIN_CALL],
81                 ]
82         ],
83         Database::class                 => [
84                 'constructParams' => [
85                         [DICE::INSTANCE => \Psr\Log\NullLogger::class],
86                         $_SERVER,
87                 ],
88         ],
89         /**
90          * Creates the App\BaseURL
91          *
92          * Same as:
93          *   $baseURL = new App\BaseURL($configuration, $_SERVER);
94          */
95         App\BaseURL::class             => [
96                 'constructParams' => [
97                         $_SERVER,
98                 ],
99         ],
100         App\Page::class => [
101                 'constructParams' => [
102                         [Dice::INSTANCE => '$basepath'],
103                 ],
104         ],
105         /**
106          * Create a Logger, which implements the LoggerInterface
107          *
108          * Same as:
109          *   $loggerFactory = new Factory\LoggerFactory();
110          *   $logger = $loggerFactory->create($channel, $configuration, $profiler);
111          *
112          * Attention1: We can use DICE for detecting dependencies inside "chained" calls too
113          * Attention2: The variable "$channel" is passed inside the creation of the dependencies per:
114          *    $app = $dice->create(App::class, [], ['$channel' => 'index']);
115          *    and is automatically passed as an argument with the same name
116          */
117         LoggerInterface::class          => [
118                 'instanceOf' => Factory\LoggerFactory::class,
119                 'constructParams' => [
120                         'index',
121                 ],
122                 'call'       => [
123                         ['create', ['index'], Dice::CHAIN_CALL],
124                 ],
125         ],
126         '$devLogger'                    => [
127                 'instanceOf' => Factory\LoggerFactory::class,
128                 'constructParams' => [
129                         'dev',
130                 ],
131                 'call'       => [
132                         ['createDev', [], Dice::CHAIN_CALL],
133                 ]
134         ],
135         Cache\ICache::class             => [
136                 'instanceOf' => Factory\CacheFactory::class,
137                 'call'       => [
138                         ['create', [], Dice::CHAIN_CALL],
139                 ],
140         ],
141         Cache\IMemoryCache::class       => [
142                 'instanceOf' => Factory\CacheFactory::class,
143                 'call'       => [
144                         ['create', [], Dice::CHAIN_CALL],
145                 ],
146         ],
147         ILock::class                    => [
148                 'instanceOf' => Factory\LockFactory::class,
149                 'call'       => [
150                         ['create', [], Dice::CHAIN_CALL],
151                 ],
152         ],
153         App\Arguments::class => [
154                 'instanceOf' => App\Arguments::class,
155                 'call' => [
156                         ['determine', [$_SERVER, $_GET], Dice::CHAIN_CALL],
157                 ],
158         ],
159         App\Module::class => [
160                 'instanceOf' => App\Module::class,
161                 'call' => [
162                         ['determineModule', [], Dice::CHAIN_CALL],
163                 ],
164         ],
165         Friendica\Core\Process::class => [
166                 'constructParams' => [
167                         [Dice::INSTANCE => '$basepath'],
168                 ],
169         ],
170         App\Router::class => [
171                 'constructParams' => [
172                         $_SERVER, null
173                 ],
174                 'call' => [
175                         ['loadRoutes', [include __DIR__ . '/routes.config.php'], Dice::CHAIN_CALL],
176                 ],
177         ],
178         L10n::class => [
179                 'constructParams' => [
180                         $_SERVER, $_GET
181                 ],
182         ],
183         ISession::class => [
184                 'instanceOf' => Factory\SessionFactory::class,
185                 'call' => [
186                         ['createSession', [$_SERVER], Dice::CHAIN_CALL],
187                         ['start', [], Dice::CHAIN_CALL],
188                 ],
189         ],
190 ];