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