]> git.mxchange.org Git - friendica.git/blob - static/dependencies.config.php
55a2c6845b4bfba72db4a05cfa68bf6d5f7eb1ac
[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\Lock\ILockDriver;
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                         ['determine', [], Dice::CHAIN_CALL],
66                 ],
67         ],
68         Config\Configuration::class => [
69                 'instanceOf' => Factory\ConfigFactory::class,
70                 'call' => [
71                         ['createConfig', [], Dice::CHAIN_CALL],
72                 ],
73         ],
74         Config\PConfiguration::class => [
75                 'instanceOf' => Factory\ConfigFactory::class,
76                 'call' => [
77                         ['createPConfig', [], Dice::CHAIN_CALL],
78                 ]
79         ],
80         Database::class => [
81                 'constructParams' => [
82                         [DICE::INSTANCE => \Psr\Log\NullLogger::class],
83                         $_SERVER,
84                 ],
85         ],
86         /**
87          * Creates the Util\BaseURL
88          *
89          * Same as:
90          *   $baseURL = new Util\BaseURL($configuration, $_SERVER);
91          */
92         Util\BaseURL::class => [
93                 'constructParams' => [
94                         $_SERVER,
95                 ],
96         ],
97         /**
98          * Create a Logger, which implements the LoggerInterface
99          *
100          * Same as:
101          *   $loggerFactory = new Factory\LoggerFactory();
102          *   $logger = $loggerFactory->create($channel, $configuration, $profiler);
103          *
104          * Attention1: We can use DICE for detecting dependencies inside "chained" calls too
105          * Attention2: The variable "$channel" is passed inside the creation of the dependencies per:
106          *    $app = $dice->create(App::class, [], ['$channel' => 'index']);
107          *    and is automatically passed as an argument with the same name
108          */
109         LoggerInterface::class => [
110                 'instanceOf' => Factory\LoggerFactory::class,
111                 'call'       => [
112                         ['create', [], Dice::CHAIN_CALL],
113                 ],
114         ],
115         '$devLogger' => [
116                 'instanceOf' => Factory\LoggerFactory::class,
117                 'call'       => [
118                         ['createDev', [], Dice::CHAIN_CALL],
119                 ]
120         ],
121         Cache\ICacheDriver::class => [
122                 'instanceOf' => Factory\CacheDriverFactory::class,
123                 'call' => [
124                         ['create', [], Dice::CHAIN_CALL],
125                 ],
126         ],
127         Cache\IMemoryCacheDriver::class => [
128                 'instanceOf' => Cache\ICacheDriver::class,
129         ],
130         ILockDriver::class => [
131                 'instanceOf' => Factory\LockDriverFactory::class,
132                 'call' => [
133                         ['create', [], Dice::CHAIN_CALL],
134                 ],
135         ],
136 ];