瀏覽代碼

Refactoring services

develop
Guillaume 3 年之前
父節點
當前提交
84d0849846
共有 12 個檔案被更改,包括 93 行新增71 行删除
  1. +10
    -1
      Container/Setting/SiteSettingContainer.php
  2. +10
    -1
      Container/Ticket/TicketContainer.php
  3. +1
    -2
      Controller/AbstractAdminController.php
  4. +6
    -0
      Controller/Setting/SettingAdminController.php
  5. +2
    -2
      Controller/Ticket/TicketAdminController.php
  6. +23
    -18
      EventSubscriber/SiteSettingEventSubscriber.php
  7. +0
    -35
      Model/Setting/EntitySettingTrait.php
  8. +2
    -2
      Model/Site/NewsModel.php
  9. +0
    -2
      Model/Site/SiteModel.php
  10. +9
    -4
      Repository/AbstractStore.php
  11. +1
    -1
      Repository/StoreInterface.php
  12. +29
    -3
      Solver/Setting/SettingSolver.php

+ 10
- 1
Container/Setting/SiteSettingContainer.php 查看文件

@@ -6,6 +6,7 @@ use Lc\SovBundle\Definition\SiteSettingDefinition;
use Lc\SovBundle\Factory\Setting\SiteSettingFactory;
use Lc\SovBundle\Repository\Setting\SiteSettingRepositoryQuery;
use Lc\SovBundle\Repository\Setting\SiteSettingStore;
use Lc\SovBundle\Solver\Setting\SettingSolver;

class SiteSettingContainer
{
@@ -13,17 +14,20 @@ class SiteSettingContainer
protected SiteSettingDefinition $definition;
protected SiteSettingRepositoryQuery $repositoryQuery;
protected SiteSettingStore $store;
protected SettingSolver $settingSolver;

public function __construct(
SiteSettingFactory $factory,
SiteSettingDefinition $definition,
SiteSettingRepositoryQuery $repositoryQuery,
SiteSettingStore $store
SiteSettingStore $store,
SettingSolver $settingSolver
) {
$this->factory = $factory;
$this->definition = $definition;
$this->repositoryQuery = $repositoryQuery;
$this->store = $store;
$this->settingSolver = $settingSolver;
}

public function getFactory(): SiteSettingFactory
@@ -45,4 +49,9 @@ class SiteSettingContainer
{
return $this->store;
}

public function getSettingSolver(): SettingSolver
{
return $this->settingSolver;
}
}

+ 10
- 1
Container/Ticket/TicketContainer.php 查看文件

@@ -6,6 +6,7 @@ use Lc\SovBundle\Builder\Ticket\TicketBuilder;
use Lc\SovBundle\Factory\Ticket\TicketFactory;
use Lc\SovBundle\Repository\Ticket\TicketRepositoryQuery;
use Lc\SovBundle\Repository\Ticket\TicketStore;
use Lc\SovBundle\Solver\Ticket\TicketSolver;

class TicketContainer
{
@@ -13,17 +14,20 @@ class TicketContainer
protected TicketBuilder $builder;
protected TicketRepositoryQuery $repositoryQuery;
protected TicketStore $store;
protected TicketSolver $solver;

public function __construct(
TicketFactory $factory,
TicketBuilder $builder,
TicketRepositoryQuery $repositoryQuery,
TicketStore $store
TicketStore $store,
TicketSolver $solver
) {
$this->factory = $factory;
$this->builder = $builder;
$this->repositoryQuery = $repositoryQuery;
$this->store = $store;
$this->solver = $solver;
}

public function getFactory(): TicketFactory
@@ -45,4 +49,9 @@ class TicketContainer
{
return $this->store;
}

public function getSolver(): TicketSolver
{
return $this->solver;
}
}

+ 1
- 2
Controller/AbstractAdminController.php 查看文件

@@ -84,7 +84,6 @@ abstract class AbstractAdminController extends EaAbstractCrudController
RequestStack::class => RequestStack::class,
EntityManagerInterface::class => EntityManagerInterface::class,
FilterManager::class => FilterManager::class,

FileContainer::class => FileContainer::class,
NewsletterContainer::class => NewsletterContainer::class,
ReminderContainer::class => ReminderContainer::class,
@@ -429,7 +428,7 @@ abstract class AbstractAdminController extends EaAbstractCrudController
$context = $this->get(AdminContextProvider::class)->getContext();

return $context->getCrudControllers()->findCrudFqcnByEntityFqcn(
$this->get('em')->getEntityName($interface)
$this->get(EntityManagerInterface::class)->getEntityName($interface)
);
}


+ 6
- 0
Controller/Setting/SettingAdminController.php 查看文件

@@ -16,6 +16,12 @@ use Symfony\Component\Routing\Annotation\Route;

