Moved BaseURL to App namespace (because similar type as Arguments/Modules/Modes)
[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                         ['determineBackend', [$_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         /**
99          * Create a Logger, which implements the LoggerInterface
100          *
101          * Same as:
102          *   $loggerFactory = new Factory\LoggerFactory();
103          *   $logger = $loggerFactory->create($channel, $configuration, $profiler);
104          *
105          * Attention1: We can use DICE for detecting dependencies inside "chained" calls too
106          * Attention2: The variable "$channel" is passed inside the creation of the dependencies per:
107          *    $app = $dice->create(App::class, [], ['$channel' => 'index']);
108          *    and is automatically passed as an argument with the same name
109          */
110         LoggerInterface::class          => [
111                 'instanceOf' => Factory\LoggerFactory::class,
112                 'call'       => [
113                         ['create', [], Dice::CHAIN_CALL],
114                 ],
115         ],
116         '$devLogger'                    => [
117                 'instanceOf' => Factory\LoggerFactory::class,
118                 'call'       => [
119                         ['createDev', [], Dice::CHAIN_CALL],
120                 ]
121         ],
122         Cache\ICache::class             => [
123                 'instanceOf' => Factory\CacheFactory::class,
124                 'call'       => [
125                         ['create', [], Dice::CHAIN_CALL],
126                 ],
127         ],
128         Cache\IMemoryCache::class       => [
129                 'instanceOf' => Factory\CacheFactory::class,
130                 'call'       => [
131                         ['create', [], Dice::CHAIN_CALL],
132                 ],
133         ],
134         ILock::class                    => [
135                 'instanceOf' => Factory\LockFactory::class,
136                 'call'       => [
137                         ['create', [], Dice::CHAIN_CALL],
138                 ],
139         ],
140         App\Arguments::class => [
141                 'instanceOf' => App\Arguments::class,
142                 'call' => [
143                         ['determine', [$_SERVER, $_GET], Dice::CHAIN_CALL],
144                 ],
145         ],
146         App\Module::class => [
147                 'instanceOf' => App\Module::class,
148                 'call' => [
149                         ['determineModule', [], Dice::CHAIN_CALL],
150                 ],
151         ],
152 ];