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.

169 lines
4.1KB

  1. <?php
  2. use Dice\Dice;
  3. use Friendica\App;
  4. use Friendica\Core\Cache;
  5. use Friendica\Core\Config;
  6. use Friendica\Core\Lock\ILock;
  7. use Friendica\Database\Database;
  8. use Friendica\Factory;
  9. use Friendica\Util;
  10. use Psr\Log\LoggerInterface;
  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. ['determineRunMode', [true, $_SERVER], Dice::CHAIN_CALL],
  64. ['determine', [], Dice::CHAIN_CALL],
  65. ],
  66. ],
  67. Config\Configuration::class => [
  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 App\BaseURL
  87. *
  88. * Same as:
  89. * $baseURL = new App\BaseURL($configuration, $_SERVER);
  90. */
  91. App\BaseURL::class => [
  92. 'constructParams' => [
  93. $_SERVER,
  94. ],
  95. ],
  96. App\Page::class => [
  97. 'constructParams' => [
  98. [Dice::INSTANCE => '$basepath'],
  99. ],
  100. ],
  101. /**
  102. * Create a Logger, which implements the LoggerInterface
  103. *
  104. * Same as:
  105. * $loggerFactory = new Factory\LoggerFactory();
  106. * $logger = $loggerFactory->create($channel, $configuration, $profiler);
  107. *
  108. * Attention1: We can use DICE for detecting dependencies inside "chained" calls too
  109. * Attention2: The variable "$channel" is passed inside the creation of the dependencies per:
  110. * $app = $dice->create(App::class, [], ['$channel' => 'index']);
  111. * and is automatically passed as an argument with the same name
  112. */
  113. LoggerInterface::class => [
  114. 'instanceOf' => Factory\LoggerFactory::class,
  115. 'constructParams' => [
  116. 'index',
  117. ],
  118. 'call' => [
  119. ['create', ['index'], Dice::CHAIN_CALL],
  120. ],
  121. ],
  122. '$devLogger' => [
  123. 'instanceOf' => Factory\LoggerFactory::class,
  124. 'constructParams' => [
  125. 'dev',
  126. ],
  127. 'call' => [
  128. ['createDev', [], Dice::CHAIN_CALL],
  129. ]
  130. ],
  131. Cache\ICache::class => [
  132. 'instanceOf' => Factory\CacheFactory::class,
  133. 'call' => [
  134. ['create', [], Dice::CHAIN_CALL],
  135. ],
  136. ],
  137. Cache\IMemoryCache::class => [
  138. 'instanceOf' => Factory\CacheFactory::class,
  139. 'call' => [
  140. ['create', [], Dice::CHAIN_CALL],
  141. ],
  142. ],
  143. ILock::class => [
  144. 'instanceOf' => Factory\LockFactory::class,
  145. 'call' => [
  146. ['create', [], Dice::CHAIN_CALL],
  147. ],
  148. ],
  149. App\Arguments::class => [
  150. 'instanceOf' => App\Arguments::class,
  151. 'call' => [
  152. ['determine', [$_SERVER, $_GET], Dice::CHAIN_CALL],
  153. ],
  154. ],
  155. App\Module::class => [
  156. 'instanceOf' => App\Module::class,
  157. 'call' => [
  158. ['determineModule', [], Dice::CHAIN_CALL],
  159. ],
  160. ],
  161. Friendica\Core\Process::class => [
  162. 'constructParams' => [
  163. [Dice::INSTANCE => '$basepath'],
  164. ],
  165. ],
  166. ];