Fix DI on other services depending on updated repositories.

This commit is contained in:
Pol Dellaiera
2021-06-11 21:07:16 +02:00
parent 81e8a4562b
commit 92b4adc113
15 changed files with 113 additions and 215 deletions

View File

@@ -19,26 +19,18 @@
namespace Chill\MainBundle\Form\Type\DataTransformer;
use Chill\MainBundle\Entity\Center;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Form\DataTransformerInterface;
use Doctrine\Persistence\ObjectManager;
use Symfony\Component\Form\Exception\TransformationFailedException;
/**
* Transform a center object to his id, and vice-versa
*
* @author Julien Fastré <julien.fastre@champs-libres.coop>
*/
class CenterTransformer implements DataTransformerInterface
{
/**
*
* @var ObjectManager
*/
private $om;
public function __construct(ObjectManager $om)
private EntityManagerInterface $em;
public function __construct(EntityManagerInterface $em)
{
$this->om = $om;
$this->em = $em;
}
public function reverseTransform($id)
@@ -46,15 +38,17 @@ class CenterTransformer implements DataTransformerInterface
if ($id === NULL) {
return NULL;
}
$center = $this->om->getRepository('ChillMainBundle:Center')
->find($id);
$center = $this
->em
->getRepository(Center::class)
->find($id);
if ($center === NULL) {
throw new TransformationFailedException(sprintf(
'No center found with id %d', $id));
}
return $center;
}
@@ -63,7 +57,7 @@ class CenterTransformer implements DataTransformerInterface
if ($center === NULL) {
return '';
}
return $center->getId();
}

View File

@@ -24,28 +24,20 @@ use Symfony\Component\Form\DataTransformerInterface;
use Symfony\Component\Form\Exception\TransformationFailedException;
use Doctrine\Persistence\ObjectManager;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\EntityManagerInterface;
class MultipleObjectsToIdTransformer implements DataTransformerInterface
{
/**
* @var ObjectManager
*/
private $em;
/**
* @var string
*/
private $class;
/**
* @param ObjectManager $em
*/
public function __construct(ObjectManager $em, $class)
private EntityManagerInterface $em;
private ?string $class;
public function __construct(EntityManagerInterface $em, ?string $class = null)
{
$this->em = $em;
$this->class = $class;
}
/**
* Transforms an object (use) to a string (id).
*

View File

@@ -20,28 +20,20 @@
namespace Chill\MainBundle\Form\Type\DataTransformer;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Form\DataTransformerInterface;
use Symfony\Component\Form\Exception\TransformationFailedException;
use Doctrine\Persistence\ObjectManager;
class ObjectToIdTransformer implements DataTransformerInterface
{
/**
* @var ObjectManager
*/
private $om;
private EntityManagerInterface $em;
/**
* @var string
*/
private $class;
private ?string $class;
/**
* @param ObjectManager $om
*/
public function __construct(ObjectManager $om, $class)
public function __construct(EntityManagerInterface $em, ?string $class = null)
{
$this->om = $om;
$this->em = $em;
$this->class = $class;
}
@@ -73,7 +65,7 @@ class ObjectToIdTransformer implements DataTransformerInterface
return null;
}
$object = $this->om
$object = $this->em
->getRepository($this->class)
->find($id)
;

View File

@@ -19,41 +19,28 @@
namespace Chill\MainBundle\Form\Type\DataTransformer;
use Chill\MainBundle\Entity\Scope;
use Symfony\Component\Form\DataTransformerInterface;
use Doctrine\Persistence\ObjectManager;
use Symfony\Component\Form\Exception\TransformationFailedException;
use Chill\MainBundle\Templating\TranslatableStringHelper;
use Doctrine\ORM\EntityManagerInterface;
/**
*
*
* @author Julien Fastré <julien.fastre@champs-libres.coop>
*/
class ScopeTransformer implements DataTransformerInterface
{
/**
*
* @var ObjectManager
*/
protected $om;
/**
*
* @var TranslatableStringHelper
*/
protected $helper;
public function __construct(ObjectManager $om)
private EntityManagerInterface $em;
public function __construct(EntityManagerInterface $em)
{
$this->om = $om;
$this->em = $em;
}
public function transform($scope)
{
if ($scope === NULL) {
return NULL;
}
return $scope->getId();
}
@@ -62,15 +49,17 @@ class ScopeTransformer implements DataTransformerInterface
if ($id == NULL) {
return NULL;
}
$scope = $this->om->getRepository('ChillMainBundle:Scope')
->find($id);
$scope = $this
->em
->getRepository(Scope::class)
->find($id);
if ($scope === NULL) {
throw new TransformationFailedException(sprintf("The scope with id "
. "'%d' were not found", $id));
}
return $scope;
}

