|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277 |
- <?php
-
- namespace Lc\SovBundle\Controller;
-
- use Doctrine\ORM\EntityManagerInterface;
- use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGenerator;
- use Knp\Component\Pager\PaginatorInterface;
- use Lc\SovBundle\Component\FileComponent;
- use Lc\SovBundle\Container\ComponentContainer;
- use Lc\SovBundle\Container\File\FileContainer;
- use Lc\SovBundle\Container\Newsletter\NewsletterContainer;
- use Lc\SovBundle\Container\Reminder\ReminderContainer;
- use Lc\SovBundle\Container\Setting\SiteSettingContainer;
- use Lc\SovBundle\Container\Site\NewsContainer;
- use Lc\SovBundle\Container\Site\PageContainer;
- use Lc\SovBundle\Container\Site\SiteContainer;
- use Lc\SovBundle\Container\Ticket\TicketContainer;
- use Lc\SovBundle\Container\Ticket\TicketMessageContainer;
- use Lc\SovBundle\Container\User\GroupUserContainer;
- use Lc\SovBundle\Container\User\UserContainer;
- use Lc\SovBundle\Field\Filter\FilterManager;
- use Lc\SovBundle\Generator\PdfGenerator;
- use Lc\SovBundle\Repository\EntityRepository;
- use Lc\SovBundle\Solver\Setting\SettingSolver;
- use Lc\SovBundle\Translation\FlashBagTranslator;
- use Lc\SovBundle\Translation\TranslatorAdmin;
- use Mailjet\MailjetSwiftMailer\SwiftMailer\MailjetTransport;
- use Psr\Log\LoggerInterface;
- use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
- use Symfony\Component\EventDispatcher\EventDispatcherInterface;
- use Symfony\Component\HttpFoundation\Request;
- use Symfony\Component\HttpFoundation\RequestStack;
- use Symfony\Component\HttpFoundation\Session\SessionInterface;
- use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
- use Symfony\Component\Security\Core\Security;
- use Symfony\Contracts\Translation\TranslatorInterface;
- use Twig\Environment;
-
- trait ControllerTrait
- {
- public static function getSubscribedServices()
- {
- return array_merge(
- parent::getSubscribedServices(),
- [
- Environment::class => Environment::class,
- Security::class => Security::class,
- EntityManagerInterface::class => EntityManagerInterface::class,
- UrlGeneratorInterface::class => UrlGeneratorInterface::class,
- SessionInterface::class => SessionInterface::class,
- PaginatorInterface::class => PaginatorInterface::class,
- RequestStack::class => RequestStack::class,
- EventDispatcherInterface::class => EventDispatcherInterface::class,
- LoggerInterface::class => LoggerInterface::class,
- ParameterBagInterface::class => ParameterBagInterface::class,
- TranslatorInterface::class => TranslatorInterface::class,
- PdfGenerator::class => PdfGenerator::class,
- TranslatorAdmin::class => TranslatorAdmin::class,
- FilterManager::class => FilterManager::class,
- FlashBagTranslator::class => FlashBagTranslator::class,
- MailjetTransport::class => MailjetTransport::class,
- AdminUrlGenerator::class => AdminUrlGenerator::class,
- SettingSolver::class => SettingSolver::class,
- ComponentContainer::class => ComponentContainer::class,
- FileContainer::class => FileContainer::class,
- NewsletterContainer::class => NewsletterContainer::class,
- ReminderContainer::class => ReminderContainer::class,
- NewsContainer::class => NewsContainer::class,
- PageContainer::class => PageContainer::class,
- SiteContainer::class => SiteContainer::class,
- TicketContainer::class => TicketContainer::class,
- TicketMessageContainer::class => TicketMessageContainer::class,
- GroupUserContainer::class => GroupUserContainer::class,
- UserContainer::class => UserContainer::class,
- SiteSettingContainer::class => SiteSettingContainer::class,
- EntityRepository::class => EntityRepository::class,
- FileComponent::class => FileComponent::class,
- ]
- );
- }
-
- public function addFlashTranslator(
- string $type,
- $translationKeyName,
- $translationEntityName = null,
- $translationParam = array()
- ): void
- {
- if ($translationEntityName === null && method_exists($this, 'getTranslationEntityName')) {
- $translationEntityName = $this->getTranslationEntityName();
- }
-
-
- $this->get(FlashBagTranslator::class)->add(
- $type,
- $translationKeyName,
- $translationEntityName,
- $translationParam
- );
- }
-
- public function isInstanceOf(string $interfaceName): bool
- {
- return in_array($interfaceName, class_implements($this->getEntityFqcn()));
- }
-
- public function generateEaUrl(string $controller = null, string $action = null, int $entityId = null, array $extraParam = array()): string
- {
- $adminUrlGenerator = $this->get(AdminUrlGenerator::class);
- if ($controller) {
- $adminUrlGenerator->setController($controller);
- }
- if ($action) {
- $adminUrlGenerator->setAction($action);
- }
- if ($entityId) {
- $adminUrlGenerator->setEntityId($entityId);
- }
- if ($extraParam) {
- foreach ($extraParam as $key => $value) {
- $adminUrlGenerator->set($key, $value);
- }
- }
- return $adminUrlGenerator->generateUrl();
- }
-
- public function getReferer(Request $request): ?string
- {
- return $request->headers->get('referer');
- }
-
- public function getTemplating(): Environment
- {
- return $this->get(Environment::class);
- }
-
- public function getEntityManager(): EntityManagerInterface
- {
- return $this->get(EntityManagerInterface::class);
- }
-
- public function getRouter(): UrlGeneratorInterface
- {
- return $this->get(UrlGeneratorInterface::class);
- }
-
- public function getSession(): SessionInterface
- {
- return $this->get(SessionInterface::class);
- }
-
- public function getSecurity(): Security
- {
- return $this->get(Security::class);
- }
-
- public function getPaginator(): PaginatorInterface
- {
- return $this->get(PaginatorInterface::class);
- }
-
- public function getRequestStack(): RequestStack
- {
- return $this->get(RequestStack::class);
- }
-
- public function getEventDispatcher(): EventDispatcherInterface
- {
- return $this->get(EventDispatcherInterface::class);
- }
-
- public function getParameterBag(): ParameterBagInterface
- {
- return $this->get(ParameterBagInterface::class);
- }
-
- public function getTranslator(): TranslatorInterface
- {
- return $this->get(TranslatorInterface::class);
- }
-
- public function getPdfGenerator(): PdfGenerator
- {
- return $this->get(PdfGenerator::class);
- }
-
- public function getTranslatorAdmin(): TranslatorAdmin
- {
- return $this->get(TranslatorAdmin::class);
- }
-
- public function getLogger(): LoggerInterface
- {
- return $this->get(LoggerInterface::class);
- }
-
- public function getMailjetTransport(): MailjetTransport
- {
- return $this->get(MailjetTransport::class);
- }
-
- public function getAdminUrlGenerator(): AdminUrlGenerator
- {
- return $this->get(AdminUrlGenerator::class);
- }
-
- public function getSettingSolver(): SettingSolver
- {
- return $this->get(SettingSolver::class);
- }
-
- public function getSettingValue($entity, $settingName)
- {
- return $this->getSettingSolver()->getSettingValue($entity, $settingName);
- }
-
- public function getComponentContainer(): ComponentContainer
- {
- return $this->get(ComponentContainer::class);
- }
-
- public function getFileContainer(): FileContainer
- {
- return $this->get(FileContainer::class);
- }
-
- public function getNewsletterContainer(): NewsletterContainer
- {
- return $this->get(NewsletterContainer::class);
- }
-
- public function getReminderContainer(): ReminderContainer
- {
- return $this->get(ReminderContainer::class);
- }
-
- public function getNewsContainer(): NewsContainer
- {
- return $this->get(NewsContainer::class);
- }
-
- public function getPageContainer(): PageContainer
- {
- return $this->get(PageContainer::class);
- }
-
- public function getSiteContainer(): SiteContainer
- {
- return $this->get(SiteContainer::class);
- }
-
- public function getTicketContainer(): TicketContainer
- {
- return $this->get(TicketContainer::class);
- }
-
- public function getTicketMessageContainer(): TicketMessageContainer
- {
- return $this->get(TicketMessageContainer::class);
- }
-
- public function getGroupUserContainer(): GroupUserContainer
- {
- return $this->get(GroupUserContainer::class);
- }
-
- public function getUserContainer(): UserContainer
- {
- return $this->get(UserContainer::class);
- }
-
- public function getSiteSettingContainer(): SiteSettingContainer
- {
- return $this->get(SiteSettingContainer::class);
- }
-
- }
|