您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

210 行
7.1KB

  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. public static function getSubscribedServices()
  33. {
  34. return array_merge(
  35. parent::getSubscribedServices(),
  36. [
  37. Environment::class => Environment::class,
  38. Security::class => Security::class,
  39. EntityManagerInterface::class => EntityManagerInterface::class,
  40. UrlGeneratorInterface::class => UrlGeneratorInterface::class,
  41. SessionInterface::class => SessionInterface::class,
  42. PaginatorInterface::class => PaginatorInterface::class,
  43. RequestStack::class => RequestStack::class,
  44. EventDispatcherInterface::class => EventDispatcherInterface::class,
  45. LoggerInterface::class => LoggerInterface::class,
  46. TranslatorInterface::class => TranslatorInterface::class,
  47. TranslatorAdmin::class => TranslatorAdmin::class,
  48. FlashBagTranslator::class => FlashBagTranslator::class,
  49. SettingSolver::class => SettingSolver::class,
  50. ComponentContainer::class => ComponentContainer::class,
  51. FileContainer::class => FileContainer::class,
  52. NewsletterContainer::class => NewsletterContainer::class,
  53. ReminderContainer::class => ReminderContainer::class,
  54. NewsContainer::class => NewsContainer::class,
  55. PageContainer::class => PageContainer::class,
  56. SiteContainer::class => SiteContainer::class,
  57. TicketContainer::class => TicketContainer::class,
  58. TicketMessageContainer::class => TicketMessageContainer::class,
  59. GroupUserContainer::class => GroupUserContainer::class,
  60. UserContainer::class => UserContainer::class,
  61. SiteSettingContainer::class => SiteSettingContainer::class,
  62. ]
  63. );
  64. }
  65. public function addFlashTranslator(string $type, $translationKeyName, $translationEntityName = null, $translationParam = array()):void
  66. {
  67. if ($translationEntityName === null && method_exists($this, 'getTranslationEntityName')) {
  68. $translationEntityName = $this->getTranslationEntityName();
  69. }
  70. $this->get(FlashBagTranslator::class)->add($type, $translationKeyName, $translationEntityName, $translationParam);
  71. }
  72. public function getReferer(Request $request): ?string
  73. {
  74. return $request->headers->get('referer');
  75. }
  76. public function getTemplating(): Environment
  77. {
  78. return $this->get(Environment::class);
  79. }
  80. public function getEntityManager(): EntityManagerInterface
  81. {
  82. return $this->get(EntityManagerInterface::class);
  83. }
  84. public function getRouter(): UrlGeneratorInterface
  85. {
  86. return $this->get(UrlGeneratorInterface::class);
  87. }
  88. public function getSession(): SessionInterface
  89. {
  90. return $this->get(SessionInterface::class);
  91. }
  92. public function getSecurity(): Security
  93. {
  94. return $this->get(Security::class);
  95. }
  96. public function getPaginator(): PaginatorInterface
  97. {
  98. return $this->get(PaginatorInterface::class);
  99. }
  100. public function getRequestStack(): RequestStack
  101. {
  102. return $this->get(RequestStack::class);
  103. }
  104. public function getEventDispatcher(): EventDispatcherInterface
  105. {
  106. return $this->get(EventDispatcherInterface::class);
  107. }
  108. public function getTranslator(): TranslatorInterface
  109. {
  110. return $this->get(TranslatorInterface::class);
  111. }
  112. public function getTranslatorAdmin(): TranslatorAdmin
  113. {
  114. return $this->get(TranslatorAdmin::class);
  115. }
  116. public function getLogger(): LoggerInterface
  117. {
  118. return $this->get(LoggerInterface::class);
  119. }
  120. public function getSettingSolver(): SettingSolver
  121. {
  122. return $this->get(SettingSolver::class);
  123. }
  124. public function getSettingValue($entity, $settingName)
  125. {
  126. return $this->getSettingSolver()->getSettingValue($entity, $settingName);
  127. }
  128. public function getComponentContainer(): ComponentContainer
  129. {
  130. return $this->get(ComponentContainer::class);
  131. }
  132. public function getFileContainer(): FileContainer
  133. {
  134. return $this->get(FileContainer::class);
  135. }
  136. public function getNewsletterContainer(): NewsletterContainer
  137. {
  138. return $this->get(NewsletterContainer::class);
  139. }
  140. public function getReminderContainer(): ReminderContainer
  141. {
  142. return $this->get(ReminderContainer::class);
  143. }
  144. public function getNewsContainer(): NewsContainer
  145. {
  146. return $this->get(NewsContainer::class);
  147. }
  148. public function getPageContainer(): PageContainer
  149. {
  150. return $this->get(PageContainer::class);
  151. }
  152. public function getSiteContainer(): SiteContainer
  153. {
  154. return $this->get(SiteContainer::class);
  155. }
  156. public function getTicketContainer(): TicketContainer
  157. {
  158. return $this->get(TicketContainer::class);
  159. }
  160. public function getTicketMessageContainer(): TicketMessageContainer
  161. {
  162. return $this->get(TicketMessageContainer::class);
  163. }
  164. public function getGroupUserContainer(): GroupUserContainer
  165. {
  166. return $this->get(GroupUserContainer::class);
  167. }
  168. public function getUserContainer(): UserContainer
  169. {
  170. return $this->get(UserContainer::class);
  171. }
  172. public function getSiteSettingContainer(): SiteSettingContainer
  173. {
  174. return $this->get(SiteSettingContainer::class);
  175. }
  176. }