From 92b4adc11395f2c4e8dcb4ad98fdcc514ba98bc6 Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Fri, 11 Jun 2021 21:07:16 +0200 Subject: [PATCH] Fix DI on other services depending on updated repositories. --- .../DataTransformer/CenterTransformer.php | 34 +++++++-------- .../MultipleObjectsToIdTransformer.php | 24 ++++------- .../DataTransformer/ObjectToIdTransformer.php | 20 +++------ .../Type/DataTransformer/ScopeTransformer.php | 41 +++++++------------ .../Form/Type/ScopePickerType.php | 5 ++- .../Form/Type/UserPickerType.php | 9 ++-- .../ChillMainBundle/config/services.yaml | 13 ++++++ .../ChillMainBundle/config/services/form.yaml | 28 +------------ .../config/services/templating.yaml | 5 +-- .../Export/Aggregator/AgeAggregator.php | 21 +++------- .../Aggregator/CountryOfBirthAggregator.php | 38 +++++------------ .../Export/Aggregator/GenderAggregator.php | 21 +++------- .../Aggregator/NationalityAggregator.php | 36 +++++----------- .../ChillPersonBundle/config/services.yaml | 5 +++ .../config/services/exports.yaml | 28 ++++++------- 15 files changed, 113 insertions(+), 215 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Form/Type/DataTransformer/CenterTransformer.php b/src/Bundle/ChillMainBundle/Form/Type/DataTransformer/CenterTransformer.php index 4b1b9a2d9..b90ab5a46 100644 --- a/src/Bundle/ChillMainBundle/Form/Type/DataTransformer/CenterTransformer.php +++ b/src/Bundle/ChillMainBundle/Form/Type/DataTransformer/CenterTransformer.php @@ -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é - */ 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(); } diff --git a/src/Bundle/ChillMainBundle/Form/Type/DataTransformer/MultipleObjectsToIdTransformer.php b/src/Bundle/ChillMainBundle/Form/Type/DataTransformer/MultipleObjectsToIdTransformer.php index 4686a5e17..00ee26fff 100644 --- a/src/Bundle/ChillMainBundle/Form/Type/DataTransformer/MultipleObjectsToIdTransformer.php +++ b/src/Bundle/ChillMainBundle/Form/Type/DataTransformer/MultipleObjectsToIdTransformer.php @@ -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). * diff --git a/src/Bundle/ChillMainBundle/Form/Type/DataTransformer/ObjectToIdTransformer.php b/src/Bundle/ChillMainBundle/Form/Type/DataTransformer/ObjectToIdTransformer.php index d041dce7c..82cdf6c21 100644 --- a/src/Bundle/ChillMainBundle/Form/Type/DataTransformer/ObjectToIdTransformer.php +++ b/src/Bundle/ChillMainBundle/Form/Type/DataTransformer/ObjectToIdTransformer.php @@ -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) ; diff --git a/src/Bundle/ChillMainBundle/Form/Type/DataTransformer/ScopeTransformer.php b/src/Bundle/ChillMainBundle/Form/Type/DataTransformer/ScopeTransformer.php index 09ef90063..bd1185333 100644 --- a/src/Bundle/ChillMainBundle/Form/Type/DataTransformer/ScopeTransformer.php +++ b/src/Bundle/ChillMainBundle/Form/Type/DataTransformer/ScopeTransformer.php @@ -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é - */ 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; } diff --git a/src/Bundle/ChillMainBundle/Form/Type/ScopePickerType.php b/src/Bundle/ChillMainBundle/Form/Type/ScopePickerType.php index 379bb2183..832db628f 100644 --- a/src/Bundle/ChillMainBundle/Form/Type/ScopePickerType.php +++ b/src/Bundle/ChillMainBundle/Form/Type/ScopePickerType.php @@ -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; diff --git a/src/Bundle/ChillMainBundle/Form/Type/UserPickerType.php b/src/Bundle/ChillMainBundle/Form/Type/UserPickerType.php index a179f4740..fece2d6d4 100644 --- a/src/Bundle/ChillMainBundle/Form/Type/UserPickerType.php +++ b/src/Bundle/ChillMainBundle/Form/Type/UserPickerType.php @@ -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; diff --git a/src/Bundle/ChillMainBundle/config/services.yaml b/src/Bundle/ChillMainBundle/config/services.yaml index 1b0c8c1e1..53e602998 100644 --- a/src/Bundle/ChillMainBundle/config/services.yaml +++ b/src/Bundle/ChillMainBundle/config/services.yaml @@ -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 diff --git a/src/Bundle/ChillMainBundle/config/services/form.yaml b/src/Bundle/ChillMainBundle/config/services/form.yaml index 5a694a417..3bfb409e9 100644 --- a/src/Bundle/ChillMainBundle/config/services/form.yaml +++ b/src/Bundle/ChillMainBundle/config/services/form.yaml @@ -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: diff --git a/src/Bundle/ChillMainBundle/config/services/templating.yaml b/src/Bundle/ChillMainBundle/config/services/templating.yaml index 9d103f690..cd35a6466 100644 --- a/src/Bundle/ChillMainBundle/config/services/templating.yaml +++ b/src/Bundle/ChillMainBundle/config/services/templating.yaml @@ -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' } diff --git a/src/Bundle/ChillPersonBundle/Export/Aggregator/AgeAggregator.php b/src/Bundle/ChillPersonBundle/Export/Aggregator/AgeAggregator.php index 7b2e6c1b4..bd07d3a48 100644 --- a/src/Bundle/ChillPersonBundle/Export/Aggregator/AgeAggregator.php +++ b/src/Bundle/ChillPersonBundle/Export/Aggregator/AgeAggregator.php @@ -24,28 +24,17 @@ use Doctrine\ORM\QueryBuilder; use Symfony\Component\Form\Extension\Core\Type\DateType; use Chill\MainBundle\Export\ExportElementValidatedInterface; use Symfony\Component\Validator\Context\ExecutionContextInterface; -use Symfony\Component\Translation\TranslatorInterface; +use Symfony\Contracts\Translation\TranslatorInterface; -/** - * - * - * @author Julien Fastré - */ -class AgeAggregator implements AggregatorInterface, - ExportElementValidatedInterface +final class AgeAggregator implements AggregatorInterface, ExportElementValidatedInterface { - /** - * - * @var - */ - protected $translator; - - public function __construct($translator) + private TranslatorInterface $translator; + + public function __construct(TranslatorInterface $translator) { $this->translator = $translator; } - public function addRole() { return null; diff --git a/src/Bundle/ChillPersonBundle/Export/Aggregator/CountryOfBirthAggregator.php b/src/Bundle/ChillPersonBundle/Export/Aggregator/CountryOfBirthAggregator.php index 5bb08af60..1deefe993 100644 --- a/src/Bundle/ChillPersonBundle/Export/Aggregator/CountryOfBirthAggregator.php +++ b/src/Bundle/ChillPersonBundle/Export/Aggregator/CountryOfBirthAggregator.php @@ -29,40 +29,23 @@ use Chill\MainBundle\Util\CountriesInfo; use Symfony\Component\Security\Core\Role\Role; use Chill\PersonBundle\Security\Authorization\PersonVoter; use Chill\MainBundle\Export\ExportElementValidatedInterface; +use Chill\MainBundle\Repository\CountryRepository; use Symfony\Component\Validator\Context\ExecutionContextInterface; use Symfony\Component\Form\Extension\Core\Type\ChoiceType; - -/** - * - * - * @author Julien Fastré - */ -class CountryOfBirthAggregator implements AggregatorInterface, - ExportElementValidatedInterface +final class CountryOfBirthAggregator implements AggregatorInterface, ExportElementValidatedInterface { - /** - * - * @var EntityRepository - */ - protected $countriesRepository; + private CountryRepository $countriesRepository; - /** - * - * @var TranslatableStringHelper - */ - protected $translatableStringHelper; + private TranslatableStringHelper $translatableStringHelper; - /** - * - * @var TranslatorInterface - */ - protected $translator; + private TranslatorInterface $translator; - public function __construct(EntityRepository $countriesRepository, - TranslatableStringHelper $translatableStringHelper, - TranslatorInterface $translator) - { + public function __construct( + CountryRepository $countriesRepository, + TranslatableStringHelper $translatableStringHelper, + TranslatorInterface $translator + ) { $this->countriesRepository = $countriesRepository; $this->translatableStringHelper = $translatableStringHelper; $this->translator = $translator; @@ -73,7 +56,6 @@ class CountryOfBirthAggregator implements AggregatorInterface, return 'person'; } - public function buildForm(FormBuilderInterface $builder) { $builder->add('group_by_level', ChoiceType::class, array( diff --git a/src/Bundle/ChillPersonBundle/Export/Aggregator/GenderAggregator.php b/src/Bundle/ChillPersonBundle/Export/Aggregator/GenderAggregator.php index 6f4314a76..cd3c022d9 100644 --- a/src/Bundle/ChillPersonBundle/Export/Aggregator/GenderAggregator.php +++ b/src/Bundle/ChillPersonBundle/Export/Aggregator/GenderAggregator.php @@ -26,31 +26,20 @@ use Symfony\Component\Translation\TranslatorInterface; use Chill\PersonBundle\Entity\Person; use Chill\PersonBundle\Export\Declarations; -/** - * - * - * @author Julien Fastré - */ -class GenderAggregator implements AggregatorInterface +final class GenderAggregator implements AggregatorInterface { - - /** - * - * @var TranslatorInterface - */ - protected $translator; - + private TranslatorInterface $translator; + public function __construct(TranslatorInterface $translator) { $this->translator = $translator; } - + public function applyOn() { return Declarations::PERSON_TYPE; } - - + public function buildForm(FormBuilderInterface $builder) { diff --git a/src/Bundle/ChillPersonBundle/Export/Aggregator/NationalityAggregator.php b/src/Bundle/ChillPersonBundle/Export/Aggregator/NationalityAggregator.php index d708957f7..e856bedc6 100644 --- a/src/Bundle/ChillPersonBundle/Export/Aggregator/NationalityAggregator.php +++ b/src/Bundle/ChillPersonBundle/Export/Aggregator/NationalityAggregator.php @@ -29,39 +29,23 @@ use Chill\MainBundle\Util\CountriesInfo; use Symfony\Component\Security\Core\Role\Role; use Chill\PersonBundle\Security\Authorization\PersonVoter; use Chill\MainBundle\Export\ExportElementValidatedInterface; +use Chill\MainBundle\Repository\CountryRepository; use Symfony\Component\Validator\Context\ExecutionContextInterface; use Symfony\Component\Form\Extension\Core\Type\ChoiceType; -/** - * - * - * @author Julien Fastré - */ -class NationalityAggregator implements AggregatorInterface, - ExportElementValidatedInterface +final class NationalityAggregator implements AggregatorInterface, ExportElementValidatedInterface { - /** - * - * @var EntityRepository - */ - protected $countriesRepository; + private CountryRepository $countriesRepository; - /** - * - * @var TranslatableStringHelper - */ - protected $translatableStringHelper; + private TranslatableStringHelper $translatableStringHelper; - /** - * - * @var TranslatorInterface - */ - protected $translator; + private TranslatorInterface $translator; - public function __construct(EntityRepository $countriesRepository, - TranslatableStringHelper $translatableStringHelper, - TranslatorInterface $translator) - { + public function __construct( + CountryRepository $countriesRepository, + TranslatableStringHelper $translatableStringHelper, + TranslatorInterface $translator + ) { $this->countriesRepository = $countriesRepository; $this->translatableStringHelper = $translatableStringHelper; $this->translator = $translator; diff --git a/src/Bundle/ChillPersonBundle/config/services.yaml b/src/Bundle/ChillPersonBundle/config/services.yaml index 0f7ef3e1c..262a44f43 100644 --- a/src/Bundle/ChillPersonBundle/config/services.yaml +++ b/src/Bundle/ChillPersonBundle/config/services.yaml @@ -68,6 +68,11 @@ services: resource: '../Controller/' tags: ['controller.service_arguments'] + Chill\PersonBundle\Export\: + autowire: true + autoconfigure: true + resource: '../Export/' + Chill\PersonBundle\Templating\Entity\: autowire: true autoconfigure: true diff --git a/src/Bundle/ChillPersonBundle/config/services/exports.yaml b/src/Bundle/ChillPersonBundle/config/services/exports.yaml index f6b5e8242..73a2763ab 100644 --- a/src/Bundle/ChillPersonBundle/config/services/exports.yaml +++ b/src/Bundle/ChillPersonBundle/config/services/exports.yaml @@ -36,43 +36,39 @@ services: chill.person.export.filter_birthdate: class: Chill\PersonBundle\Export\Filter\BirthdateFilter tags: - - { name: chill.export_filter, alias: person_birthdate_filter } - + - { name: chill.export_filter, alias: person_birthdate_filter } + chill.person.export.filter_nationality: class: Chill\PersonBundle\Export\Filter\NationalityFilter - arguments: - - "@chill.main.helper.translatable_string" + autowire: true + autoconfigure: true tags: - { name: chill.export_filter, alias: person_nationality_filter } chill.person.export.aggregator_nationality: class: Chill\PersonBundle\Export\Aggregator\NationalityAggregator - arguments: - - "@chill.main.countries_repository" - - "@chill.main.helper.translatable_string" - - "@translator" + autowire: true + autoconfigure: true tags: - { name: chill.export_aggregator, alias: person_nationality_aggregator } chill.person.export.aggregator_country_of_birth: class: Chill\PersonBundle\Export\Aggregator\CountryOfBirthAggregator - arguments: - - "@chill.main.countries_repository" - - "@chill.main.helper.translatable_string" - - "@translator" + autowire: true + autoconfigure: true tags: - { name: chill.export_aggregator, alias: person_country_of_birth_aggregator } chill.person.export.aggregator_gender: class: Chill\PersonBundle\Export\Aggregator\GenderAggregator - arguments: - - "@translator" + autowire: true + autoconfigure: true tags: - { name: chill.export_aggregator, alias: person_gender_aggregator } chill.person.export.aggregator_age: class: Chill\PersonBundle\Export\Aggregator\AgeAggregator - arguments: - - "@translator" + autowire: true + autoconfigure: true tags: - { name: chill.export_aggregator, alias: person_age_aggregator }