Selaa lähdekoodia

Refactoring services

develop
Guillaume 3 vuotta sitten
vanhempi
commit
b2aaa53b57
21 muutettua tiedostoa jossa 82 lisäystä ja 93 poistoa
  1. +1
    -1
      Builder/Ticket/TicketBuilder.php
  2. +1
    -1
      Builder/User/UserBuilder.php
  3. +1
    -1
      Component/FormComponent.php
  4. +7
    -6
      Controller/AbstractAdminController.php
  5. +2
    -2
      Controller/Newsletter/NewsletterAdminController.php
  6. +9
    -8
      Controller/Reminder/ReminderAdminController.php
  7. +16
    -17
      Controller/Setting/SettingAdminController.php
  8. +2
    -2
      Controller/Site/NewsAdminController.php
  9. +2
    -2
      Controller/Site/PageAdminController.php
  10. +10
    -9
      Controller/Ticket/TicketAdminController.php
  11. +8
    -7
      Controller/User/AccountAdminController.php
  12. +2
    -2
      Controller/User/GroupUserAdminController.php
  13. +3
    -3
      Controller/User/UserAdminController.php
  14. +1
    -15
      Repository/Site/NewsStore.php
  15. +1
    -1
      Repository/Site/PageStore.php
  16. +4
    -4
      Repository/Ticket/TicketStore.php
  17. +1
    -1
      Repository/User/UserRepository.php
  18. +2
    -2
      Repository/User/UserRepositoryQuery.php
  19. +2
    -2
      Repository/User/UserStore.php
  20. +2
    -2
      Resolver/UrlResolver.php
  21. +5
    -5
      Translation/TranslatorAdmin.php

+ 1
- 1
Builder/Ticket/TicketBuilder.php Näytä tiedosto

@@ -17,7 +17,7 @@ class TicketBuilder
}

