/app/ServiceProvider/ClassProvider.php

https://github.com/wheatbin/wheatbin · PHP · 154 lines · 142 code · 12 blank · 0 comment · 0 complexity · 639b903f958ede86ed85994131b2a205 MD5 · raw file

  1. <?php
  2. namespace Kanboard\ServiceProvider;
  3. use Pimple\Container;
  4. use Pimple\ServiceProviderInterface;
  5. use League\HTMLToMarkdown\HtmlConverter;
  6. use Kanboard\Core\Mail\Client as EmailClient;
  7. use Kanboard\Core\ObjectStorage\FileStorage;
  8. use Kanboard\Core\Paginator;
  9. use Kanboard\Core\Http\OAuth2;
  10. use Kanboard\Core\Tool;
  11. use Kanboard\Core\Http\Client as HttpClient;
  12. class ClassProvider implements ServiceProviderInterface
  13. {
  14. private $classes = array(
  15. 'Model' => array(
  16. 'Action',
  17. 'Authentication',
  18. 'Board',
  19. 'Category',
  20. 'Color',
  21. 'Comment',
  22. 'Config',
  23. 'Currency',
  24. 'CustomFilter',
  25. 'File',
  26. 'Group',
  27. 'GroupMember',
  28. 'LastLogin',
  29. 'Link',
  30. 'Notification',
  31. 'OverdueNotification',
  32. 'Project',
  33. 'ProjectActivity',
  34. 'ProjectAnalytic',
  35. 'ProjectDuplication',
  36. 'ProjectDailyColumnStats',
  37. 'ProjectDailyStats',
  38. 'ProjectPermission',
  39. 'ProjectNotification',
  40. 'ProjectMetadata',
  41. 'ProjectGroupRole',
  42. 'ProjectUserRole',
  43. 'RememberMeSession',
  44. 'Subtask',
  45. 'SubtaskExport',
  46. 'SubtaskTimeTracking',
  47. 'Swimlane',
  48. 'Task',
  49. 'TaskAnalytic',
  50. 'TaskCreation',
  51. 'TaskDuplication',
  52. 'TaskExport',
  53. 'TaskFinder',
  54. 'TaskFilter',
  55. 'TaskLink',
  56. 'TaskModification',
  57. 'TaskPermission',
  58. 'TaskPosition',
  59. 'TaskStatus',
  60. 'TaskValidator',
  61. 'TaskImport',
  62. 'TaskMetadata',
  63. 'Transition',
  64. 'User',
  65. 'UserImport',
  66. 'UserLocking',
  67. 'UserNotification',
  68. 'UserNotificationFilter',
  69. 'UserUnreadNotification',
  70. 'UserMetadata',
  71. ),
  72. 'Formatter' => array(
  73. 'TaskFilterGanttFormatter',
  74. 'TaskFilterAutoCompleteFormatter',
  75. 'TaskFilterCalendarFormatter',
  76. 'TaskFilterICalendarFormatter',
  77. 'ProjectGanttFormatter',
  78. 'UserFilterAutoCompleteFormatter',
  79. 'GroupAutoCompleteFormatter',
  80. ),
  81. 'Core' => array(
  82. 'DateParser',
  83. 'Helper',
  84. 'Lexer',
  85. 'Template',
  86. ),
  87. 'Core\Http' => array(
  88. 'Request',
  89. 'Response',
  90. 'RememberMeCookie',
  91. ),
  92. 'Core\Cache' => array(
  93. 'MemoryCache',
  94. ),
  95. 'Core\Plugin' => array(
  96. 'Hook',
  97. ),
  98. 'Core\Security' => array(
  99. 'Token',
  100. 'Role',
  101. ),
  102. 'Core\User' => array(
  103. 'GroupSync',
  104. 'UserSync',
  105. 'UserSession',
  106. 'UserProfile',
  107. ),
  108. 'Integration' => array(
  109. 'BitbucketWebhook',
  110. 'GithubWebhook',
  111. 'GitlabWebhook',
  112. )
  113. );
  114. public function register(Container $container)
  115. {
  116. Tool::buildDIC($container, $this->classes);
  117. $container['paginator'] = $container->factory(function ($c) {
  118. return new Paginator($c);
  119. });
  120. $container['oauth'] = $container->factory(function ($c) {
  121. return new OAuth2($c);
  122. });
  123. $container['httpClient'] = function ($c) {
  124. return new HttpClient($c);
  125. };
  126. $container['htmlConverter'] = function () {
  127. return new HtmlConverter(array('strip_tags' => true));
  128. };
  129. $container['objectStorage'] = function () {
  130. return new FileStorage(FILES_DIR);
  131. };
  132. $container['emailClient'] = function ($container) {
  133. $mailer = new EmailClient($container);
  134. $mailer->setTransport('smtp', '\Kanboard\Core\Mail\Transport\Smtp');
  135. $mailer->setTransport('sendmail', '\Kanboard\Core\Mail\Transport\Sendmail');
  136. $mailer->setTransport('mail', '\Kanboard\Core\Mail\Transport\Mail');
  137. return $mailer;
  138. };
  139. $container['cspRules'] = array('style-src' => "'self' 'unsafe-inline'", 'img-src' => '* data:');
  140. return $container;
  141. }
  142. }