class SettingAdminController extends AbstractController
{
protected EntityManagerInterface $entityManager;

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

/**
* @Route("/admin/setting/site", name="sov_admin_setting_site")

+ 2
- 2
Controller/Ticket/TicketAdminController.php 查看文件

@@ -74,12 +74,12 @@ class TicketAdminController extends AbstractAdminController
ChoiceField::new('type')
->autocomplete()
->setChoices(
$translatorAdmin->transChoices(TicketModel::getTypeChoices(), 'Ticket', 'type')
$translatorAdmin->transChoices($this->get(TicketContainer::class)->getSolver()->getTypeChoices(), 'Ticket', 'type')
),
ChoiceField::new('status')
->autocomplete()
->setChoices(
$translatorAdmin->transChoices(TicketModel::getStatusChoices(), 'Ticket', 'status')
$translatorAdmin->transChoices($this->get(TicketContainer::class)->getSolver()->getStatusChoices(), 'Ticket', 'status')

)
->setTemplatePath('@LcSov/admin/ticket/field/status.html.twig')

+ 23
- 18
EventSubscriber/SiteSettingEventSubscriber.php 查看文件

@@ -8,32 +8,37 @@ use Lc\SovBundle\Factory\Setting\SiteSettingFactory;
use Lc\SovBundle\Factory\Site\SiteFactory;
use Lc\SovBundle\Repository\Setting\SiteSettingRepository;
use Lc\SovBundle\Repository\Site\SiteRepository;
use Lc\SovBundle\Repository\Site\SiteStore;
use Lc\SovBundle\Solver\Setting\SettingSolver;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\KernelEvents;

class SiteSettingEventSubscriber implements EventSubscriberInterface
{
protected $em;
protected $siteSettingDefinition;
protected $siteSettingFactory;
protected $siteSettingRepository;
protected $siteRepository;
protected $siteFactory;
protected EntityManagerInterface $entityManager;
protected SiteSettingDefinitionInterface $siteSettingDefinition;
protected SiteSettingFactory $siteSettingFactory;
protected SiteSettingRepository $siteSettingRepository;
protected SiteStore $siteStore;
protected SiteFactory $siteFactory;
protected SettingSolver $settingSolver;

public function __construct(
EntityManagerInterface $em,
EntityManagerInterface $entityManager,
SiteSettingRepository $siteSettingRepository,
SiteRepository $siteRepository,
SiteStore $siteStore,
SiteSettingDefinitionInterface $siteSettingDefinition,
SiteSettingFactory $siteSettingFactory,
SiteFactory $siteFactory
SiteFactory $siteFactory,
SettingSolver $settingSolver
) {
$this->em = $em;
$this->entityManager = $entityManager;
$this->siteSettingDefinition = $siteSettingDefinition;
$this->siteSettingFactory = $siteSettingFactory;
$this->siteSettingRepository = $siteSettingRepository;
$this->siteRepository = $siteRepository;
$this->siteStore = $siteStore;
$this->siteFactory = $siteFactory;
$this->settingSolver = $settingSolver;
}

public static function getSubscribedEvents()
@@ -48,8 +53,8 @@ class SiteSettingEventSubscriber implements EventSubscriberInterface
$site = $this->getSiteDefault();
if (!$site) {
$site = $this->siteFactory->create('default');
$this->em->persist($site);
$this->em->flush($site);
$this->entityManager->persist($site);
$this->entityManager->flush($site);
}

$settings = $this->siteSettingDefinition->getSettings();
@@ -57,7 +62,7 @@ class SiteSettingEventSubscriber implements EventSubscriberInterface

foreach ($settings as $category => $settingList) {
foreach ($settingList as $settingName => $setting) {
$entitySetting = $site->getSetting($settingName);
$entitySetting = $this->settingSolver->getSetting($site, $settingName);

if (!$entitySetting) {

@@ -79,7 +84,7 @@ class SiteSettingEventSubscriber implements EventSubscriberInterface

$entitySetting = $factory->create($site, $setting['name'], $text, $date, $file);

$this->em->persist($entitySetting);
$this->entityManager->persist($entitySetting);
} else {
$methodGetValue = 'get' . ucfirst($setting['field']);
if ($entitySetting->$methodGetValue() === null
@@ -87,18 +92,18 @@ class SiteSettingEventSubscriber implements EventSubscriberInterface
&& $setting['default'] !== null) {
$methodSetValue = 'set' . ucfirst($setting['field']);
$entitySetting->$methodSetValue($setting['default']);
$this->em->update($entitySetting);
$this->entityManager->update($entitySetting);
}
}
}
}

$this->em->flush();
$this->entityManager->flush();
}

public function getSiteDefault()
{
return $this->siteRepository->findOneByDevAlias('default');
return $this->siteStore->getOneByDevAlias('default');
}

}

+ 0
- 35
Model/Setting/EntitySettingTrait.php 查看文件

@@ -1,35 +0,0 @@
<?php

namespace Lc\SovBundle\Model\Setting;

//TODO à déplacer dans un solver

trait EntitySettingTrait
{
public function getSetting($name): ?SettingModel
{
if ($this->getSettings()) {
foreach ($this->getSettings() as $setting) {
if ($setting->getName() == $name) {
return $setting;
}
}
}

return null;
}

public function getSettingValue($name): ?string
{
if ($this->getSettings()) {
foreach ($this->getSettings() as $setting) {
if ($setting->getName() == $name) {
return $setting->getValue();
}
}
}

return null;
}

}

+ 2
- 2
Model/Site/NewsModel.php 查看文件

@@ -27,12 +27,12 @@ abstract class NewsModel extends AbstractFullEntity implements NewsInterface


/**
* @ORM\ManyToOne(targetEntity="Lc\SovBundle\Newsletter\NewsletterInsterface", inversedBy="news")
* @ORM\ManyToOne(targetEntity="Lc\SovBundle\Model\Newsletter\NewsletterInterface", inversedBy="news")
*/
protected $newsletter;

/**
* @ORM\ManyToOne(targetEntity="Lc\SovBundle\File\FileInsterface", cascade={"persist", "remove"})
* @ORM\ManyToOne(targetEntity="Lc\SovBundle\Model\File\FileInterface", cascade={"persist", "remove"})
*/
protected $image;


+ 0
- 2
Model/Site/SiteModel.php 查看文件

@@ -5,7 +5,6 @@ namespace Lc\SovBundle\Model\Site;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Lc\SovBundle\Model\Setting\EntitySettingTrait;
use Lc\SovBundle\Model\Setting\SiteSettingInterface;
use Lc\SovBundle\Doctrine\EntityInterface;
use Lc\SovBundle\Doctrine\Extension\DevAliasInterface;
@@ -13,7 +12,6 @@ use Lc\SovBundle\Doctrine\Extension\DevAliasTrait;

abstract class SiteModel implements SiteInterface, EntityInterface, DevAliasInterface
{
use EntitySettingTrait;
use DevAliasTrait;

/**

+ 9
- 4
Repository/AbstractStore.php 查看文件

@@ -67,14 +67,19 @@ abstract class AbstractStore implements StoreInterface
return $query->findOne();
}

public function getOneByDevAlias(string $devAlias, bool $isOnline = true, $query = null)
public function getOneByDevAlias(string $devAlias, $query = null)
{
$query = $this->createDefaultQuery($query);
$query->filterByDevAlias($devAlias);
return $query->findOne();
}

if ($isOnline) {
$query->filterIsOnline();
}
public function getOneOnlineByDevAlias(string $devAlias, $query = null)
{
$query = $this->createDefaultQuery($query);
$query
->filterByDevAlias($devAlias)
->filterIsOnline();

return $query->findOne();
}

+ 1
- 1
Repository/StoreInterface.php 查看文件

@@ -20,7 +20,7 @@ interface StoreInterface

public function getOneBySlug(string $slug, bool $isOnline = true, $query = null);

public function getOneByDevAlias(string $devAlias, bool $isOnline = true, $query = null);
public function getOneByDevAlias(string $devAlias, $query = null);

public function get($query = null);


+ 29
- 3
Solver/Setting/SettingSolver.php 查看文件

@@ -2,13 +2,37 @@

namespace Lc\SovBundle\Solver\Setting;

use Lc\SovBundle\Doctrine\EntityInterface;
use Lc\SovBundle\Model\Setting\SettingInterface;
use Lc\SovBundle\Model\Ticket\TicketInterface;
use Lc\SovBundle\Model\Ticket\TicketModel;
use Lc\SovBundle\Model\Setting\SettingModel;

class SettingSolver
{
public function getValue(SettingInterface $setting)
public function getSetting(EntityInterface $entity, string $name): ?SettingModel
{
if ($entity->getSettings()) {
foreach ($entity->getSettings() as $setting) {
if ($setting->getName() == $name) {
return $setting;
}
}
}

return null;
}

public function getSettingValue(EntityInterface $entity, string $name): ?string
{
$setting = $this->getSetting($entity, $name);

if($setting) {
return $this->getValue($setting);
}

return null;
}

public function getValue(SettingInterface $setting): ?string
{
if ($setting->getText()) {
return $setting->getText();
@@ -17,5 +41,7 @@ class SettingSolver
} elseif ($setting->getFile()) {
return $setting->getFile();
}

return null;
}
}

Loading…
取消
儲存