// uploadImageTicketMessage
public function uploadImageTicketMessage($formTicket)
public function uploadImageTicketMessage($formTicket): ?string
{
return $this->formComponent->uploadFile(
$formTicket,

+ 1
- 1
Builder/User/UserBuilder.php Näytä tiedosto

@@ -15,7 +15,7 @@ class UserBuilder
$this->entityManager = $entityManager;
}

public function setNewsletter(UserInterface $user, NewsletterInterface $newsletter, bool $subscribeNewsletter)
public function setNewsletter(UserInterface $user, NewsletterInterface $newsletter, bool $subscribeNewsletter): void
{
if ($subscribeNewsletter) {
$user->addNewsletter($newsletter);

+ 1
- 1
Component/FormComponent.php Näytä tiedosto

@@ -32,7 +32,7 @@ class FormComponent
}

// uploadImageTicketMessage
public function uploadFile($form, $child, $directory, $subdirectory)
public function uploadFile($form, $child, $directory, $subdirectory): ?string
{
$file = $form->get($child)->getData();


+ 7
- 6
Controller/AbstractAdminController.php Näytä tiedosto

@@ -64,6 +64,7 @@ use Symfony\Component\Form\Extension\Core\Type\DateTimeType;
use Symfony\Component\Form\Extension\Core\Type\DateType;
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
@@ -71,18 +72,18 @@ use Symfony\Component\HttpFoundation\Session\SessionInterface;

abstract class AbstractAdminController extends EaAbstractCrudController
{
protected $filtersForm;
protected FormInterface $filtersForm;

public static function getSubscribedServices()
{
return array_merge(
parent::getSubscribedServices(),
[
'session' => SessionInterface::class,
'request' => RequestStack::class,
'em' => EntityManagerInterface::class,
'translator_admin' => TranslatorAdmin::class,
'filter_manager' => FilterManager::class,
SessionInterface::class => SessionInterface::class,
RequestStack::class => RequestStack::class,
EntityManagerInterface::class => EntityManagerInterface::class,
TranslatorAdmin::class => TranslatorAdmin::class,
FilterManager::class => FilterManager::class,

FileContainer::class => FileContainer::class,
NewsletterContainer::class => NewsletterContainer::class,

+ 2
- 2
Controller/Newsletter/NewsletterAdminController.php Näytä tiedosto

@@ -4,6 +4,7 @@ namespace Lc\SovBundle\Controller\Newsletter;

use EasyCorp\Bundle\EasyAdminBundle\Field\FormField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
use Lc\SovBundle\Container\Newsletter\NewsletterContainer;
use Lc\SovBundle\Controller\AbstractAdminController;
use Lc\SovBundle\Factory\Newsletter\NewsletterFactory;
use Lc\SovBundle\Field\BooleanField;
@@ -31,8 +32,7 @@ abstract class NewsletterAdminController extends AbstractAdminController

public function createEntity(string $entityFqcn)
{
$factory = new NewsletterFactory();
return $factory->create();
return $this->get(NewsletterContainer::class)->getFactory()->create();
}

}

+ 9
- 8
Controller/Reminder/ReminderAdminController.php Näytä tiedosto

@@ -3,10 +3,11 @@
namespace Lc\SovBundle\Controller\Reminder;

use Doctrine\ORM\EntityManagerInterface;
use Lc\CaracoleBundle\Resolver\MerchantResolver;
use Lc\CaracoleBundle\Resolver\SectionResolver;
use Lc\SovBundle\Container\Reminder\ReminderContainer;
use Lc\SovBundle\Factory\Reminder\ReminderFactory;
use Lc\SovBundle\Factory\Reminder\ReminderFactoryInterface;
use Lc\SovBundle\Form\Reminder\ReminderAdminFormType;
use Lc\SovBundle\Repository\Reminder\ReminderRepositoryQueryInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\Form\FormFactoryInterface;
@@ -20,7 +21,7 @@ class ReminderAdminController extends AbstractController
{

protected EntityManagerInterface $entityManager;
protected ReminderRepositoryQueryInterface $reminderRepositoryQuery;
protected ReminderContainer $reminderContainer;
protected FormFactoryInterface $formFactory;
protected UrlGeneratorInterface $urlGenerator;
protected MerchantResolver $merchantResolver;
@@ -29,13 +30,13 @@ class ReminderAdminController extends AbstractController

public function __construct(
EntityManagerInterface $entityManager,
ReminderRepositoryQueryInterface $reminderRepositoryQuery,
ReminderContainer $reminderContainer,
FormFactoryInterface $formFactory,
UrlGeneratorInterface $urlGenerator,
ParameterBagInterface $parameterBag
) {
$this->entityManager = $entityManager;
$this->reminderRepositoryQuery = $reminderRepositoryQuery;
$this->reminderContainer = $reminderContainer;
$this->formFactory = $formFactory;
$this->urlGenerator = $urlGenerator;
$this->parameterBag = $parameterBag;
@@ -49,7 +50,7 @@ class ReminderAdminController extends AbstractController
$id = $request->get('id');

if($id) {
$reminder = $this->reminderRepositoryQuery->getRepository()->find($id);
$reminder = $this->reminderContainer->getRepositoryQuery()->getRepository()->find($id);
$action = $this->urlGenerator->generate(
$this->parameterBag->get('app.reminder.route_edit'),
['id' => $id]
@@ -108,7 +109,7 @@ class ReminderAdminController extends AbstractController
public function edit(Request $request)
{
$id = $request->get('id');
$reminder = $this->reminderRepositoryQuery->getRepository()->find($id);
$reminder = $this->reminderContainer->getRepositoryQuery()->getRepository()->find($id);

$form = $this->formFactory->create(ReminderAdminFormType::class, $reminder);
$form->handleRequest($request);
@@ -130,7 +131,7 @@ class ReminderAdminController extends AbstractController
public function done(Request $request): JsonResponse
{
$id = $request->get('id');
$reminder = $this->reminderRepositoryQuery->getRepository()->find($id);
$reminder = $this->reminderContainer->getRepositoryQuery()->getRepository()->find($id);
$done = $request->get('done');

if($done == 'true') {

+ 16
- 17
Controller/Setting/SettingAdminController.php Näytä tiedosto

@@ -3,6 +3,8 @@
namespace Lc\SovBundle\Controller\Setting;

use Doctrine\ORM\EntityManagerInterface;
use Lc\SovBundle\Container\Setting\SiteSettingContainer;
use Lc\SovBundle\Container\Site\SiteContainer;
use Lc\SovBundle\Definition\SiteSettingDefinitionInterface;
use Lc\SovBundle\Form\Setting\SiteSettingsFormType;
use Lc\SovBundle\Repository\Setting\SiteSettingRepository;
@@ -14,24 +16,21 @@ use Symfony\Component\Routing\Annotation\Route;

class SettingAdminController extends AbstractController
{
protected $em;
protected $translatorAdmin;
protected $siteSettingRepository;
protected $siteSettingDefinition;
protected $siteRepository;
protected EntityManagerInterface $entityManager;
protected TranslatorAdmin $translatorAdmin;
protected SiteSettingContainer $siteSettingContainer;
protected SiteContainer $siteContainer;

public function __construct(
EntityManagerInterface $em,
EntityManagerInterface $entityManager,
TranslatorAdmin $translatorAdmin,
SiteSettingRepository $siteSettingRepository,
SiteSettingDefinitionInterface $siteSettingDefinition,
SiteRepository $siteRepository
SiteSettingContainer $siteSettingContainer,
SiteContainer $siteContainer
) {
$this->em = $em;
$this->entityManager = $entityManager;
$this->translatorAdmin = $translatorAdmin;
$this->siteSettingRepository = $siteSettingRepository;
$this->siteSettingDefinition = $siteSettingDefinition;
$this->siteRepository = $siteRepository;
$this->siteSettingContainer = $siteSettingContainer;
$this->siteContainer = $siteContainer;
}

/**
@@ -39,15 +38,15 @@ class SettingAdminController extends AbstractController
*/
public function manageGlobal(Request $request)
{
$site = $this->siteRepository->findOneByDevAlias('default') ;
$site = $this->siteContainer->getRepositoryQuery()->getRepository()->findOneByDevAlias('default') ;
$form = $this->createForm(SiteSettingsFormType::class, $site);

$form->handleRequest($request);

if ($form->isSubmitted() && $form->isValid()) {

$this->em->update($site);
$this->em->flush();
$this->entityManager->update($site);
$this->entityManager->flush();

$this->addFlash('success', $this->translatorAdmin->transFlashMessage('settings_saved'));
}
@@ -55,7 +54,7 @@ class SettingAdminController extends AbstractController
return $this->render(
'@LcSov/admin/setting/edit_site.html.twig' ,
[
'setting_definition' => $this->siteSettingDefinition,
'setting_definition' => $this->siteSettingContainer->getDefinition(),
'form' => $form->createView()
]
);

+ 2
- 2
Controller/Site/NewsAdminController.php Näytä tiedosto

@@ -6,6 +6,7 @@ use EasyCorp\Bundle\EasyAdminBundle\Field\DateField;
use EasyCorp\Bundle\EasyAdminBundle\Field\FormField;
use EasyCorp\Bundle\EasyAdminBundle\Field\NumberField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
use Lc\SovBundle\Container\Site\NewsContainer;
use Lc\SovBundle\Controller\AbstractAdminController;
use Lc\SovBundle\Factory\Site\NewsFactory;
use Lc\SovBundle\Field\CKEditorField;
@@ -36,7 +37,6 @@ abstract class NewsAdminController extends AbstractAdminController

public function createEntity(string $entityFqcn)
{
$factory = new NewsFactory();
return $factory->create();
return $this->get(NewsContainer::class)->getFactory()->create();
}
}

+ 2
- 2
Controller/Site/PageAdminController.php Näytä tiedosto

@@ -5,6 +5,7 @@ namespace Lc\SovBundle\Controller\Site;
use EasyCorp\Bundle\EasyAdminBundle\Field\FormField;
use EasyCorp\Bundle\EasyAdminBundle\Field\NumberField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
use Lc\SovBundle\Container\Site\PageContainer;
use Lc\SovBundle\Controller\AbstractAdminController;
use Lc\SovBundle\Factory\Site\PageFactory;
use Lc\SovBundle\Field\CKEditorField;
@@ -33,8 +34,7 @@ abstract class PageAdminController extends AbstractAdminController

public function createEntity(string $entityFqcn)
{
$factory = new PageFactory();
return $factory->create();
return $this->get(PageContainer::class)->getFactory()->create();
}

}

+ 10
- 9
Controller/Ticket/TicketAdminController.php Näytä tiedosto

@@ -2,6 +2,7 @@

namespace Lc\SovBundle\Controller\Ticket;

use Doctrine\ORM\EntityManagerInterface;
use EasyCorp\Bundle\EasyAdminBundle\Config\Action;
use EasyCorp\Bundle\EasyAdminBundle\Config\Actions;
use EasyCorp\Bundle\EasyAdminBundle\Config\Assets;
@@ -13,6 +14,7 @@ use EasyCorp\Bundle\EasyAdminBundle\Field\DateField;
use EasyCorp\Bundle\EasyAdminBundle\Field\IntegerField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGenerator;
use Lc\SovBundle\Container\Ticket\TicketContainer;
use Lc\SovBundle\Factory\Ticket\TicketFactory;
use Lc\SovBundle\Factory\Ticket\TicketFactoryInterface;
use Lc\SovBundle\Factory\Ticket\TicketMessageFactory;
@@ -25,6 +27,7 @@ use Lc\SovBundle\Controller\AbstractAdminController;
use Lc\SovBundle\Model\Ticket\TicketModel;
use Lc\SovBundle\Translation\TranslatorAdmin;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\RequestStack;

class TicketAdminController extends AbstractAdminController
{
@@ -36,8 +39,7 @@ class TicketAdminController extends AbstractAdminController

public function createEntity(string $entityFqcn)
{
$factory = new TicketFactory();
return $factory->create();
return $this->get(TicketContainer::class)->getFactory()->create();
}

public function configureAssets(Assets $assets): Assets
@@ -106,8 +108,8 @@ class TicketAdminController extends AbstractAdminController
if ($form->isSubmitted() && $form->isValid()) {
$ticket = $form->getData();

$this->get('em')->persist($ticket);
$this->get('em')->flush();
$this->get(EntityManagerInterface::class)->create($ticket);
$this->get(EntityManagerInterface::class)->flush();

$url = $adminUrlGenerator
->setAction('index')
@@ -142,17 +144,16 @@ class TicketAdminController extends AbstractAdminController
]
);

$ticketMessageFactory = new TicketMessageFactory();
$ticketMessage = $ticketMessageFactory->create();
$ticketMessage = $this->get(TicketContainer::class)->getFactory()->create();
$formAddTicketMessage = $this->createForm(TicketMessageFormType::class, $ticketMessage);
$formAddTicketMessage->handleRequest($this->get('request')->getMasterRequest());
$formAddTicketMessage->handleRequest($this->get(RequestStack::class)->getMainRequest());

if ($formAddTicketMessage->isSubmitted() && $formAddTicketMessage->isValid()) {
$ticketMessage = $formAddTicketMessage->getData();
$ticketMessage->setTicket($ticket);
$ticketMessage->setAnswerByAdmin(true);
$this->get('em')->persist($ticketMessage);
$this->get('em')->flush();
$this->get(EntityManagerInterface::class)->create($ticketMessage);
$this->get(EntityManagerInterface::class)->flush();
}

return $this->render(

+ 8
- 7
Controller/User/AccountAdminController.php Näytä tiedosto

@@ -2,6 +2,7 @@

namespace Lc\SovBundle\Controller\User;

use Doctrine\ORM\EntityManagerInterface;
use Lc\SovBundle\Doctrine\EntityManager;
use Lc\SovBundle\Form\User\ChangePasswordFormType;
use Lc\SovBundle\Form\User\ProfileFormType;
@@ -15,11 +16,11 @@ use Symfony\Component\Routing\Annotation\Route;

class AccountAdminController extends AbstractController
{
protected $em;
protected EntityManagerInterface $entityManager;

public function __construct(EntityManager $em)
public function __construct(EntityManagerInterface $entityManager)
{
$this->em = $em;
$this->entityManager = $entityManager;
}

/**
@@ -36,8 +37,8 @@ class AccountAdminController extends AbstractController
if ($form->isSubmitted() && $form->isValid()) {
$user = $form->getData();

$this->em->update($user);
$this->em->flush();
$this->entityManager->update($user);
$this->entityManager->flush();

$this->addFlash('success', new TranslatableMessage('form.account_profile.message.success', [], 'admin'));
}
@@ -67,8 +68,8 @@ class AccountAdminController extends AbstractController

$user->setPassword($passwordEncoder->encodePassword($user, $plainPassword));

$this->em->update($user);
$this->em->flush();
$this->entityManager->update($user);
$this->entityManager->flush();

$this->addFlash('success', new TranslatableMessage('form.account_password.message.success', [], 'admin'));
}

+ 2
- 2
Controller/User/GroupUserAdminController.php Näytä tiedosto

@@ -3,6 +3,7 @@
namespace Lc\SovBundle\Controller\User;

use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
use Lc\SovBundle\Container\User\GroupUserContainer;
use Lc\SovBundle\Controller\AbstractAdminController;
use Lc\SovBundle\Factory\User\GroupUserFactory;

@@ -19,7 +20,6 @@ abstract class GroupUserAdminController extends AbstractAdminController

public function createEntity(string $entityFqcn)
{
$factory = new GroupUserFactory();
return $factory->create();
return $this->get(GroupUserContainer::class)->getFactory()->create();
}
}

+ 3
- 3
Controller/User/UserAdminController.php Näytä tiedosto

@@ -5,6 +5,7 @@ namespace Lc\SovBundle\Controller\User;
use EasyCorp\Bundle\EasyAdminBundle\Field\ChoiceField;
use EasyCorp\Bundle\EasyAdminBundle\Field\EmailField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
use Lc\SovBundle\Container\User\UserContainer;
use Lc\SovBundle\Controller\AbstractAdminController;
use Lc\SovBundle\Definition\RolesDefinition;
use Lc\SovBundle\Definition\RolesDefinitionInterface;
@@ -16,7 +17,7 @@ use Symfony\Component\HttpFoundation\Session\SessionInterface;

abstract class UserAdminController extends AbstractAdminController
{
protected $rolesDefinition;
protected RolesDefinitionInterface $rolesDefinition;

public function __construct(
SessionInterface $session,
@@ -44,7 +45,6 @@ abstract class UserAdminController extends AbstractAdminController

public function createEntity(string $entityFqcn)
{
$factory = new UserFactory();
return $factory->create();
return $this->get(UserContainer::class)->getFactory()->create();
}
}

+ 1
- 15
Repository/Site/NewsStore.php Näytä tiedosto

@@ -13,7 +13,7 @@ class NewsStore extends AbstractStore implements NewsStoreInterface
$this->query = $query;
}

//findLatests
//findLatests
public function getLatests(int $maxResults = 0, $query = null): array
{
if (is_null($query)) {
@@ -30,18 +30,4 @@ class NewsStore extends AbstractStore implements NewsStoreInterface

return $query->find();
}

public function findLatests($maxResults = 0)
{
$result = $this->findByMerchantQuery()
->orderBy('e.date', 'DESC');

$result->andWhere('e.status = 1');

if ($maxResults) {
$result->setMaxResults($maxResults);
}

return $result->getQuery()->getResult();
}
}

+ 1
- 1
Repository/Site/PageStore.php Näytä tiedosto

@@ -14,7 +14,7 @@ class PageStore extends AbstractStore implements PageStoreInterface
$this->query = $query;
}

//findPageBySlug
//findPageBySlug
public function getBySlug(string $slug): ?PageInterface
{
$query = $this->query->create();

+ 4
- 4
Repository/Ticket/TicketStore.php Näytä tiedosto

@@ -27,8 +27,8 @@ class TicketStore extends AbstractStore implements TicketStoreInterface
return $query->find();
}

// findAllOpen
public function getAllOpen(int $limit = 0, $query = null): array
// findAllOpen
public function getOpen(int $limit = 0, $query = null): array
{
if (is_null($query)) {
$query = $this->query->create();
@@ -42,8 +42,8 @@ class TicketStore extends AbstractStore implements TicketStoreInterface
return $query->find();
}

//countAllOpen
public function countAllOpen($query = null): string
// countAllOpen
public function countOpen($query = null): string
{
if (is_null($query)) {
$query = $this->query->create();

+ 1
- 1
Repository/User/UserRepository.php Näytä tiedosto

@@ -25,7 +25,7 @@ class UserRepository extends AbstractRepository
}

$user->setPassword($newEncodedPassword);
$this->_em->persist($user);
$this->_em->update($user);
$this->_em->flush();
}


+ 2
- 2
Repository/User/UserRepositoryQuery.php Näytä tiedosto

@@ -21,14 +21,14 @@ class UserRepositoryQuery extends AbstractRepositoryQuery implements UserReposit
->setParameter('newsletter', $newsletter->getId());
}

public function filterLikeRole(string $role): self
public function filterByRole(string $role): self
{
return $this
->andWhere('.roles LIKE :roles')
->setParameter('roles', '%"' . $role . '"%');
}

public function filterLikeTicketTypeNotification(string $ticketType): self
public function filterByTicketTypeNotification(string $ticketType): self
{
return $this
->andWhere('.ticketTypesNotification LIKE :ticketType')

+ 2
- 2
Repository/User/UserStore.php Näytä tiedosto

@@ -32,7 +32,7 @@ class UserStore extends AbstractStore implements UserStoreInterface
{
$query = $this->query->create();
$query
->filterLikeRole($role);
->filterByRole($role);

return $query->find();
}
@@ -42,7 +42,7 @@ class UserStore extends AbstractStore implements UserStoreInterface
{
$query = $this->query->create();
$query
->filterLikeTicketTypeNotification($ticketType);
->filterByTicketTypeNotification($ticketType);

return $query->find();
}

+ 2
- 2
Resolver/UrlResolver.php Näytä tiedosto

@@ -18,12 +18,12 @@ class UrlResolver
$this->parameterBag = $parameterBag;
}

public function isServerLocalhost()
public function isServerLocalhost(): bool
{
return in_array($_SERVER['REMOTE_ADDR'], ['127.0.0.1', '::1']);
}

public function isBot()
public function isBot(): bool
{
if (isset($_SERVER['HTTP_USER_AGENT']) && preg_match(
'/bot|crawl|slurp|spider/i',

+ 5
- 5
Translation/TranslatorAdmin.php Näytä tiedosto

@@ -7,7 +7,7 @@ use Symfony\Contracts\Translation\TranslatorInterface;

class TranslatorAdmin
{
protected $translator;
protected TranslatorInterface $translator;

const DOMAIN = 'admin';

@@ -16,17 +16,17 @@ class TranslatorAdmin
$this->translator = $translator;
}

public function transAction($action)
public function transAction($action): string
{
return $this->trans('action.' . $action);
}

public function transMenu($menu)
public function transMenu($menu): string
{
return $this->trans('menu.' . $menu);
}

public function transFlashMessage($name, $params = [])
public function transFlashMessage($name, $params = []): string
{
return $this->trans('flash_message.' . $name, $params);
}
@@ -68,7 +68,7 @@ class TranslatorAdmin
);
}

public function transTitle($pageName, $entityClass = null, $params = [])
public function transTitle($pageName, $entityClass = null, $params = []): string
{
$entityName = $this->getEntityName($entityClass);


Loading…
Peruuta
Tallenna