Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

212 lines
7.2KB

  1. <?php
  2. namespace Lc\SovBundle\Controller;
  3. use Doctrine\ORM\EntityManagerInterface;
  4. use Knp\Component\Pager\PaginatorInterface;
  5. use Lc\SovBundle\Container\ComponentContainer;
  6. use Lc\SovBundle\Container\File\FileContainer;
  7. use Lc\SovBundle\Container\Newsletter\NewsletterContainer;
  8. use Lc\SovBundle\Container\Reminder\ReminderContainer;
  9. use Lc\SovBundle\Container\Setting\SiteSettingContainer;
  10. use Lc\SovBundle\Container\Site\NewsContainer;
  11. use Lc\SovBundle\Container\Site\PageContainer;
  12. use Lc\SovBundle\Container\Site\SiteContainer;
  13. use Lc\SovBundle\Container\Ticket\TicketContainer;
  14. use Lc\SovBundle\Container\Ticket\TicketMessageContainer;
  15. use Lc\SovBundle\Container\User\GroupUserContainer;
  16. use Lc\SovBundle\Container\User\UserContainer;
  17. use Lc\SovBundle\Solver\Setting\SettingSolver;
  18. use Lc\SovBundle\Translation\FlashBagTranslator;
  19. use Lc\SovBundle\Translation\TranslatorAdmin;
  20. use Psr\Log\LoggerInterface;
  21. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController as SfAbstractController;
  22. use Symfony\Component\EventDispatcher\EventDispatcherInterface;
  23. use Symfony\Component\HttpFoundation\Request;
  24. use Symfony\Component\HttpFoundation\RequestStack;
  25. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  26. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  27. use Symfony\Component\Security\Core\Security;
  28. use Symfony\Contracts\Translation\TranslatorInterface;
  29. use Twig\Environment;
  30. class AbstractController extends SfAbstractController
  31. {
  32. //TODO doit utiiliser un controller trait, et la totalité des méthodes de controller seront dans le trait
  33. public static function getSubscribedServices()
  34. {
  35. return array_merge(
  36. parent::getSubscribedServices(),
  37. [
  38. Environment::class => Environment::class,
  39. Security::class => Security::class,
  40. EntityManagerInterface::class => EntityManagerInterface::class,
  41. UrlGeneratorInterface::class => UrlGeneratorInterface::class,
  42. SessionInterface::class => SessionInterface::class,
  43. PaginatorInterface::class => PaginatorInterface::class,
  44. RequestStack::class => RequestStack::class,
  45. EventDispatcherInterface::class => EventDispatcherInterface::class,
  46. LoggerInterface::class => LoggerInterface::class,
  47. TranslatorInterface::class => TranslatorInterface::class,
  48. TranslatorAdmin::class => TranslatorAdmin::class,
  49. FlashBagTranslator::class => FlashBagTranslator::class,
  50. SettingSolver::class => SettingSolver::class,
  51. ComponentContainer::class => ComponentContainer::class,
  52. FileContainer::class => FileContainer::class,
  53. NewsletterContainer::class => NewsletterContainer::class,
  54. ReminderContainer::class => ReminderContainer::class,
  55. NewsContainer::class => NewsContainer::class,
  56. PageContainer::class => PageContainer::class,
  57. SiteContainer::class => SiteContainer::class,
  58. TicketContainer::class => TicketContainer::class,
  59. TicketMessageContainer::class => TicketMessageContainer::class,
  60. GroupUserContainer::class => GroupUserContainer::class,
  61. UserContainer::class => UserContainer::class,
  62. SiteSettingContainer::class => SiteSettingContainer::class,
  63. ]
  64. );
  65. }
  66. public function addFlashTranslator(string $type, $translationKeyName, $translationEntityName = null, $translationParam = array()):void
  67. {
  68. if ($translationEntityName === null && method_exists($this, 'getTranslationEntityName')) {
  69. $translationEntityName = $this->getTranslationEntityName();
  70. }
  71. $this->get(FlashBagTranslator::class)->add($type, $translationKeyName, $translationEntityName, $translationParam);
  72. }
  73. public function getReferer(Request $request): ?string
  74. {
  75. return $request->headers->get('referer');
  76. }
  77. public function getTemplating(): Environment
  78. {
  79. return $this->get(Environment::class);
  80. }
  81. public function getEntityManager(): EntityManagerInterface
  82. {
  83. return $this->get(EntityManagerInterface::class);
  84. }
  85. public function getRouter(): UrlGeneratorInterface
  86. {
  87. return $this->get(UrlGeneratorInterface::class);
  88. }
  89. public function getSession(): SessionInterface
  90. {
  91. return $this->get(SessionInterface::class);
  92. }
  93. public function getSecurity(): Security
  94. {
  95. return $this->get(Security::class);
  96. }
  97. public function getPaginator(): PaginatorInterface
  98. {
  99. return $this->get(PaginatorInterface::class);
  100. }
  101. public function getRequestStack(): RequestStack
  102. {
  103. return $this->get(RequestStack::class);
  104. }
  105. public function getEventDispatcher(): EventDispatcherInterface
  106. {
  107. return $this->get(EventDispatcherInterface::class);
  108. }
  109. public function getTranslator(): TranslatorInterface
  110. {
  111. return $this->get(TranslatorInterface::class);
  112. }
  113. public function getTranslatorAdmin(): TranslatorAdmin
  114. {
  115. return $this->get(TranslatorAdmin::class);
  116. }
  117. public function getLogger(): LoggerInterface
  118. {
  119. return $this->get(LoggerInterface::class);
  120. }
  121. public function getSettingSolver(): SettingSolver
  122. {
  123. return $this->get(SettingSolver::class);
  124. }
  125. public function getSettingValue($entity, $settingName)
  126. {
  127. return $this->getSettingSolver()->getSettingValue($entity, $settingName);
  128. }
  129. public function getComponentContainer(): ComponentContainer
  130. {
  131. return $this->get(ComponentContainer::class);
  132. }
  133. public function getFileContainer(): FileContainer
  134. {
  135. return $this->get(FileContainer::class);
  136. }
  137. public function getNewsletterContainer(): NewsletterContainer
  138. {
  139. return $this->get(NewsletterContainer::class);
  140. }
  141. public function getReminderContainer(): ReminderContainer
  142. {
  143. return $this->get(ReminderContainer::class);
  144. }
  145. public function getNewsContainer(): NewsContainer
  146. {
  147. return $this->get(NewsContainer::class);
  148. }
  149. public function getPageContainer(): PageContainer
  150. {
  151. return $this->get(PageContainer::class);
  152. }
  153. public function getSiteContainer(): SiteContainer
  154. {
  155. return $this->get(SiteContainer::class);
  156. }
  157. public function getTicketContainer(): TicketContainer
  158. {
  159. return $this->get(TicketContainer::class);
  160. }
  161. public function getTicketMessageContainer(): TicketMessageContainer
  162. {
  163. return $this->get(TicketMessageContainer::class);
  164. }
  165. public function getGroupUserContainer(): GroupUserContainer
  166. {
  167. return $this->get(GroupUserContainer::class);
  168. }
  169. public function getUserContainer(): UserContainer
  170. {
  171. return $this->get(UserContainer::class);
  172. }
  173. public function getSiteSettingContainer(): SiteSettingContainer
  174. {
  175. return $this->get(SiteSettingContainer::class);
  176. }
  177. }