View File

@@ -22,6 +22,7 @@ use Chill\MainBundle\Entity\Center;
use Chill\MainBundle\Entity\Scope;
use Chill\MainBundle\Entity\User;
use Chill\MainBundle\Form\DataMapper\ScopePickerDataMapper;
use Chill\MainBundle\Repository\ScopeRepository;
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
use Chill\MainBundle\Templating\TranslatableStringHelper;
use Doctrine\ORM\EntityRepository;
@@ -60,7 +61,7 @@ class ScopePickerType extends AbstractType
protected $tokenStorage;
/**
* @var EntityRepository
* @var ScopeRepository
*/
protected $scopeRepository;
@@ -72,7 +73,7 @@ class ScopePickerType extends AbstractType
public function __construct(
AuthorizationHelper $authorizationHelper,
TokenStorageInterface $tokenStorage,
EntityRepository $scopeRepository,
ScopeRepository $scopeRepository,
TranslatableStringHelper $translatableStringHelper
) {
$this->authorizationHelper = $authorizationHelper;

View File

@@ -25,6 +25,7 @@ use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Chill\MainBundle\Entity\User;
use Chill\MainBundle\Repository\UserRepository;
use Symfony\Component\Security\Core\Role\RoleHierarchyInterface;
use Symfony\Component\Security\Core\Role\Role;
@@ -53,16 +54,12 @@ class UserPickerType extends AbstractType
*/
protected $tokenStorage;
/**
*
* @var \Chill\MainBundle\Repository\UserRepository
*/
protected $userRepository;
protected UserRepository $userRepository;
public function __construct(
AuthorizationHelper $authorizationHelper,
TokenStorageInterface $tokenStorage,
EntityRepository $userRepository
UserRepository $userRepository
) {
$this->authorizationHelper = $authorizationHelper;
$this->tokenStorage = $tokenStorage;

View File

@@ -6,12 +6,25 @@ services:
autowire: true
autoconfigure: true
Chill\MainBundle\Repository\:
resource: '../Repository/'
autowire: true
autoconfigure: true
Chill\MainBundle\Serializer\Normalizer\:
resource: '../Serializer/Normalizer'
autoconfigure: true
autowire: true
tags:
- { name: 'serializer.normalizer', priority: 64 }
Chill\MainBundle\Form\Type\:
resource: '../Form/Type'
autoconfigure: true
autowire: true
tags:
- { name: form.type }
Chill\MainBundle\Doctrine\Event\:
resource: '../Doctrine/Event/'
autowire: true

View File

@@ -65,8 +65,6 @@ services:
chill.main.form.choice_loader.postal_code:
class: Chill\MainBundle\Form\ChoiceLoader\PostalCodeChoiceLoader
arguments:
- '@Chill\MainBundle\Repository\PostalCodeRepository'
chill.main.form.type.export:
class: Chill\MainBundle\Form\Type\Export\ExportType
@@ -98,32 +96,10 @@ services:
arguments:
- '@Chill\MainBundle\Export\ExportManager'
chill.main.form.date_type:
class: Chill\MainBundle\Form\Type\ChillDateType
tags:
- { name: form.type }
chill.main.form.pick_user_type:
class: Chill\MainBundle\Form\Type\UserPickerType
arguments:
- "@chill.main.security.authorization.helper"
- "@security.token_storage"
- "@chill.main.user_repository"
tags:
- { name: form.type }
chill.main.form.pick_scope_type:
class: Chill\MainBundle\Form\Type\ScopePickerType
arguments:
- "@chill.main.security.authorization.helper"
- "@security.token_storage"
- "@chill.main.scope_repository"
- "@chill.main.helper.translatable_string"
tags:
- { name: form.type }
chill.main.form.advanced_search_type:
class: Chill\MainBundle\Form\AdvancedSearchType
autowire: true
autoconfigure: true
arguments:
- "@chill_main.search_provider"
tags:

View File

@@ -32,9 +32,8 @@ services:
- { name: twig.extension }
Chill\MainBundle\Templating\Entity\CommentRender:
arguments:
- '@chill.main.user_repository'
- '@Symfony\Component\Templating\EngineInterface'
autoconfigure: true
autowire: true
tags:
- { name: 'chill.render_entity' }