]> git.mxchange.org Git - friendica.git/blob - static/dependencies.config.php
Ensure *toArray returns an array
[friendica.git] / static / dependencies.config.php
1 <?php
2
3 use Dice\Dice;
4 use Friendica\App;
5 use Friendica\Core\Config;
6 use Friendica\Database\Database;
7 use Friendica\Factory;
8 use Friendica\Util;
9 use Psr\Log\LoggerInterface;
10
11 /**
12  * The configuration defines "complex" dependencies inside Friendica
13  * So this classes shouldn't be simple or their dependencies are already defined here.
14  *
15  * This kind of dependencies are NOT required to be defined here:
16  *   - $a = new ClassA(new ClassB());
17  *   - $a = new ClassA();
18  *   - $a = new ClassA(Configuration $configuration);
19  *
20  * This kind of dependencies SHOULD be defined here:
21  *   - $a = new ClassA();
22  *     $b = $a->create();
23  *
24  *   - $a = new ClassA($creationPassedVariable);
25  *
26  */
27 return [
28         '*' => [
29                 // marks all class result as shared for other creations, so there's just
30                 // one instance for the whole execution
31                 'shared' => true,
32         ],
33         '$basepath' => [
34                 'instanceOf' => Util\BasePath::class,
35                 'call' => [
36                         ['getPath', [], Dice::CHAIN_CALL],
37                 ],
38                 'constructParams' => [
39                         dirname(__FILE__, 2),
40                         $_SERVER
41                 ]
42         ],
43         Util\BasePath::class => [
44                 'constructParams' => [
45                         dirname(__FILE__, 2),
46                         $_SERVER
47                 ]
48         ],
49         Util\ConfigFileLoader::class => [
50                 'shared' => true,
51                 'constructParams' => [
52                         [Dice::INSTANCE => '$basepath'],
53                 ],
54         ],
55         Config\Cache\ConfigCache::class => [
56                 'instanceOf' => Factory\ConfigFactory::class,
57                 'call'       => [
58                         ['createCache', [], Dice::CHAIN_CALL],
59                 ],
60         ],
61         App\Mode::class => [
62                 'call'   => [
63                         ['determine', [], Dice::CHAIN_CALL],
64                 ],
65         ],
66         Config\Configuration::class => [
67                 'shared' => true,
68                 'instanceOf' => Factory\ConfigFactory::class,
69                 'call' => [
70                         ['createConfig', [], Dice::CHAIN_CALL],
71                 ],
72         ],
73         Config\PConfiguration::class => [
74                 'instanceOf' => Factory\ConfigFactory::class,
75                 'call' => [
76                         ['createPConfig', [], Dice::CHAIN_CALL],
77                 ]
78         ],
79         Database::class => [
80                 'constructParams' => [
81                         [DICE::INSTANCE => \Psr\Log\NullLogger::class],
82                         $_SERVER,
83                 ],
84         ],
85         /**
86          * Creates the Util\BaseURL
87          *
88          * Same as:
89          *   $baseURL = new Util\BaseURL($configuration, $_SERVER);
90          */
91         Util\BaseURL::class => [
92                 'constructParams' => [
93                         $_SERVER,
94                 ],
95         ],
96         /**
97          * Create a Logger, which implements the LoggerInterface
98          *
99          * Same as:
100          *   $loggerFactory = new Factory\LoggerFactory();
101          *   $logger = $loggerFactory->create($channel, $configuration, $profiler);
102          *
103          * Attention1: We can use DICE for detecting dependencies inside "chained" calls too
104          * Attention2: The variable "$channel" is passed inside the creation of the dependencies per:
105          *    $app = $dice->create(App::class, [], ['$channel' => 'index']);
106          *    and is automatically passed as an argument with the same name
107          */
108         LoggerInterface::class => [
109                 'instanceOf' => Factory\LoggerFactory::class,
110                 'call'       => [
111                         ['create', [], Dice::CHAIN_CALL],
112                 ],
113         ],
114         '$devLogger' => [
115                 'instanceOf' => Factory\LoggerFactory::class,
116                 'call'       => [
117                         ['createDev', [], Dice::CHAIN_CALL],
118                 ]
119         ],
120 ];