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