Friendica Communications Platform (please note that this is a clone of the repository at github, issues are handled there) https://friendi.ca
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

183 lines
4.4KB

  1. <?php
  2. use Dice\Dice;
  3. use Friendica\App;
  4. use Friendica\Core\Cache;
  5. use Friendica\Core\Config;
  6. use Friendica\Core\L10n\L10n;
  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. * The configuration defines "complex" dependencies inside Friendica
  14. * So this classes shouldn't be simple or their dependencies are already defined here.
  15. *
  16. * This kind of dependencies are NOT required to be defined here:
  17. * - $a = new ClassA(new ClassB());
  18. * - $a = new ClassA();
  19. * - $a = new ClassA(Configuration $configuration);
  20. *
  21. * This kind of dependencies SHOULD be defined here:
  22. * - $a = new ClassA();
  23. * $b = $a->create();
  24. *
  25. * - $a = new ClassA($creationPassedVariable);
  26. *
  27. */
  28. return [
  29. '*' => [
  30. // marks all class result as shared for other creations, so there's just
  31. // one instance for the whole execution
  32. 'shared' => true,
  33. ],
  34. '$basepath' => [
  35. 'instanceOf' => Util\BasePath::class,
  36. 'call' => [
  37. ['getPath', [], Dice::CHAIN_CALL],
  38. ],
  39. 'constructParams' => [
  40. dirname(__FILE__, 2),
  41. $_SERVER
  42. ]
  43. ],
  44. Util\BasePath::class => [
  45. 'constructParams' => [
  46. dirname(__FILE__, 2),
  47. $_SERVER
  48. ]
  49. ],
  50. Util\ConfigFileLoader::class => [
  51. 'shared' => true,
  52. 'constructParams' => [
  53. [Dice::INSTANCE => '$basepath'],
  54. ],
  55. ],
  56. Config\Cache\ConfigCache::class => [
  57. 'instanceOf' => Factory\ConfigFactory::class,
  58. 'call' => [
  59. ['createCache', [], Dice::CHAIN_CALL],
  60. ],
  61. ],
  62. App\Mode::class => [
  63. 'call' => [
  64. ['determineRunMode', [true, $_SERVER], Dice::CHAIN_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 App\BaseURL
  88. *
  89. * Same as:
  90. * $baseURL = new App\BaseURL($configuration, $_SERVER);
  91. */
  92. App\BaseURL::class => [
  93. 'constructParams' => [
  94. $_SERVER,
  95. ],
  96. ],
  97. App\Page::class => [
  98. 'constructParams' => [
  99. [Dice::INSTANCE => '$basepath'],
  100. ],
  101. ],
  102. /**
  103. * Create a Logger, which implements the LoggerInterface
  104. *
  105. * Same as:
  106. * $loggerFactory = new Factory\LoggerFactory();
  107. * $logger = $loggerFactory->create($channel, $configuration, $profiler);
  108. *
  109. * Attention1: We can use DICE for detecting dependencies inside "chained" calls too
  110. * Attention2: The variable "$channel" is passed inside the creation of the dependencies per:
  111. * $app = $dice->create(App::class, [], ['$channel' => 'index']);
  112. * and is automatically passed as an argument with the same name
  113. */
  114. LoggerInterface::class => [
  115. 'instanceOf' => Factory\LoggerFactory::class,
  116. 'constructParams' => [
  117. 'index',
  118. ],
  119. 'call' => [
  120. ['create', ['index'], Dice::CHAIN_CALL],
  121. ],
  122. ],
  123. '$devLogger' => [
  124. 'instanceOf' => Factory\LoggerFactory::class,
  125. 'constructParams' => [
  126. 'dev',
  127. ],
  128. 'call' => [
  129. ['createDev', [], Dice::CHAIN_CALL],
  130. ]
  131. ],
  132. Cache\ICache::class => [
  133. 'instanceOf' => Factory\CacheFactory::class,
  134. 'call' => [
  135. ['create', [], Dice::CHAIN_CALL],
  136. ],
  137. ],
  138. Cache\IMemoryCache::class => [
  139. 'instanceOf' => Factory\CacheFactory::class,
  140. 'call' => [
  141. ['create', [], Dice::CHAIN_CALL],
  142. ],
  143. ],
  144. ILock::class => [
  145. 'instanceOf' => Factory\LockFactory::class,
  146. 'call' => [
  147. ['create', [], Dice::CHAIN_CALL],
  148. ],
  149. ],
  150. App\Arguments::class => [
  151. 'instanceOf' => App\Arguments::class,
  152. 'call' => [
  153. ['determine', [$_SERVER, $_GET], Dice::CHAIN_CALL],
  154. ],
  155. ],
  156. App\Module::class => [
  157. 'instanceOf' => App\Module::class,
  158. 'call' => [
  159. ['determineModule', [], Dice::CHAIN_CALL],
  160. ],
  161. ],
  162. Friendica\Core\Process::class => [
  163. 'constructParams' => [
  164. [Dice::INSTANCE => '$basepath'],
  165. ],
  166. ],
  167. App\Router::class => [
  168. 'constructParams' => [
  169. $_SERVER, null
  170. ],
  171. 'call' => [
  172. ['loadRoutes', [include __DIR__ . '/routes.config.php'], Dice::CHAIN_CALL],
  173. ],
  174. ],
  175. L10n::class => [
  176. 'constructParams' => [
  177. $_SERVER, $_GET
  178. ],
  179. ],
  180. ];