From d830b19756f4c7c337096e8ef03a6a6124d374b0 Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Wed, 17 Nov 2021 20:23:37 +0100 Subject: [PATCH 01/31] fix: Enforce (and document) the type of property. --- src/Bundle/ChillPersonBundle/Entity/Person.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Entity/Person.php b/src/Bundle/ChillPersonBundle/Entity/Person.php index fc6a7058f..df2f8ac51 100644 --- a/src/Bundle/ChillPersonBundle/Entity/Person.php +++ b/src/Bundle/ChillPersonBundle/Entity/Person.php @@ -305,11 +305,10 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI /** * The person's center - * @var Center * * @ORM\ManyToOne(targetEntity="Chill\MainBundle\Entity\Center") */ - private $center; + private ?Center $center = null; /** * The person's accompanying periods (when the person was accompanied by the center) From d7fbbbf92cfe5233130ed7d5c27aeb9364426436 Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Wed, 17 Nov 2021 20:31:20 +0100 Subject: [PATCH 02/31] fix: `Autowire` and `autoconfigure` services in `chill_main`. --- .../ChillMainBundle/config/services.yaml | 7 ---- .../config/services/cache.yaml | 4 +++ .../config/services/command.yaml | 10 +++--- .../config/services/controller.yaml | 9 ++--- .../ChillMainBundle/config/services/crud.yaml | 4 +++ .../config/services/doctrine.yaml | 6 +++- .../config/services/export.yaml | 15 ++++---- .../config/services/fixtures.yaml | 4 +++ .../ChillMainBundle/config/services/form.yaml | 34 ++----------------- .../config/services/logger.yaml | 4 +++ .../ChillMainBundle/config/services/menu.yaml | 6 ++-- .../config/services/notification.yaml | 8 ++--- .../config/services/pagination.yaml | 6 ++-- .../config/services/phonenumber.yaml | 8 +++-- .../config/services/redis.yaml | 7 ++-- .../config/services/routing.yaml | 6 +++- .../config/services/search.yaml | 10 +++--- .../config/services/security.yaml | 25 -------------- .../config/services/serializer.yaml | 4 ++- .../config/services/templating.yaml | 16 +++------ .../config/services/timeline.yaml | 4 +++ .../config/services/validator.yaml | 6 +++- .../config/services/widget.yaml | 4 +++ 23 files changed, 92 insertions(+), 115 deletions(-) diff --git a/src/Bundle/ChillMainBundle/config/services.yaml b/src/Bundle/ChillMainBundle/config/services.yaml index f5f10cf57..916257335 100644 --- a/src/Bundle/ChillMainBundle/config/services.yaml +++ b/src/Bundle/ChillMainBundle/config/services.yaml @@ -8,28 +8,21 @@ services: Chill\MainBundle\Repository\: resource: '../Repository/' - autowire: true - autoconfigure: true Chill\MainBundle\Repository\UserACLAwareRepositoryInterface: '@Chill\MainBundle\Repository\UserACLAwareRepository' 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 tags: - { name: 'doctrine.event_subscriber' } diff --git a/src/Bundle/ChillMainBundle/config/services/cache.yaml b/src/Bundle/ChillMainBundle/config/services/cache.yaml index de362ea30..ce2bb3e08 100644 --- a/src/Bundle/ChillMainBundle/config/services/cache.yaml +++ b/src/Bundle/ChillMainBundle/config/services/cache.yaml @@ -1,4 +1,8 @@ services: + _defaults: + autowire: true + autoconfigure: true + chill_main.tag_aware_cache: class: Symfony\Component\Cache\Adapter\TagAwareAdapter arguments: diff --git a/src/Bundle/ChillMainBundle/config/services/command.yaml b/src/Bundle/ChillMainBundle/config/services/command.yaml index a005f9944..87220bc1f 100644 --- a/src/Bundle/ChillMainBundle/config/services/command.yaml +++ b/src/Bundle/ChillMainBundle/config/services/command.yaml @@ -1,11 +1,9 @@ services: + _defaults: + autowire: true + autoconfigure: true + Chill\MainBundle\Command\ChillImportUsersCommand: - arguments: - $em: '@Doctrine\ORM\EntityManagerInterface' - $logger: '@Psr\Log\LoggerInterface' - $passwordEncoder: '@Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface' - $validator: '@Symfony\Component\Validator\Validator\ValidatorInterface' - $userRepository: '@Chill\MainBundle\Repository\UserRepository' tags: - { name: console.command } diff --git a/src/Bundle/ChillMainBundle/config/services/controller.yaml b/src/Bundle/ChillMainBundle/config/services/controller.yaml index a74755ffd..28abc94e8 100644 --- a/src/Bundle/ChillMainBundle/config/services/controller.yaml +++ b/src/Bundle/ChillMainBundle/config/services/controller.yaml @@ -1,12 +1,13 @@ services: + _defaults: + autowire: true + autoconfigure: true Chill\MainBundle\Controller\: - autowire: true resource: '../../Controller' tags: ['controller.service_arguments'] Chill\MainBundle\Controller\PasswordController: - autowire: true arguments: $chillLogger: '@monolog.logger.chill' tags: ['controller.service_arguments'] @@ -28,10 +29,6 @@ services: $validator: '@Symfony\Component\Validator\Validator\ValidatorInterface' tags: ['controller.service_arguments'] - Chill\MainBundle\Controller\UserController: - autowire: true - autoconfigure: true - Chill\MainBundle\Controller\NotificationController: arguments: $security: '@Symfony\Component\Security\Core\Security' diff --git a/src/Bundle/ChillMainBundle/config/services/crud.yaml b/src/Bundle/ChillMainBundle/config/services/crud.yaml index 5d1940a87..02533f433 100644 --- a/src/Bundle/ChillMainBundle/config/services/crud.yaml +++ b/src/Bundle/ChillMainBundle/config/services/crud.yaml @@ -1,4 +1,8 @@ services: + _defaults: + autowire: true + autoconfigure: true + Chill\MainBundle\CRUD\Routing\CRUDRoutesLoader: arguments: $crudConfig: '%chill_main_crud_route_loader_config%' diff --git a/src/Bundle/ChillMainBundle/config/services/doctrine.yaml b/src/Bundle/ChillMainBundle/config/services/doctrine.yaml index 09b68f03b..e59088fc4 100644 --- a/src/Bundle/ChillMainBundle/config/services/doctrine.yaml +++ b/src/Bundle/ChillMainBundle/config/services/doctrine.yaml @@ -1,3 +1,7 @@ --- services: - 'Chill\MainBundle\Doctrine\Migrations\VersionComparator': ~ + _defaults: + autowire: true + autoconfigure: true + + Chill\MainBundle\Doctrine\Migrations\VersionComparator: ~ diff --git a/src/Bundle/ChillMainBundle/config/services/export.yaml b/src/Bundle/ChillMainBundle/config/services/export.yaml index ac49199af..ce361677b 100644 --- a/src/Bundle/ChillMainBundle/config/services/export.yaml +++ b/src/Bundle/ChillMainBundle/config/services/export.yaml @@ -1,9 +1,13 @@ services: + _defaults: + autowire: true + autoconfigure: true + chill.main.export_element_validator: class: Chill\MainBundle\Validator\Constraints\Export\ExportElementConstraintValidator tags: - { name: validator.constraint_validator } - + # deprecated in favor of spreadsheet_formatter # chill.main.export.csv_formatter: # class: Chill\MainBundle\Export\Formatter\CSVFormatter @@ -11,7 +15,7 @@ services: # - "@translator" # tags: # - { name: chill.export_formatter, alias: 'csv' } - + chill.main.export.spreadsheet_formatter: class: Chill\MainBundle\Export\Formatter\SpreadSheetFormatter arguments: @@ -19,7 +23,7 @@ services: $exportManager: '@Chill\MainBundle\Export\ExportManager' tags: - { name: chill.export_formatter, alias: 'spreadsheet' } - + chill.main.export.list_formatter: class: Chill\MainBundle\Export\Formatter\CSVListFormatter arguments: @@ -27,7 +31,7 @@ services: $exportManager: '@Chill\MainBundle\Export\ExportManager' tags: - { name: chill.export_formatter, alias: 'csvlist' } - + chill.main.export.list_spreadsheet_formatter: class: Chill\MainBundle\Export\Formatter\SpreadsheetListFormatter arguments: @@ -35,7 +39,7 @@ services: $exportManager: '@Chill\MainBundle\Export\ExportManager' tags: - { name: chill.export_formatter, alias: 'spreadlist' } - + chill.main.export.pivoted_list_formatter: class: Chill\MainBundle\Export\Formatter\CSVPivotedListFormatter arguments: @@ -43,4 +47,3 @@ services: $exportManager: '@Chill\MainBundle\Export\ExportManager' tags: - { name: chill.export_formatter, alias: 'csv_pivoted_list' } - \ No newline at end of file diff --git a/src/Bundle/ChillMainBundle/config/services/fixtures.yaml b/src/Bundle/ChillMainBundle/config/services/fixtures.yaml index ccae65867..29aabb25f 100644 --- a/src/Bundle/ChillMainBundle/config/services/fixtures.yaml +++ b/src/Bundle/ChillMainBundle/config/services/fixtures.yaml @@ -1,4 +1,8 @@ services: + _defaults: + autowire: true + autoconfigure: true + Chill\MainBundle\DataFixtures\ORM\: resource: ../../DataFixtures/ORM tags: [ 'doctrine.fixture.orm' ] diff --git a/src/Bundle/ChillMainBundle/config/services/form.yaml b/src/Bundle/ChillMainBundle/config/services/form.yaml index 27d018229..843e03cb0 100644 --- a/src/Bundle/ChillMainBundle/config/services/form.yaml +++ b/src/Bundle/ChillMainBundle/config/services/form.yaml @@ -1,4 +1,7 @@ services: + _defaults: + autowire: true + autoconfigure: true chill.main.form.type.translatable.string: class: Chill\MainBundle\Form\Type\TranslatableStringFormType @@ -39,10 +42,6 @@ services: tags: - { name: form.type, alias: select2_chill_language } - Chill\MainBundle\Form\Type\PickCenterType: - autowire: true - autoconfigure: true - chill.main.form.type.composed_role_scope: class: Chill\MainBundle\Form\Type\ComposedRoleScopeType arguments: @@ -62,10 +61,6 @@ services: tags: - { name: form.type } - Chill\MainBundle\Form\ChoiceLoader\PostalCodeChoiceLoader: - autowire: true - autoconfigure: true - chill.main.form.type.export: class: Chill\MainBundle\Form\Type\Export\ExportType tags: @@ -96,14 +91,8 @@ services: arguments: - '@Chill\MainBundle\Export\ExportManager' - Chill\MainBundle\Form\Type\DataTransformer\CenterTransformer: - autowire: true - autoconfigure: true - chill.main.form.advanced_search_type: class: Chill\MainBundle\Form\AdvancedSearchType - autowire: true - autoconfigure: true arguments: - "@chill_main.search_provider" tags: @@ -116,10 +105,6 @@ services: tags: - { name: form.type } - Chill\MainBundle\Form\UserType: - autowire: true - autoconfigure: true - Chill\MainBundle\Form\PermissionsGroupType: tags: - { name: form.type } @@ -130,16 +115,3 @@ services: - "@security.token_storage" tags: - { name: form.type } - - - Chill\MainBundle\Form\Type\PickAddressType: - autoconfigure: true - autowire: true - - Chill\MainBundle\Form\DataTransform\AddressToIdDataTransformer: - autoconfigure: true - autowire: true - - Chill\MainBundle\Form\Type\LocationFormType: - autowire: true - autoconfigure: true \ No newline at end of file diff --git a/src/Bundle/ChillMainBundle/config/services/logger.yaml b/src/Bundle/ChillMainBundle/config/services/logger.yaml index 2da5a4a4c..a8c8dce58 100644 --- a/src/Bundle/ChillMainBundle/config/services/logger.yaml +++ b/src/Bundle/ChillMainBundle/config/services/logger.yaml @@ -1,4 +1,8 @@ services: + _defaults: + autowire: true + autoconfigure: true + chill.main.logger: # a logger to log events from the app (deletion, remove, etc.) alias: monolog.logger.chill diff --git a/src/Bundle/ChillMainBundle/config/services/menu.yaml b/src/Bundle/ChillMainBundle/config/services/menu.yaml index cf31dccf1..a41e90345 100644 --- a/src/Bundle/ChillMainBundle/config/services/menu.yaml +++ b/src/Bundle/ChillMainBundle/config/services/menu.yaml @@ -1,9 +1,11 @@ services: - Chill\MainBundle\Routing\MenuBuilder\: - resource: '../../Routing/MenuBuilder' + _defaults: autowire: true autoconfigure: true + Chill\MainBundle\Routing\MenuBuilder\: + resource: '../../Routing/MenuBuilder' + Chill\MainBundle\Routing\MenuBuilder\UserMenuBuilder: arguments: $tokenStorage: '@Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface' diff --git a/src/Bundle/ChillMainBundle/config/services/notification.yaml b/src/Bundle/ChillMainBundle/config/services/notification.yaml index c8d970c5d..93aa9b770 100644 --- a/src/Bundle/ChillMainBundle/config/services/notification.yaml +++ b/src/Bundle/ChillMainBundle/config/services/notification.yaml @@ -1,4 +1,8 @@ services: + _defaults: + autowire: true + autoconfigure: true + Chill\MainBundle\Notification\Mailer: arguments: $logger: '@Psr\Log\LoggerInterface' @@ -8,7 +12,3 @@ services: $router: '@Symfony\Component\Routing\RouterInterface' $translator: '@Symfony\Component\Translation\TranslatorInterface' $routeParameters: '%chill_main.notifications%' - - Chill\MainBundle\Notification\NotificationRenderer: - autoconfigure: true - autowire: true diff --git a/src/Bundle/ChillMainBundle/config/services/pagination.yaml b/src/Bundle/ChillMainBundle/config/services/pagination.yaml index cb0855a3d..f94bc31be 100644 --- a/src/Bundle/ChillMainBundle/config/services/pagination.yaml +++ b/src/Bundle/ChillMainBundle/config/services/pagination.yaml @@ -1,9 +1,11 @@ services: + _defaults: + autowire: true + autoconfigure: true + chill_main.paginator_factory: class: Chill\MainBundle\Pagination\PaginatorFactory public: true - autowire: true - autoconfigure: true arguments: - "@request_stack" - "@router" diff --git a/src/Bundle/ChillMainBundle/config/services/phonenumber.yaml b/src/Bundle/ChillMainBundle/config/services/phonenumber.yaml index f297c03e0..7c5d78e08 100644 --- a/src/Bundle/ChillMainBundle/config/services/phonenumber.yaml +++ b/src/Bundle/ChillMainBundle/config/services/phonenumber.yaml @@ -1,16 +1,20 @@ services: + _defaults: + autowire: true + autoconfigure: true + Chill\MainBundle\Phonenumber\PhonenumberHelper: arguments: $logger: '@Psr\Log\LoggerInterface' $config: '%chill_main.phone_helper%' $cachePool: '@cache.user_data' - + Chill\MainBundle\Phonenumber\Templating: arguments: $phonenumberHelper: '@Chill\MainBundle\Phonenumber\PhonenumberHelper' tags: - { name: twig.extension } - + Chill\MainBundle\Validation\Validator\ValidPhonenumber: arguments: $logger: '@Psr\Log\LoggerInterface' diff --git a/src/Bundle/ChillMainBundle/config/services/redis.yaml b/src/Bundle/ChillMainBundle/config/services/redis.yaml index c8d5c2879..6ccbfee7f 100644 --- a/src/Bundle/ChillMainBundle/config/services/redis.yaml +++ b/src/Bundle/ChillMainBundle/config/services/redis.yaml @@ -1,10 +1,13 @@ services: + _defaults: + autowire: true + autoconfigure: true + Chill\MainBundle\Redis\RedisConnectionFactory: arguments: $parameters: "%chill_main.redis%" tags: - { name: kernel.event_subcriber } - + Chill\MainBundle\Redis\ChillRedis: factory: [ '@Chill\MainBundle\Redis\RedisConnectionFactory', 'create' ] - \ No newline at end of file diff --git a/src/Bundle/ChillMainBundle/config/services/routing.yaml b/src/Bundle/ChillMainBundle/config/services/routing.yaml index c935f1a4d..fa8a56696 100644 --- a/src/Bundle/ChillMainBundle/config/services/routing.yaml +++ b/src/Bundle/ChillMainBundle/config/services/routing.yaml @@ -1,4 +1,8 @@ services: + _defaults: + autowire: true + autoconfigure: true + chill.main.menu_composer: class: Chill\MainBundle\Routing\MenuComposer arguments: @@ -6,7 +10,7 @@ services: - '@Knp\Menu\FactoryInterface' - '@Symfony\Component\Translation\TranslatorInterface' Chill\MainBundle\Routing\MenuComposer: '@chill.main.menu_composer' - + chill.main.routes_loader: class: Chill\MainBundle\Routing\Loader\ChillRoutesLoader arguments: diff --git a/src/Bundle/ChillMainBundle/config/services/search.yaml b/src/Bundle/ChillMainBundle/config/services/search.yaml index 38e421eaf..c0954fffe 100644 --- a/src/Bundle/ChillMainBundle/config/services/search.yaml +++ b/src/Bundle/ChillMainBundle/config/services/search.yaml @@ -1,14 +1,12 @@ services: + _defaults: + autowire: true + autoconfigure: true + chill_main.search_provider: class: Chill\MainBundle\Search\SearchProvider Chill\MainBundle\Search\SearchProvider: '@chill_main.search_provider' - Chill\MainBundle\Search\SearchApi: - autowire: true - autoconfigure: true - Chill\MainBundle\Search\Entity\: - autowire: true - autoconfigure: true resource: '../../Search/Entity' diff --git a/src/Bundle/ChillMainBundle/config/services/security.yaml b/src/Bundle/ChillMainBundle/config/services/security.yaml index dc7949556..15e190a1e 100644 --- a/src/Bundle/ChillMainBundle/config/services/security.yaml +++ b/src/Bundle/ChillMainBundle/config/services/security.yaml @@ -12,38 +12,13 @@ services: arguments: - !tagged_iterator chill_main.scope_resolver - # do not autowire the directory Security/Resolver - Chill\MainBundle\Security\Resolver\DefaultCenterResolver: - autoconfigure: true - autowire: true - - Chill\MainBundle\Security\Resolver\DefaultScopeResolver: - autoconfigure: true - autowire: true - - # do not autowire the directory Security/Resolver - Chill\MainBundle\Security\Resolver\ResolverTwigExtension: - autoconfigure: true - autowire: true - - # do not autowire the directory Security/Resolver - Chill\MainBundle\Security\Authorization\DefaultVoterHelperFactory: - autowire: true - - # do not autowire the directory Security/Resolver Chill\MainBundle\Security\Authorization\VoterHelperFactoryInterface: '@Chill\MainBundle\Security\Authorization\DefaultVoterHelperFactory' chill.main.security.authorization.helper: class: Chill\MainBundle\Security\Authorization\AuthorizationHelper - autowire: true - autoconfigure: true Chill\MainBundle\Security\Authorization\AuthorizationHelper: '@chill.main.security.authorization.helper' Chill\MainBundle\Security\Authorization\AuthorizationHelperInterface: '@chill.main.security.authorization.helper' - Chill\MainBundle\Security\ParentRoleHelper: - autowire: true - autoconfigure: true - chill.main.role_provider: class: Chill\MainBundle\Security\RoleProvider Chill\MainBundle\Security\RoleProvider: '@chill.main.role_provider' diff --git a/src/Bundle/ChillMainBundle/config/services/serializer.yaml b/src/Bundle/ChillMainBundle/config/services/serializer.yaml index efe98996e..4d8aa9954 100644 --- a/src/Bundle/ChillMainBundle/config/services/serializer.yaml +++ b/src/Bundle/ChillMainBundle/config/services/serializer.yaml @@ -1,11 +1,13 @@ --- services: + _defaults: + autowire: true + autoconfigure: true # note: the autowiring for serializers and normalizers is declared # into ../services.yaml Chill\MainBundle\Serializer\Normalizer\DoctrineExistingEntityNormalizer: - autowire: true tags: - { name: 'serializer.normalizer', priority: 8 } diff --git a/src/Bundle/ChillMainBundle/config/services/templating.yaml b/src/Bundle/ChillMainBundle/config/services/templating.yaml index 02d806db4..060b25588 100644 --- a/src/Bundle/ChillMainBundle/config/services/templating.yaml +++ b/src/Bundle/ChillMainBundle/config/services/templating.yaml @@ -1,4 +1,8 @@ services: + _defaults: + autowire: true + autoconfigure: true + # twig_intl: # class: Twig_Extensions_Extension_Intl # tags: @@ -32,8 +36,6 @@ services: - { name: twig.extension } Chill\MainBundle\Templating\Entity\CommentRender: - autoconfigure: true - autowire: true tags: - { name: 'chill.render_entity' } @@ -41,17 +43,7 @@ services: tags: - { name: twig.extension } - Chill\MainBundle\Templating\Entity\AddressRender: - autoconfigure: true - autowire: true - - Chill\MainBundle\Templating\Entity\UserRender: - autoconfigure: true - autowire: true - Chill\MainBundle\Templating\Listing\: resource: './../../Templating/Listing' - autoconfigure: true - autowire: true Chill\MainBundle\Templating\Listing\FilterOrderHelperFactoryInterface: '@Chill\MainBundle\Templating\Listing\FilterOrderHelperFactory' diff --git a/src/Bundle/ChillMainBundle/config/services/timeline.yaml b/src/Bundle/ChillMainBundle/config/services/timeline.yaml index fe830c7ab..7b7987f5a 100644 --- a/src/Bundle/ChillMainBundle/config/services/timeline.yaml +++ b/src/Bundle/ChillMainBundle/config/services/timeline.yaml @@ -1,4 +1,8 @@ services: + _defaults: + autowire: true + autoconfigure: true + chill_main.timeline_builder: class: Chill\MainBundle\Timeline\TimelineBuilder arguments: diff --git a/src/Bundle/ChillMainBundle/config/services/validator.yaml b/src/Bundle/ChillMainBundle/config/services/validator.yaml index c15b2181e..b3b60b9d6 100644 --- a/src/Bundle/ChillMainBundle/config/services/validator.yaml +++ b/src/Bundle/ChillMainBundle/config/services/validator.yaml @@ -1,11 +1,15 @@ services: + _defaults: + autowire: true + autoconfigure: true + chill_main.validator_user_circle_consistency: class: Chill\MainBundle\Validator\Constraints\Entity\UserCircleConsistencyValidator arguments: - "@chill.main.security.authorization.helper" tags: - { name: "validator.constraint_validator" } - + Chill\MainBundle\Validation\Validator\UserUniqueEmailAndUsername: arguments: $em: '@Doctrine\ORM\EntityManagerInterface' diff --git a/src/Bundle/ChillMainBundle/config/services/widget.yaml b/src/Bundle/ChillMainBundle/config/services/widget.yaml index 53f29da5b..1f4bca2e3 100644 --- a/src/Bundle/ChillMainBundle/config/services/widget.yaml +++ b/src/Bundle/ChillMainBundle/config/services/widget.yaml @@ -1,2 +1,6 @@ services: + _defaults: + autowire: true + autoconfigure: true + Chill\MainBundle\Templating\UI\CountNotificationUser: ~ From d1e1f7faa40d950298d1816887932803f59c814c Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Thu, 18 Nov 2021 08:34:17 +0100 Subject: [PATCH 03/31] Revert "fix: `Autowire` and `autoconfigure` services in `chill_main`." This reverts commit d7fbbbf92cfe5233130ed7d5c27aeb9364426436. --- .../ChillMainBundle/config/services.yaml | 7 ++++ .../config/services/cache.yaml | 4 --- .../config/services/command.yaml | 10 +++--- .../config/services/controller.yaml | 9 +++-- .../ChillMainBundle/config/services/crud.yaml | 4 --- .../config/services/doctrine.yaml | 6 +--- .../config/services/export.yaml | 15 ++++---- .../config/services/fixtures.yaml | 4 --- .../ChillMainBundle/config/services/form.yaml | 34 +++++++++++++++++-- .../config/services/logger.yaml | 4 --- .../ChillMainBundle/config/services/menu.yaml | 6 ++-- .../config/services/notification.yaml | 8 ++--- .../config/services/pagination.yaml | 6 ++-- .../config/services/phonenumber.yaml | 8 ++--- .../config/services/redis.yaml | 7 ++-- .../config/services/routing.yaml | 6 +--- .../config/services/search.yaml | 10 +++--- .../config/services/security.yaml | 25 ++++++++++++++ .../config/services/serializer.yaml | 4 +-- .../config/services/templating.yaml | 16 ++++++--- .../config/services/timeline.yaml | 4 --- .../config/services/validator.yaml | 6 +--- .../config/services/widget.yaml | 4 --- 23 files changed, 115 insertions(+), 92 deletions(-) diff --git a/src/Bundle/ChillMainBundle/config/services.yaml b/src/Bundle/ChillMainBundle/config/services.yaml index 916257335..f5f10cf57 100644 --- a/src/Bundle/ChillMainBundle/config/services.yaml +++ b/src/Bundle/ChillMainBundle/config/services.yaml @@ -8,21 +8,28 @@ services: Chill\MainBundle\Repository\: resource: '../Repository/' + autowire: true + autoconfigure: true Chill\MainBundle\Repository\UserACLAwareRepositoryInterface: '@Chill\MainBundle\Repository\UserACLAwareRepository' 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 tags: - { name: 'doctrine.event_subscriber' } diff --git a/src/Bundle/ChillMainBundle/config/services/cache.yaml b/src/Bundle/ChillMainBundle/config/services/cache.yaml index ce2bb3e08..de362ea30 100644 --- a/src/Bundle/ChillMainBundle/config/services/cache.yaml +++ b/src/Bundle/ChillMainBundle/config/services/cache.yaml @@ -1,8 +1,4 @@ services: - _defaults: - autowire: true - autoconfigure: true - chill_main.tag_aware_cache: class: Symfony\Component\Cache\Adapter\TagAwareAdapter arguments: diff --git a/src/Bundle/ChillMainBundle/config/services/command.yaml b/src/Bundle/ChillMainBundle/config/services/command.yaml index 87220bc1f..a005f9944 100644 --- a/src/Bundle/ChillMainBundle/config/services/command.yaml +++ b/src/Bundle/ChillMainBundle/config/services/command.yaml @@ -1,9 +1,11 @@ services: - _defaults: - autowire: true - autoconfigure: true - Chill\MainBundle\Command\ChillImportUsersCommand: + arguments: + $em: '@Doctrine\ORM\EntityManagerInterface' + $logger: '@Psr\Log\LoggerInterface' + $passwordEncoder: '@Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface' + $validator: '@Symfony\Component\Validator\Validator\ValidatorInterface' + $userRepository: '@Chill\MainBundle\Repository\UserRepository' tags: - { name: console.command } diff --git a/src/Bundle/ChillMainBundle/config/services/controller.yaml b/src/Bundle/ChillMainBundle/config/services/controller.yaml index 28abc94e8..a74755ffd 100644 --- a/src/Bundle/ChillMainBundle/config/services/controller.yaml +++ b/src/Bundle/ChillMainBundle/config/services/controller.yaml @@ -1,13 +1,12 @@ services: - _defaults: - autowire: true - autoconfigure: true Chill\MainBundle\Controller\: + autowire: true resource: '../../Controller' tags: ['controller.service_arguments'] Chill\MainBundle\Controller\PasswordController: + autowire: true arguments: $chillLogger: '@monolog.logger.chill' tags: ['controller.service_arguments'] @@ -29,6 +28,10 @@ services: $validator: '@Symfony\Component\Validator\Validator\ValidatorInterface' tags: ['controller.service_arguments'] + Chill\MainBundle\Controller\UserController: + autowire: true + autoconfigure: true + Chill\MainBundle\Controller\NotificationController: arguments: $security: '@Symfony\Component\Security\Core\Security' diff --git a/src/Bundle/ChillMainBundle/config/services/crud.yaml b/src/Bundle/ChillMainBundle/config/services/crud.yaml index 02533f433..5d1940a87 100644 --- a/src/Bundle/ChillMainBundle/config/services/crud.yaml +++ b/src/Bundle/ChillMainBundle/config/services/crud.yaml @@ -1,8 +1,4 @@ services: - _defaults: - autowire: true - autoconfigure: true - Chill\MainBundle\CRUD\Routing\CRUDRoutesLoader: arguments: $crudConfig: '%chill_main_crud_route_loader_config%' diff --git a/src/Bundle/ChillMainBundle/config/services/doctrine.yaml b/src/Bundle/ChillMainBundle/config/services/doctrine.yaml index e59088fc4..09b68f03b 100644 --- a/src/Bundle/ChillMainBundle/config/services/doctrine.yaml +++ b/src/Bundle/ChillMainBundle/config/services/doctrine.yaml @@ -1,7 +1,3 @@ --- services: - _defaults: - autowire: true - autoconfigure: true - - Chill\MainBundle\Doctrine\Migrations\VersionComparator: ~ + 'Chill\MainBundle\Doctrine\Migrations\VersionComparator': ~ diff --git a/src/Bundle/ChillMainBundle/config/services/export.yaml b/src/Bundle/ChillMainBundle/config/services/export.yaml index ce361677b..ac49199af 100644 --- a/src/Bundle/ChillMainBundle/config/services/export.yaml +++ b/src/Bundle/ChillMainBundle/config/services/export.yaml @@ -1,13 +1,9 @@ services: - _defaults: - autowire: true - autoconfigure: true - chill.main.export_element_validator: class: Chill\MainBundle\Validator\Constraints\Export\ExportElementConstraintValidator tags: - { name: validator.constraint_validator } - + # deprecated in favor of spreadsheet_formatter # chill.main.export.csv_formatter: # class: Chill\MainBundle\Export\Formatter\CSVFormatter @@ -15,7 +11,7 @@ services: # - "@translator" # tags: # - { name: chill.export_formatter, alias: 'csv' } - + chill.main.export.spreadsheet_formatter: class: Chill\MainBundle\Export\Formatter\SpreadSheetFormatter arguments: @@ -23,7 +19,7 @@ services: $exportManager: '@Chill\MainBundle\Export\ExportManager' tags: - { name: chill.export_formatter, alias: 'spreadsheet' } - + chill.main.export.list_formatter: class: Chill\MainBundle\Export\Formatter\CSVListFormatter arguments: @@ -31,7 +27,7 @@ services: $exportManager: '@Chill\MainBundle\Export\ExportManager' tags: - { name: chill.export_formatter, alias: 'csvlist' } - + chill.main.export.list_spreadsheet_formatter: class: Chill\MainBundle\Export\Formatter\SpreadsheetListFormatter arguments: @@ -39,7 +35,7 @@ services: $exportManager: '@Chill\MainBundle\Export\ExportManager' tags: - { name: chill.export_formatter, alias: 'spreadlist' } - + chill.main.export.pivoted_list_formatter: class: Chill\MainBundle\Export\Formatter\CSVPivotedListFormatter arguments: @@ -47,3 +43,4 @@ services: $exportManager: '@Chill\MainBundle\Export\ExportManager' tags: - { name: chill.export_formatter, alias: 'csv_pivoted_list' } + \ No newline at end of file diff --git a/src/Bundle/ChillMainBundle/config/services/fixtures.yaml b/src/Bundle/ChillMainBundle/config/services/fixtures.yaml index 29aabb25f..ccae65867 100644 --- a/src/Bundle/ChillMainBundle/config/services/fixtures.yaml +++ b/src/Bundle/ChillMainBundle/config/services/fixtures.yaml @@ -1,8 +1,4 @@ services: - _defaults: - autowire: true - autoconfigure: true - Chill\MainBundle\DataFixtures\ORM\: resource: ../../DataFixtures/ORM tags: [ 'doctrine.fixture.orm' ] diff --git a/src/Bundle/ChillMainBundle/config/services/form.yaml b/src/Bundle/ChillMainBundle/config/services/form.yaml index 843e03cb0..27d018229 100644 --- a/src/Bundle/ChillMainBundle/config/services/form.yaml +++ b/src/Bundle/ChillMainBundle/config/services/form.yaml @@ -1,7 +1,4 @@ services: - _defaults: - autowire: true - autoconfigure: true chill.main.form.type.translatable.string: class: Chill\MainBundle\Form\Type\TranslatableStringFormType @@ -42,6 +39,10 @@ services: tags: - { name: form.type, alias: select2_chill_language } + Chill\MainBundle\Form\Type\PickCenterType: + autowire: true + autoconfigure: true + chill.main.form.type.composed_role_scope: class: Chill\MainBundle\Form\Type\ComposedRoleScopeType arguments: @@ -61,6 +62,10 @@ services: tags: - { name: form.type } + Chill\MainBundle\Form\ChoiceLoader\PostalCodeChoiceLoader: + autowire: true + autoconfigure: true + chill.main.form.type.export: class: Chill\MainBundle\Form\Type\Export\ExportType tags: @@ -91,8 +96,14 @@ services: arguments: - '@Chill\MainBundle\Export\ExportManager' + Chill\MainBundle\Form\Type\DataTransformer\CenterTransformer: + autowire: true + autoconfigure: true + chill.main.form.advanced_search_type: class: Chill\MainBundle\Form\AdvancedSearchType + autowire: true + autoconfigure: true arguments: - "@chill_main.search_provider" tags: @@ -105,6 +116,10 @@ services: tags: - { name: form.type } + Chill\MainBundle\Form\UserType: + autowire: true + autoconfigure: true + Chill\MainBundle\Form\PermissionsGroupType: tags: - { name: form.type } @@ -115,3 +130,16 @@ services: - "@security.token_storage" tags: - { name: form.type } + + + Chill\MainBundle\Form\Type\PickAddressType: + autoconfigure: true + autowire: true + + Chill\MainBundle\Form\DataTransform\AddressToIdDataTransformer: + autoconfigure: true + autowire: true + + Chill\MainBundle\Form\Type\LocationFormType: + autowire: true + autoconfigure: true \ No newline at end of file diff --git a/src/Bundle/ChillMainBundle/config/services/logger.yaml b/src/Bundle/ChillMainBundle/config/services/logger.yaml index a8c8dce58..2da5a4a4c 100644 --- a/src/Bundle/ChillMainBundle/config/services/logger.yaml +++ b/src/Bundle/ChillMainBundle/config/services/logger.yaml @@ -1,8 +1,4 @@ services: - _defaults: - autowire: true - autoconfigure: true - chill.main.logger: # a logger to log events from the app (deletion, remove, etc.) alias: monolog.logger.chill diff --git a/src/Bundle/ChillMainBundle/config/services/menu.yaml b/src/Bundle/ChillMainBundle/config/services/menu.yaml index a41e90345..cf31dccf1 100644 --- a/src/Bundle/ChillMainBundle/config/services/menu.yaml +++ b/src/Bundle/ChillMainBundle/config/services/menu.yaml @@ -1,10 +1,8 @@ services: - _defaults: - autowire: true - autoconfigure: true - Chill\MainBundle\Routing\MenuBuilder\: resource: '../../Routing/MenuBuilder' + autowire: true + autoconfigure: true Chill\MainBundle\Routing\MenuBuilder\UserMenuBuilder: arguments: diff --git a/src/Bundle/ChillMainBundle/config/services/notification.yaml b/src/Bundle/ChillMainBundle/config/services/notification.yaml index 93aa9b770..c8d970c5d 100644 --- a/src/Bundle/ChillMainBundle/config/services/notification.yaml +++ b/src/Bundle/ChillMainBundle/config/services/notification.yaml @@ -1,8 +1,4 @@ services: - _defaults: - autowire: true - autoconfigure: true - Chill\MainBundle\Notification\Mailer: arguments: $logger: '@Psr\Log\LoggerInterface' @@ -12,3 +8,7 @@ services: $router: '@Symfony\Component\Routing\RouterInterface' $translator: '@Symfony\Component\Translation\TranslatorInterface' $routeParameters: '%chill_main.notifications%' + + Chill\MainBundle\Notification\NotificationRenderer: + autoconfigure: true + autowire: true diff --git a/src/Bundle/ChillMainBundle/config/services/pagination.yaml b/src/Bundle/ChillMainBundle/config/services/pagination.yaml index f94bc31be..cb0855a3d 100644 --- a/src/Bundle/ChillMainBundle/config/services/pagination.yaml +++ b/src/Bundle/ChillMainBundle/config/services/pagination.yaml @@ -1,11 +1,9 @@ services: - _defaults: - autowire: true - autoconfigure: true - chill_main.paginator_factory: class: Chill\MainBundle\Pagination\PaginatorFactory public: true + autowire: true + autoconfigure: true arguments: - "@request_stack" - "@router" diff --git a/src/Bundle/ChillMainBundle/config/services/phonenumber.yaml b/src/Bundle/ChillMainBundle/config/services/phonenumber.yaml index 7c5d78e08..f297c03e0 100644 --- a/src/Bundle/ChillMainBundle/config/services/phonenumber.yaml +++ b/src/Bundle/ChillMainBundle/config/services/phonenumber.yaml @@ -1,20 +1,16 @@ services: - _defaults: - autowire: true - autoconfigure: true - Chill\MainBundle\Phonenumber\PhonenumberHelper: arguments: $logger: '@Psr\Log\LoggerInterface' $config: '%chill_main.phone_helper%' $cachePool: '@cache.user_data' - + Chill\MainBundle\Phonenumber\Templating: arguments: $phonenumberHelper: '@Chill\MainBundle\Phonenumber\PhonenumberHelper' tags: - { name: twig.extension } - + Chill\MainBundle\Validation\Validator\ValidPhonenumber: arguments: $logger: '@Psr\Log\LoggerInterface' diff --git a/src/Bundle/ChillMainBundle/config/services/redis.yaml b/src/Bundle/ChillMainBundle/config/services/redis.yaml index 6ccbfee7f..c8d5c2879 100644 --- a/src/Bundle/ChillMainBundle/config/services/redis.yaml +++ b/src/Bundle/ChillMainBundle/config/services/redis.yaml @@ -1,13 +1,10 @@ services: - _defaults: - autowire: true - autoconfigure: true - Chill\MainBundle\Redis\RedisConnectionFactory: arguments: $parameters: "%chill_main.redis%" tags: - { name: kernel.event_subcriber } - + Chill\MainBundle\Redis\ChillRedis: factory: [ '@Chill\MainBundle\Redis\RedisConnectionFactory', 'create' ] + \ No newline at end of file diff --git a/src/Bundle/ChillMainBundle/config/services/routing.yaml b/src/Bundle/ChillMainBundle/config/services/routing.yaml index fa8a56696..c935f1a4d 100644 --- a/src/Bundle/ChillMainBundle/config/services/routing.yaml +++ b/src/Bundle/ChillMainBundle/config/services/routing.yaml @@ -1,8 +1,4 @@ services: - _defaults: - autowire: true - autoconfigure: true - chill.main.menu_composer: class: Chill\MainBundle\Routing\MenuComposer arguments: @@ -10,7 +6,7 @@ services: - '@Knp\Menu\FactoryInterface' - '@Symfony\Component\Translation\TranslatorInterface' Chill\MainBundle\Routing\MenuComposer: '@chill.main.menu_composer' - + chill.main.routes_loader: class: Chill\MainBundle\Routing\Loader\ChillRoutesLoader arguments: diff --git a/src/Bundle/ChillMainBundle/config/services/search.yaml b/src/Bundle/ChillMainBundle/config/services/search.yaml index c0954fffe..38e421eaf 100644 --- a/src/Bundle/ChillMainBundle/config/services/search.yaml +++ b/src/Bundle/ChillMainBundle/config/services/search.yaml @@ -1,12 +1,14 @@ services: - _defaults: - autowire: true - autoconfigure: true - chill_main.search_provider: class: Chill\MainBundle\Search\SearchProvider Chill\MainBundle\Search\SearchProvider: '@chill_main.search_provider' + Chill\MainBundle\Search\SearchApi: + autowire: true + autoconfigure: true + Chill\MainBundle\Search\Entity\: + autowire: true + autoconfigure: true resource: '../../Search/Entity' diff --git a/src/Bundle/ChillMainBundle/config/services/security.yaml b/src/Bundle/ChillMainBundle/config/services/security.yaml index 15e190a1e..dc7949556 100644 --- a/src/Bundle/ChillMainBundle/config/services/security.yaml +++ b/src/Bundle/ChillMainBundle/config/services/security.yaml @@ -12,13 +12,38 @@ services: arguments: - !tagged_iterator chill_main.scope_resolver + # do not autowire the directory Security/Resolver + Chill\MainBundle\Security\Resolver\DefaultCenterResolver: + autoconfigure: true + autowire: true + + Chill\MainBundle\Security\Resolver\DefaultScopeResolver: + autoconfigure: true + autowire: true + + # do not autowire the directory Security/Resolver + Chill\MainBundle\Security\Resolver\ResolverTwigExtension: + autoconfigure: true + autowire: true + + # do not autowire the directory Security/Resolver + Chill\MainBundle\Security\Authorization\DefaultVoterHelperFactory: + autowire: true + + # do not autowire the directory Security/Resolver Chill\MainBundle\Security\Authorization\VoterHelperFactoryInterface: '@Chill\MainBundle\Security\Authorization\DefaultVoterHelperFactory' chill.main.security.authorization.helper: class: Chill\MainBundle\Security\Authorization\AuthorizationHelper + autowire: true + autoconfigure: true Chill\MainBundle\Security\Authorization\AuthorizationHelper: '@chill.main.security.authorization.helper' Chill\MainBundle\Security\Authorization\AuthorizationHelperInterface: '@chill.main.security.authorization.helper' + Chill\MainBundle\Security\ParentRoleHelper: + autowire: true + autoconfigure: true + chill.main.role_provider: class: Chill\MainBundle\Security\RoleProvider Chill\MainBundle\Security\RoleProvider: '@chill.main.role_provider' diff --git a/src/Bundle/ChillMainBundle/config/services/serializer.yaml b/src/Bundle/ChillMainBundle/config/services/serializer.yaml index 4d8aa9954..efe98996e 100644 --- a/src/Bundle/ChillMainBundle/config/services/serializer.yaml +++ b/src/Bundle/ChillMainBundle/config/services/serializer.yaml @@ -1,13 +1,11 @@ --- services: - _defaults: - autowire: true - autoconfigure: true # note: the autowiring for serializers and normalizers is declared # into ../services.yaml Chill\MainBundle\Serializer\Normalizer\DoctrineExistingEntityNormalizer: + autowire: true tags: - { name: 'serializer.normalizer', priority: 8 } diff --git a/src/Bundle/ChillMainBundle/config/services/templating.yaml b/src/Bundle/ChillMainBundle/config/services/templating.yaml index 060b25588..02d806db4 100644 --- a/src/Bundle/ChillMainBundle/config/services/templating.yaml +++ b/src/Bundle/ChillMainBundle/config/services/templating.yaml @@ -1,8 +1,4 @@ services: - _defaults: - autowire: true - autoconfigure: true - # twig_intl: # class: Twig_Extensions_Extension_Intl # tags: @@ -36,6 +32,8 @@ services: - { name: twig.extension } Chill\MainBundle\Templating\Entity\CommentRender: + autoconfigure: true + autowire: true tags: - { name: 'chill.render_entity' } @@ -43,7 +41,17 @@ services: tags: - { name: twig.extension } + Chill\MainBundle\Templating\Entity\AddressRender: + autoconfigure: true + autowire: true + + Chill\MainBundle\Templating\Entity\UserRender: + autoconfigure: true + autowire: true + Chill\MainBundle\Templating\Listing\: resource: './../../Templating/Listing' + autoconfigure: true + autowire: true Chill\MainBundle\Templating\Listing\FilterOrderHelperFactoryInterface: '@Chill\MainBundle\Templating\Listing\FilterOrderHelperFactory' diff --git a/src/Bundle/ChillMainBundle/config/services/timeline.yaml b/src/Bundle/ChillMainBundle/config/services/timeline.yaml index 7b7987f5a..fe830c7ab 100644 --- a/src/Bundle/ChillMainBundle/config/services/timeline.yaml +++ b/src/Bundle/ChillMainBundle/config/services/timeline.yaml @@ -1,8 +1,4 @@ services: - _defaults: - autowire: true - autoconfigure: true - chill_main.timeline_builder: class: Chill\MainBundle\Timeline\TimelineBuilder arguments: diff --git a/src/Bundle/ChillMainBundle/config/services/validator.yaml b/src/Bundle/ChillMainBundle/config/services/validator.yaml index b3b60b9d6..c15b2181e 100644 --- a/src/Bundle/ChillMainBundle/config/services/validator.yaml +++ b/src/Bundle/ChillMainBundle/config/services/validator.yaml @@ -1,15 +1,11 @@ services: - _defaults: - autowire: true - autoconfigure: true - chill_main.validator_user_circle_consistency: class: Chill\MainBundle\Validator\Constraints\Entity\UserCircleConsistencyValidator arguments: - "@chill.main.security.authorization.helper" tags: - { name: "validator.constraint_validator" } - + Chill\MainBundle\Validation\Validator\UserUniqueEmailAndUsername: arguments: $em: '@Doctrine\ORM\EntityManagerInterface' diff --git a/src/Bundle/ChillMainBundle/config/services/widget.yaml b/src/Bundle/ChillMainBundle/config/services/widget.yaml index 1f4bca2e3..53f29da5b 100644 --- a/src/Bundle/ChillMainBundle/config/services/widget.yaml +++ b/src/Bundle/ChillMainBundle/config/services/widget.yaml @@ -1,6 +1,2 @@ services: - _defaults: - autowire: true - autoconfigure: true - Chill\MainBundle\Templating\UI\CountNotificationUser: ~ From 78615519f42e54eb591629a9445fbbfeda1f923e Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Thu, 18 Nov 2021 09:34:52 +0100 Subject: [PATCH 04/31] select2 field added to task form --- CHANGELOG.md | 1 + src/Bundle/ChillTaskBundle/Form/SingleTaskType.php | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6dc54473f..31c3e1b5d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,7 @@ and this project adheres to * [person suggest] In widget "add person", improve the pertinence of persons when one of the names starts with the pattern; * [person] do not ask for center any more on person creation * [3party] do not ask for center any more on 3party creation +* [task] Select2 field in task form to allow search for a user (https://gitlab.com/champs-libres/departement-de-la-vendee/accent-suivi-developpement/-/issues/167) ## Test releases diff --git a/src/Bundle/ChillTaskBundle/Form/SingleTaskType.php b/src/Bundle/ChillTaskBundle/Form/SingleTaskType.php index 85fe632b7..9af1197c2 100644 --- a/src/Bundle/ChillTaskBundle/Form/SingleTaskType.php +++ b/src/Bundle/ChillTaskBundle/Form/SingleTaskType.php @@ -52,7 +52,8 @@ class SingleTaskType extends AbstractType 'required' => false, 'center' => $center, 'role' => TaskVoter::SHOW, - 'placeholder' => 'Not assigned' + 'placeholder' => 'Not assigned', + 'attr' => [ 'class' => ' select2 '] ]) ->add('startDate', ChillDateType::class, [ 'required' => false From 9f06bc71265f0281dcf7506c008c1c447bd5da43 Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Thu, 18 Nov 2021 08:49:43 +0100 Subject: [PATCH 05/31] fix: `Autowire` and `autoconfigure` services in `chill_main`. This commit does not remove services that are not automatically PSR loaded. --- .../ChillMainBundle/config/services.yaml | 7 ---- .../config/services/cache.yaml | 4 +++ .../config/services/command.yaml | 10 +++--- .../config/services/controller.yaml | 9 ++--- .../ChillMainBundle/config/services/crud.yaml | 4 +++ .../config/services/doctrine.yaml | 6 +++- .../config/services/export.yaml | 15 ++++---- .../config/services/fixtures.yaml | 4 +++ .../ChillMainBundle/config/services/form.yaml | 34 ++++++------------- .../config/services/logger.yaml | 4 +++ .../ChillMainBundle/config/services/menu.yaml | 6 ++-- .../config/services/notification.yaml | 8 +++-- .../config/services/pagination.yaml | 6 ++-- .../config/services/phonenumber.yaml | 10 +++--- .../config/services/redis.yaml | 7 ++-- .../config/services/routing.yaml | 6 +++- .../config/services/search.yaml | 10 +++--- .../config/services/security.yaml | 28 +++------------ .../config/services/serializer.yaml | 4 ++- .../config/services/templating.yaml | 16 ++++----- .../config/services/timeline.yaml | 4 +++ .../config/services/validator.yaml | 6 +++- .../config/services/widget.yaml | 4 +++ 23 files changed, 108 insertions(+), 104 deletions(-) diff --git a/src/Bundle/ChillMainBundle/config/services.yaml b/src/Bundle/ChillMainBundle/config/services.yaml index f5f10cf57..916257335 100644 --- a/src/Bundle/ChillMainBundle/config/services.yaml +++ b/src/Bundle/ChillMainBundle/config/services.yaml @@ -8,28 +8,21 @@ services: Chill\MainBundle\Repository\: resource: '../Repository/' - autowire: true - autoconfigure: true Chill\MainBundle\Repository\UserACLAwareRepositoryInterface: '@Chill\MainBundle\Repository\UserACLAwareRepository' 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 tags: - { name: 'doctrine.event_subscriber' } diff --git a/src/Bundle/ChillMainBundle/config/services/cache.yaml b/src/Bundle/ChillMainBundle/config/services/cache.yaml index de362ea30..ce2bb3e08 100644 --- a/src/Bundle/ChillMainBundle/config/services/cache.yaml +++ b/src/Bundle/ChillMainBundle/config/services/cache.yaml @@ -1,4 +1,8 @@ services: + _defaults: + autowire: true + autoconfigure: true + chill_main.tag_aware_cache: class: Symfony\Component\Cache\Adapter\TagAwareAdapter arguments: diff --git a/src/Bundle/ChillMainBundle/config/services/command.yaml b/src/Bundle/ChillMainBundle/config/services/command.yaml index a005f9944..87220bc1f 100644 --- a/src/Bundle/ChillMainBundle/config/services/command.yaml +++ b/src/Bundle/ChillMainBundle/config/services/command.yaml @@ -1,11 +1,9 @@ services: + _defaults: + autowire: true + autoconfigure: true + Chill\MainBundle\Command\ChillImportUsersCommand: - arguments: - $em: '@Doctrine\ORM\EntityManagerInterface' - $logger: '@Psr\Log\LoggerInterface' - $passwordEncoder: '@Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface' - $validator: '@Symfony\Component\Validator\Validator\ValidatorInterface' - $userRepository: '@Chill\MainBundle\Repository\UserRepository' tags: - { name: console.command } diff --git a/src/Bundle/ChillMainBundle/config/services/controller.yaml b/src/Bundle/ChillMainBundle/config/services/controller.yaml index a74755ffd..28abc94e8 100644 --- a/src/Bundle/ChillMainBundle/config/services/controller.yaml +++ b/src/Bundle/ChillMainBundle/config/services/controller.yaml @@ -1,12 +1,13 @@ services: + _defaults: + autowire: true + autoconfigure: true Chill\MainBundle\Controller\: - autowire: true resource: '../../Controller' tags: ['controller.service_arguments'] Chill\MainBundle\Controller\PasswordController: - autowire: true arguments: $chillLogger: '@monolog.logger.chill' tags: ['controller.service_arguments'] @@ -28,10 +29,6 @@ services: $validator: '@Symfony\Component\Validator\Validator\ValidatorInterface' tags: ['controller.service_arguments'] - Chill\MainBundle\Controller\UserController: - autowire: true - autoconfigure: true - Chill\MainBundle\Controller\NotificationController: arguments: $security: '@Symfony\Component\Security\Core\Security' diff --git a/src/Bundle/ChillMainBundle/config/services/crud.yaml b/src/Bundle/ChillMainBundle/config/services/crud.yaml index 5d1940a87..02533f433 100644 --- a/src/Bundle/ChillMainBundle/config/services/crud.yaml +++ b/src/Bundle/ChillMainBundle/config/services/crud.yaml @@ -1,4 +1,8 @@ services: + _defaults: + autowire: true + autoconfigure: true + Chill\MainBundle\CRUD\Routing\CRUDRoutesLoader: arguments: $crudConfig: '%chill_main_crud_route_loader_config%' diff --git a/src/Bundle/ChillMainBundle/config/services/doctrine.yaml b/src/Bundle/ChillMainBundle/config/services/doctrine.yaml index 09b68f03b..e59088fc4 100644 --- a/src/Bundle/ChillMainBundle/config/services/doctrine.yaml +++ b/src/Bundle/ChillMainBundle/config/services/doctrine.yaml @@ -1,3 +1,7 @@ --- services: - 'Chill\MainBundle\Doctrine\Migrations\VersionComparator': ~ + _defaults: + autowire: true + autoconfigure: true + + Chill\MainBundle\Doctrine\Migrations\VersionComparator: ~ diff --git a/src/Bundle/ChillMainBundle/config/services/export.yaml b/src/Bundle/ChillMainBundle/config/services/export.yaml index ac49199af..ce361677b 100644 --- a/src/Bundle/ChillMainBundle/config/services/export.yaml +++ b/src/Bundle/ChillMainBundle/config/services/export.yaml @@ -1,9 +1,13 @@ services: + _defaults: + autowire: true + autoconfigure: true + chill.main.export_element_validator: class: Chill\MainBundle\Validator\Constraints\Export\ExportElementConstraintValidator tags: - { name: validator.constraint_validator } - + # deprecated in favor of spreadsheet_formatter # chill.main.export.csv_formatter: # class: Chill\MainBundle\Export\Formatter\CSVFormatter @@ -11,7 +15,7 @@ services: # - "@translator" # tags: # - { name: chill.export_formatter, alias: 'csv' } - + chill.main.export.spreadsheet_formatter: class: Chill\MainBundle\Export\Formatter\SpreadSheetFormatter arguments: @@ -19,7 +23,7 @@ services: $exportManager: '@Chill\MainBundle\Export\ExportManager' tags: - { name: chill.export_formatter, alias: 'spreadsheet' } - + chill.main.export.list_formatter: class: Chill\MainBundle\Export\Formatter\CSVListFormatter arguments: @@ -27,7 +31,7 @@ services: $exportManager: '@Chill\MainBundle\Export\ExportManager' tags: - { name: chill.export_formatter, alias: 'csvlist' } - + chill.main.export.list_spreadsheet_formatter: class: Chill\MainBundle\Export\Formatter\SpreadsheetListFormatter arguments: @@ -35,7 +39,7 @@ services: $exportManager: '@Chill\MainBundle\Export\ExportManager' tags: - { name: chill.export_formatter, alias: 'spreadlist' } - + chill.main.export.pivoted_list_formatter: class: Chill\MainBundle\Export\Formatter\CSVPivotedListFormatter arguments: @@ -43,4 +47,3 @@ services: $exportManager: '@Chill\MainBundle\Export\ExportManager' tags: - { name: chill.export_formatter, alias: 'csv_pivoted_list' } - \ No newline at end of file diff --git a/src/Bundle/ChillMainBundle/config/services/fixtures.yaml b/src/Bundle/ChillMainBundle/config/services/fixtures.yaml index ccae65867..29aabb25f 100644 --- a/src/Bundle/ChillMainBundle/config/services/fixtures.yaml +++ b/src/Bundle/ChillMainBundle/config/services/fixtures.yaml @@ -1,4 +1,8 @@ services: + _defaults: + autowire: true + autoconfigure: true + Chill\MainBundle\DataFixtures\ORM\: resource: ../../DataFixtures/ORM tags: [ 'doctrine.fixture.orm' ] diff --git a/src/Bundle/ChillMainBundle/config/services/form.yaml b/src/Bundle/ChillMainBundle/config/services/form.yaml index 27d018229..003fce783 100644 --- a/src/Bundle/ChillMainBundle/config/services/form.yaml +++ b/src/Bundle/ChillMainBundle/config/services/form.yaml @@ -1,4 +1,7 @@ services: + _defaults: + autowire: true + autoconfigure: true chill.main.form.type.translatable.string: class: Chill\MainBundle\Form\Type\TranslatableStringFormType @@ -39,9 +42,7 @@ services: tags: - { name: form.type, alias: select2_chill_language } - Chill\MainBundle\Form\Type\PickCenterType: - autowire: true - autoconfigure: true + Chill\MainBundle\Form\Type\PickCenterType: ~ chill.main.form.type.composed_role_scope: class: Chill\MainBundle\Form\Type\ComposedRoleScopeType @@ -62,9 +63,7 @@ services: tags: - { name: form.type } - Chill\MainBundle\Form\ChoiceLoader\PostalCodeChoiceLoader: - autowire: true - autoconfigure: true + Chill\MainBundle\Form\ChoiceLoader\PostalCodeChoiceLoader: ~ chill.main.form.type.export: class: Chill\MainBundle\Form\Type\Export\ExportType @@ -96,14 +95,10 @@ services: arguments: - '@Chill\MainBundle\Export\ExportManager' - Chill\MainBundle\Form\Type\DataTransformer\CenterTransformer: - autowire: true - autoconfigure: true + Chill\MainBundle\Form\Type\DataTransformer\CenterTransformer: ~ chill.main.form.advanced_search_type: class: Chill\MainBundle\Form\AdvancedSearchType - autowire: true - autoconfigure: true arguments: - "@chill_main.search_provider" tags: @@ -116,9 +111,7 @@ services: tags: - { name: form.type } - Chill\MainBundle\Form\UserType: - autowire: true - autoconfigure: true + Chill\MainBundle\Form\UserType: ~ Chill\MainBundle\Form\PermissionsGroupType: tags: @@ -131,15 +124,8 @@ services: tags: - { name: form.type } + Chill\MainBundle\Form\Type\PickAddressType: ~ - Chill\MainBundle\Form\Type\PickAddressType: - autoconfigure: true - autowire: true + Chill\MainBundle\Form\DataTransform\AddressToIdDataTransformer: ~ - Chill\MainBundle\Form\DataTransform\AddressToIdDataTransformer: - autoconfigure: true - autowire: true - - Chill\MainBundle\Form\Type\LocationFormType: - autowire: true - autoconfigure: true \ No newline at end of file + Chill\MainBundle\Form\Type\LocationFormType: ~ diff --git a/src/Bundle/ChillMainBundle/config/services/logger.yaml b/src/Bundle/ChillMainBundle/config/services/logger.yaml index 2da5a4a4c..a8c8dce58 100644 --- a/src/Bundle/ChillMainBundle/config/services/logger.yaml +++ b/src/Bundle/ChillMainBundle/config/services/logger.yaml @@ -1,4 +1,8 @@ services: + _defaults: + autowire: true + autoconfigure: true + chill.main.logger: # a logger to log events from the app (deletion, remove, etc.) alias: monolog.logger.chill diff --git a/src/Bundle/ChillMainBundle/config/services/menu.yaml b/src/Bundle/ChillMainBundle/config/services/menu.yaml index cf31dccf1..a41e90345 100644 --- a/src/Bundle/ChillMainBundle/config/services/menu.yaml +++ b/src/Bundle/ChillMainBundle/config/services/menu.yaml @@ -1,9 +1,11 @@ services: - Chill\MainBundle\Routing\MenuBuilder\: - resource: '../../Routing/MenuBuilder' + _defaults: autowire: true autoconfigure: true + Chill\MainBundle\Routing\MenuBuilder\: + resource: '../../Routing/MenuBuilder' + Chill\MainBundle\Routing\MenuBuilder\UserMenuBuilder: arguments: $tokenStorage: '@Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface' diff --git a/src/Bundle/ChillMainBundle/config/services/notification.yaml b/src/Bundle/ChillMainBundle/config/services/notification.yaml index c8d970c5d..efb25c5b5 100644 --- a/src/Bundle/ChillMainBundle/config/services/notification.yaml +++ b/src/Bundle/ChillMainBundle/config/services/notification.yaml @@ -1,4 +1,8 @@ services: + _defaults: + autowire: true + autoconfigure: true + Chill\MainBundle\Notification\Mailer: arguments: $logger: '@Psr\Log\LoggerInterface' @@ -9,6 +13,4 @@ services: $translator: '@Symfony\Component\Translation\TranslatorInterface' $routeParameters: '%chill_main.notifications%' - Chill\MainBundle\Notification\NotificationRenderer: - autoconfigure: true - autowire: true + Chill\MainBundle\Notification\NotificationRenderer: ~ diff --git a/src/Bundle/ChillMainBundle/config/services/pagination.yaml b/src/Bundle/ChillMainBundle/config/services/pagination.yaml index cb0855a3d..f94bc31be 100644 --- a/src/Bundle/ChillMainBundle/config/services/pagination.yaml +++ b/src/Bundle/ChillMainBundle/config/services/pagination.yaml @@ -1,9 +1,11 @@ services: + _defaults: + autowire: true + autoconfigure: true + chill_main.paginator_factory: class: Chill\MainBundle\Pagination\PaginatorFactory public: true - autowire: true - autoconfigure: true arguments: - "@request_stack" - "@router" diff --git a/src/Bundle/ChillMainBundle/config/services/phonenumber.yaml b/src/Bundle/ChillMainBundle/config/services/phonenumber.yaml index f297c03e0..46fa853ee 100644 --- a/src/Bundle/ChillMainBundle/config/services/phonenumber.yaml +++ b/src/Bundle/ChillMainBundle/config/services/phonenumber.yaml @@ -1,19 +1,21 @@ services: + _defaults: + autowire: true + autoconfigure: true + Chill\MainBundle\Phonenumber\PhonenumberHelper: arguments: - $logger: '@Psr\Log\LoggerInterface' $config: '%chill_main.phone_helper%' $cachePool: '@cache.user_data' - + Chill\MainBundle\Phonenumber\Templating: arguments: $phonenumberHelper: '@Chill\MainBundle\Phonenumber\PhonenumberHelper' tags: - { name: twig.extension } - + Chill\MainBundle\Validation\Validator\ValidPhonenumber: arguments: - $logger: '@Psr\Log\LoggerInterface' $phonenumberHelper: '@Chill\MainBundle\Phonenumber\PhonenumberHelper' tags: - { name: validator.constraint_validator } diff --git a/src/Bundle/ChillMainBundle/config/services/redis.yaml b/src/Bundle/ChillMainBundle/config/services/redis.yaml index c8d5c2879..6ccbfee7f 100644 --- a/src/Bundle/ChillMainBundle/config/services/redis.yaml +++ b/src/Bundle/ChillMainBundle/config/services/redis.yaml @@ -1,10 +1,13 @@ services: + _defaults: + autowire: true + autoconfigure: true + Chill\MainBundle\Redis\RedisConnectionFactory: arguments: $parameters: "%chill_main.redis%" tags: - { name: kernel.event_subcriber } - + Chill\MainBundle\Redis\ChillRedis: factory: [ '@Chill\MainBundle\Redis\RedisConnectionFactory', 'create' ] - \ No newline at end of file diff --git a/src/Bundle/ChillMainBundle/config/services/routing.yaml b/src/Bundle/ChillMainBundle/config/services/routing.yaml index c935f1a4d..fa8a56696 100644 --- a/src/Bundle/ChillMainBundle/config/services/routing.yaml +++ b/src/Bundle/ChillMainBundle/config/services/routing.yaml @@ -1,4 +1,8 @@ services: + _defaults: + autowire: true + autoconfigure: true + chill.main.menu_composer: class: Chill\MainBundle\Routing\MenuComposer arguments: @@ -6,7 +10,7 @@ services: - '@Knp\Menu\FactoryInterface' - '@Symfony\Component\Translation\TranslatorInterface' Chill\MainBundle\Routing\MenuComposer: '@chill.main.menu_composer' - + chill.main.routes_loader: class: Chill\MainBundle\Routing\Loader\ChillRoutesLoader arguments: diff --git a/src/Bundle/ChillMainBundle/config/services/search.yaml b/src/Bundle/ChillMainBundle/config/services/search.yaml index 38e421eaf..377b0655a 100644 --- a/src/Bundle/ChillMainBundle/config/services/search.yaml +++ b/src/Bundle/ChillMainBundle/config/services/search.yaml @@ -1,14 +1,14 @@ services: + _defaults: + autowire: true + autoconfigure: true + chill_main.search_provider: class: Chill\MainBundle\Search\SearchProvider Chill\MainBundle\Search\SearchProvider: '@chill_main.search_provider' - Chill\MainBundle\Search\SearchApi: - autowire: true - autoconfigure: true + Chill\MainBundle\Search\SearchApi: ~ Chill\MainBundle\Search\Entity\: - autowire: true - autoconfigure: true resource: '../../Search/Entity' diff --git a/src/Bundle/ChillMainBundle/config/services/security.yaml b/src/Bundle/ChillMainBundle/config/services/security.yaml index dc7949556..8dcd15f5d 100644 --- a/src/Bundle/ChillMainBundle/config/services/security.yaml +++ b/src/Bundle/ChillMainBundle/config/services/security.yaml @@ -12,37 +12,23 @@ services: arguments: - !tagged_iterator chill_main.scope_resolver - # do not autowire the directory Security/Resolver - Chill\MainBundle\Security\Resolver\DefaultCenterResolver: - autoconfigure: true - autowire: true + Chill\MainBundle\Security\Resolver\DefaultCenterResolver: ~ - Chill\MainBundle\Security\Resolver\DefaultScopeResolver: - autoconfigure: true - autowire: true + Chill\MainBundle\Security\Resolver\DefaultScopeResolver: ~ - # do not autowire the directory Security/Resolver - Chill\MainBundle\Security\Resolver\ResolverTwigExtension: - autoconfigure: true - autowire: true + Chill\MainBundle\Security\Resolver\ResolverTwigExtension: ~ - # do not autowire the directory Security/Resolver - Chill\MainBundle\Security\Authorization\DefaultVoterHelperFactory: - autowire: true + Chill\MainBundle\Security\Authorization\DefaultVoterHelperFactory: ~ # do not autowire the directory Security/Resolver Chill\MainBundle\Security\Authorization\VoterHelperFactoryInterface: '@Chill\MainBundle\Security\Authorization\DefaultVoterHelperFactory' chill.main.security.authorization.helper: class: Chill\MainBundle\Security\Authorization\AuthorizationHelper - autowire: true - autoconfigure: true Chill\MainBundle\Security\Authorization\AuthorizationHelper: '@chill.main.security.authorization.helper' Chill\MainBundle\Security\Authorization\AuthorizationHelperInterface: '@chill.main.security.authorization.helper' - Chill\MainBundle\Security\ParentRoleHelper: - autowire: true - autoconfigure: true + Chill\MainBundle\Security\ParentRoleHelper: ~ chill.main.role_provider: class: Chill\MainBundle\Security\RoleProvider @@ -62,12 +48,10 @@ services: Chill\MainBundle\Security\PasswordRecover\TokenManager: arguments: $secret: '%kernel.secret%' - $logger: '@Psr\Log\LoggerInterface' Chill\MainBundle\Security\PasswordRecover\RecoverPasswordHelper: arguments: $tokenManager: '@Chill\MainBundle\Security\PasswordRecover\TokenManager' - $urlGenerator: '@Symfony\Component\Routing\Generator\UrlGeneratorInterface' $mailer: '@Chill\MainBundle\Notification\Mailer' $routeParameters: "%chill_main.notifications%" @@ -80,11 +64,9 @@ services: Chill\MainBundle\Security\PasswordRecover\PasswordRecoverLocker: arguments: $chillRedis: '@Chill\MainBundle\Redis\ChillRedis' - $logger: '@Psr\Log\LoggerInterface' Chill\MainBundle\Security\PasswordRecover\PasswordRecoverVoter: arguments: $locker: '@Chill\MainBundle\Security\PasswordRecover\PasswordRecoverLocker' - $requestStack: '@Symfony\Component\HttpFoundation\RequestStack' tags: - { name: security.voter } diff --git a/src/Bundle/ChillMainBundle/config/services/serializer.yaml b/src/Bundle/ChillMainBundle/config/services/serializer.yaml index efe98996e..4d8aa9954 100644 --- a/src/Bundle/ChillMainBundle/config/services/serializer.yaml +++ b/src/Bundle/ChillMainBundle/config/services/serializer.yaml @@ -1,11 +1,13 @@ --- services: + _defaults: + autowire: true + autoconfigure: true # note: the autowiring for serializers and normalizers is declared # into ../services.yaml Chill\MainBundle\Serializer\Normalizer\DoctrineExistingEntityNormalizer: - autowire: true tags: - { name: 'serializer.normalizer', priority: 8 } diff --git a/src/Bundle/ChillMainBundle/config/services/templating.yaml b/src/Bundle/ChillMainBundle/config/services/templating.yaml index 02d806db4..ade26b946 100644 --- a/src/Bundle/ChillMainBundle/config/services/templating.yaml +++ b/src/Bundle/ChillMainBundle/config/services/templating.yaml @@ -1,4 +1,8 @@ services: + _defaults: + autowire: true + autoconfigure: true + # twig_intl: # class: Twig_Extensions_Extension_Intl # tags: @@ -32,8 +36,6 @@ services: - { name: twig.extension } Chill\MainBundle\Templating\Entity\CommentRender: - autoconfigure: true - autowire: true tags: - { name: 'chill.render_entity' } @@ -41,17 +43,11 @@ services: tags: - { name: twig.extension } - Chill\MainBundle\Templating\Entity\AddressRender: - autoconfigure: true - autowire: true + Chill\MainBundle\Templating\Entity\AddressRender: ~ - Chill\MainBundle\Templating\Entity\UserRender: - autoconfigure: true - autowire: true + Chill\MainBundle\Templating\Entity\UserRender: ~ Chill\MainBundle\Templating\Listing\: resource: './../../Templating/Listing' - autoconfigure: true - autowire: true Chill\MainBundle\Templating\Listing\FilterOrderHelperFactoryInterface: '@Chill\MainBundle\Templating\Listing\FilterOrderHelperFactory' diff --git a/src/Bundle/ChillMainBundle/config/services/timeline.yaml b/src/Bundle/ChillMainBundle/config/services/timeline.yaml index fe830c7ab..7b7987f5a 100644 --- a/src/Bundle/ChillMainBundle/config/services/timeline.yaml +++ b/src/Bundle/ChillMainBundle/config/services/timeline.yaml @@ -1,4 +1,8 @@ services: + _defaults: + autowire: true + autoconfigure: true + chill_main.timeline_builder: class: Chill\MainBundle\Timeline\TimelineBuilder arguments: diff --git a/src/Bundle/ChillMainBundle/config/services/validator.yaml b/src/Bundle/ChillMainBundle/config/services/validator.yaml index c15b2181e..b3b60b9d6 100644 --- a/src/Bundle/ChillMainBundle/config/services/validator.yaml +++ b/src/Bundle/ChillMainBundle/config/services/validator.yaml @@ -1,11 +1,15 @@ services: + _defaults: + autowire: true + autoconfigure: true + chill_main.validator_user_circle_consistency: class: Chill\MainBundle\Validator\Constraints\Entity\UserCircleConsistencyValidator arguments: - "@chill.main.security.authorization.helper" tags: - { name: "validator.constraint_validator" } - + Chill\MainBundle\Validation\Validator\UserUniqueEmailAndUsername: arguments: $em: '@Doctrine\ORM\EntityManagerInterface' diff --git a/src/Bundle/ChillMainBundle/config/services/widget.yaml b/src/Bundle/ChillMainBundle/config/services/widget.yaml index 53f29da5b..1f4bca2e3 100644 --- a/src/Bundle/ChillMainBundle/config/services/widget.yaml +++ b/src/Bundle/ChillMainBundle/config/services/widget.yaml @@ -1,2 +1,6 @@ services: + _defaults: + autowire: true + autoconfigure: true + Chill\MainBundle\Templating\UI\CountNotificationUser: ~ From cc9ce4167f64536bce26c21f57710d9c39df00db Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Thu, 18 Nov 2021 09:10:13 +0100 Subject: [PATCH 06/31] fix: Upgrade `TranslatableStringHelper` service and create its interface. --- .../Templating/TranslatableStringHelper.php | 110 ++++++------------ .../TranslatableStringHelperInterface.php | 17 +++ .../ChillMainBundle/config/services.yaml | 4 +- 3 files changed, 55 insertions(+), 76 deletions(-) create mode 100644 src/Bundle/ChillMainBundle/Templating/TranslatableStringHelperInterface.php diff --git a/src/Bundle/ChillMainBundle/Templating/TranslatableStringHelper.php b/src/Bundle/ChillMainBundle/Templating/TranslatableStringHelper.php index 673b87dbe..cbeb9514e 100644 --- a/src/Bundle/ChillMainBundle/Templating/TranslatableStringHelper.php +++ b/src/Bundle/ChillMainBundle/Templating/TranslatableStringHelper.php @@ -1,92 +1,56 @@ - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ + +declare(strict_types=1); namespace Chill\MainBundle\Templating; use Symfony\Component\HttpFoundation\RequestStack; -use Symfony\Component\Translation\Translator; +use Symfony\Contracts\Translation\TranslatorInterface; -/** - * - * This helper helps to find the string in current locale from translatable_strings - * - * @author Julien Fastré - * - */ -class TranslatableStringHelper +final class TranslatableStringHelper implements TranslatableStringHelperInterface { - /** - * - * @var RequestStack - */ - private $requestStack; - - private $fallbackLocales; - - public function __construct(RequestStack $requestStack, Translator $translator) + private RequestStack $requestStack; + + private TranslatorInterface $translator; + + public function __construct(RequestStack $requestStack, TranslatorInterface $translator) { $this->requestStack = $requestStack; - $this->fallbackLocales = $translator->getFallbackLocales(); + $this->translator = $translator; } - - /** - * return the string in current locale if it exists. - * - * If it does not exists; return the name in the first language available. - * - * Return a blank string if any strings are available. - * Return NULL if $translatableString is NULL - * - * @param array $translatableStrings - * @return string - */ - public function localize(array $translatableStrings) - { - if (NULL === $translatableStrings) { - return NULL; - } - - $language = $this->requestStack->getCurrentRequest()->getLocale(); - - if (isset($translatableStrings[$language])) { - - return $translatableStrings[$language]; - } else { - foreach ($this->fallbackLocales as $locale) { - if (array_key_exists($locale, $translatableStrings)) { - - return $translatableStrings[$locale]; - } - } - + public function localize(array $translatableStrings): ?string + { + if ([] === $translatableStrings) { + return null; } - + + $request = $this->requestStack->getCurrentRequest(); + + if (null === $request) { + return null; + } + + $language = $request->getLocale(); + + if (array_key_exists($language, $translatableStrings)) { + return $translatableStrings[$language]; + } + + foreach ($this->translator->getFallbackLocales() as $locale) { + if (array_key_exists($locale, $translatableStrings)) { + return $translatableStrings[$locale]; + } + } + // no fallback translation... trying the first available $langs = array_keys($translatableStrings); - - if (count($langs) === 0) { + + if ([] === $langs) { return ''; } - - return $translatableStrings[$langs[0]]; + return $translatableStrings[$langs[0]]; } -} \ No newline at end of file +} diff --git a/src/Bundle/ChillMainBundle/Templating/TranslatableStringHelperInterface.php b/src/Bundle/ChillMainBundle/Templating/TranslatableStringHelperInterface.php new file mode 100644 index 000000000..72e9397f8 --- /dev/null +++ b/src/Bundle/ChillMainBundle/Templating/TranslatableStringHelperInterface.php @@ -0,0 +1,17 @@ + Date: Thu, 18 Nov 2021 10:13:13 +0100 Subject: [PATCH 07/31] fix: Use `TranslatableStringHelperInterface`. --- .../ChillBudgetBundle/Form/ChargeType.php | 62 ++++++--------- .../ChillBudgetBundle/Form/ResourceType.php | 75 +++++++------------ .../Form/SocialWork/SocialIssueType.php | 56 +++----------- 3 files changed, 62 insertions(+), 131 deletions(-) diff --git a/src/Bundle/ChillBudgetBundle/Form/ChargeType.php b/src/Bundle/ChillBudgetBundle/Form/ChargeType.php index da219abb9..6d0b9c7b6 100644 --- a/src/Bundle/ChillBudgetBundle/Form/ChargeType.php +++ b/src/Bundle/ChillBudgetBundle/Form/ChargeType.php @@ -1,42 +1,34 @@ configRepository = $configRepository; $this->translatableStringHelper = $translatableStringHelper; } - public function buildForm(FormBuilderInterface $builder, array $options) { $builder @@ -45,24 +37,23 @@ class ChargeType extends AbstractType 'placeholder' => 'Choose a charge type' ]) ->add('amount', MoneyType::class) - ->add('comment', TextAreaType::class, [ + ->add('comment', TextareaType::class, [ 'required' => false - ]) - ; - + ]); + if ($options['show_start_date']) { $builder->add('startDate', ChillDateType::class, [ 'label' => 'Start of validity period' ]); } - + if ($options['show_end_date']) { $builder->add('endDate', ChillDateType::class, [ 'required' => false, 'label' => 'End of validity period' ]); } - + if ($options['show_help']) { $builder->add('help', ChoiceType::class, [ 'choices' => [ @@ -77,48 +68,39 @@ class ChargeType extends AbstractType ]); } } - + private function getTypes() { $charges = $this->configRepository ->getChargesLabels(); - + // rewrite labels to filter in language foreach ($charges as $key => $labels) { $charges[$key] = $this->translatableStringHelper->localize($labels); } - + \asort($charges); - + return \array_flip($charges); } - - /** - * {@inheritdoc} - */ + public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults(array( - 'data_class' => 'Chill\AMLI\BudgetBundle\Entity\Charge', + 'data_class' => Charge::class, 'show_start_date' => true, 'show_end_date' => true, 'show_help' => true )); - + $resolver ->setAllowedTypes('show_start_date', 'boolean') ->setAllowedTypes('show_end_date', 'boolean') - ->setAllowedTypes('show_help', 'boolean') - ; + ->setAllowedTypes('show_help', 'boolean'); } - /** - * {@inheritdoc} - */ public function getBlockPrefix() { return 'chill_amli_budgetbundle_charge'; } - - } diff --git a/src/Bundle/ChillBudgetBundle/Form/ResourceType.php b/src/Bundle/ChillBudgetBundle/Form/ResourceType.php index abf7191ab..2df9ee6d7 100644 --- a/src/Bundle/ChillBudgetBundle/Form/ResourceType.php +++ b/src/Bundle/ChillBudgetBundle/Form/ResourceType.php @@ -1,7 +1,10 @@ configRepository = $configRepository; $this->translatableStringHelper = $translatableStringHelper; } - public function buildForm(FormBuilderInterface $builder, array $options) { $builder @@ -45,17 +38,16 @@ class ResourceType extends AbstractType 'label' => 'Resource element type' ]) ->add('amount', MoneyType::class) - ->add('comment', TextAreaType::class, [ + ->add('comment', TextareaType::class, [ 'required' => false - ]) - ; - + ]); + if ($options['show_start_date']) { $builder->add('startDate', ChillDateType::class, [ 'label' => 'Start of validity period' ]); } - + if ($options['show_end_date']) { $builder->add('endDate', ChillDateType::class, [ 'required' => false, @@ -63,25 +55,7 @@ class ResourceType extends AbstractType ]); } } - - private function getTypes() - { - $resources = $this->configRepository - ->getResourcesLabels(); - - // rewrite labels to filter in language - foreach ($resources as $key => $labels) { - $resources[$key] = $this->translatableStringHelper->localize($labels); - } - - asort($resources); - - return \array_flip($resources); - } - - /** - * {@inheritdoc} - */ + public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults(array( @@ -89,20 +63,29 @@ class ResourceType extends AbstractType 'show_start_date' => true, 'show_end_date' => true )); - + $resolver ->setAllowedTypes('show_start_date', 'boolean') - ->setAllowedTypes('show_end_date', 'boolean') - ; + ->setAllowedTypes('show_end_date', 'boolean'); } - /** - * {@inheritdoc} - */ public function getBlockPrefix() { return 'chill_amli_budgetbundle_resource'; } + private function getTypes() + { + $resources = $this->configRepository + ->getResourcesLabels(); + // rewrite labels to filter in language + foreach ($resources as $key => $labels) { + $resources[$key] = $this->translatableStringHelper->localize($labels); + } + + asort($resources); + + return \array_flip($resources); + } } diff --git a/src/Bundle/ChillPersonBundle/Form/SocialWork/SocialIssueType.php b/src/Bundle/ChillPersonBundle/Form/SocialWork/SocialIssueType.php index 1f21defd9..f41d843c2 100644 --- a/src/Bundle/ChillPersonBundle/Form/SocialWork/SocialIssueType.php +++ b/src/Bundle/ChillPersonBundle/Form/SocialWork/SocialIssueType.php @@ -1,83 +1,49 @@ - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ + +declare(strict_types=1); + namespace Chill\PersonBundle\Form\SocialWork; +use Chill\MainBundle\Templating\TranslatableStringHelperInterface; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolver; use Chill\MainBundle\Form\Type\TranslatableStringFormType; use Symfony\Component\Form\Extension\Core\Type\DateType; -use Chill\MainBundle\Templating\TranslatableStringHelper; use Symfony\Bridge\Doctrine\Form\Type\EntityType; use Chill\PersonBundle\Entity\SocialWork\SocialIssue; -/** - * Class SocialIssueType - * - * @package Chill\PersonBundle\Form - */ class SocialIssueType extends AbstractType { - /** - * - * @var TranslatableStringHelper - */ - protected $translatableStringHelper; + protected TranslatableStringHelperInterface $translatableStringHelper; - public function __construct(TranslatableStringHelper $translatableStringHelper) { + public function __construct( + TranslatableStringHelperInterface $translatableStringHelper + ) { $this->translatableStringHelper = $translatableStringHelper; } - /** - * @param FormBuilderInterface $builder - * @param array $options - */ public function buildForm(FormBuilderInterface $builder, array $options) { $builder ->add('title', TranslatableStringFormType::class, [ 'label' => 'Nom' ]) - ->add('parent', EntityType::class, [ 'class' => SocialIssue::class, 'required' => false, - 'choice_label' => function (SocialIssue $issue) { - return $this->translatableStringHelper->localize($issue->getTitle()); - } + 'choice_label' => static fn (SocialIssue $issue): ?string => $this->translatableStringHelper->localize($issue->getTitle()) ]) - ->add('desactivationDate', DateType::class, [ 'attr' => ['class' => 'datepicker'], 'widget'=> 'single_text', 'format' => 'dd-MM-yyyy', 'required' => false, ]); -} + } - /** - * @param OptionsResolver $resolver - */ public function configureOptions(OptionsResolver $resolver) { - $resolver - ->setDefault('class', SocialIssue::class) - ; + $resolver->setDefault('class', SocialIssue::class); } } From 97ab71b63d9503cffbf47053d45df895f32be83c Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Thu, 18 Nov 2021 10:14:40 +0100 Subject: [PATCH 08/31] fix: Add missing repositories, fix typing information, autoload `Repository` directory. --- .../ActivityReasonCategoryRepository.php | 23 +++++++ .../Repository/ActivityReasonRepository.php | 23 +++++++ .../Repository/ActivityRepository.php | 60 ++++--------------- .../Repository/ActivityTypeRepository.php | 23 +++++++ .../ChillActivityBundle/config/services.yaml | 12 ++-- .../config/services/repositories.yaml | 28 ++------- 6 files changed, 94 insertions(+), 75 deletions(-) create mode 100644 src/Bundle/ChillActivityBundle/Repository/ActivityReasonCategoryRepository.php create mode 100644 src/Bundle/ChillActivityBundle/Repository/ActivityReasonRepository.php create mode 100644 src/Bundle/ChillActivityBundle/Repository/ActivityTypeRepository.php diff --git a/src/Bundle/ChillActivityBundle/Repository/ActivityReasonCategoryRepository.php b/src/Bundle/ChillActivityBundle/Repository/ActivityReasonCategoryRepository.php new file mode 100644 index 000000000..3026105b0 --- /dev/null +++ b/src/Bundle/ChillActivityBundle/Repository/ActivityReasonCategoryRepository.php @@ -0,0 +1,23 @@ +, - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ +declare(strict_types=1); namespace Chill\ActivityBundle\Repository; @@ -29,10 +11,10 @@ use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; use Doctrine\Persistence\ManagerRegistry; /** - * @method AccompanyingPeriodParticipation|null find($id, $lockMode = null, $lockVersion = null) - * @method AccompanyingPeriodParticipation|null findOneBy(array $criteria, array $orderBy = null) - * @method AccompanyingPeriodParticipation[] findAll() - * @method AccompanyingPeriodParticipation[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) + * @method Activity|null find($id, $lockMode = null, $lockVersion = null) + * @method Activity|null findOneBy(array $criteria, array $orderBy = null) + * @method Activity[] findAll() + * @method Activity[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) */ class ActivityRepository extends ServiceEntityRepository { @@ -42,12 +24,7 @@ class ActivityRepository extends ServiceEntityRepository } /** - * @param $person - * @param array $scopes - * @param string[] $orderBy - * @param int $limit - * @param int $offset - * @return array|Activity[] + * @return Activity[] */ public function findByPersonImplied(Person $person, array $scopes, ?array $orderBy = [ 'date' => 'DESC'], ?int $limit = 100, ?int $offset = 0): array { @@ -63,8 +40,7 @@ class ActivityRepository extends ServiceEntityRepository ':person MEMBER OF a.persons' ) ) - ->setParameter('person', $person) - ; + ->setParameter('person', $person); foreach ($orderBy as $k => $dir) { $qb->addOrderBy('a.'.$k, $dir); @@ -72,17 +48,11 @@ class ActivityRepository extends ServiceEntityRepository $qb->setMaxResults($limit)->setFirstResult($offset); - return $qb->getQuery() - ->getResult(); + return $qb->getQuery()->getResult(); } /** - * @param AccompanyingPeriod $period - * @param array $scopes - * @param int|null $limit - * @param int|null $offset - * @param array|string[] $orderBy - * @return array|Activity[] + * @return Activity[] */ public function findByAccompanyingPeriod(AccompanyingPeriod $period, array $scopes, ?bool $allowNullScope = false, ?int $limit = 100, ?int $offset = 0, array $orderBy = ['date' => 'desc']): array { @@ -92,8 +62,7 @@ class ActivityRepository extends ServiceEntityRepository if (!$allowNullScope) { $qb ->where($qb->expr()->in('a.scope', ':scopes')) - ->setParameter('scopes', $scopes) - ; + ->setParameter('scopes', $scopes); } else { $qb ->where( @@ -102,16 +71,14 @@ class ActivityRepository extends ServiceEntityRepository $qb->expr()->isNull('a.scope') ) ) - ->setParameter('scopes', $scopes) - ; + ->setParameter('scopes', $scopes); } $qb ->andWhere( $qb->expr()->eq('a.accompanyingPeriod', ':period') ) - ->setParameter('period', $period) - ; + ->setParameter('period', $period); foreach ($orderBy as $k => $dir) { $qb->addOrderBy('a.'.$k, $dir); @@ -119,7 +86,6 @@ class ActivityRepository extends ServiceEntityRepository $qb->setMaxResults($limit)->setFirstResult($offset); - return $qb->getQuery() - ->getResult(); + return $qb->getQuery()->getResult(); } } diff --git a/src/Bundle/ChillActivityBundle/Repository/ActivityTypeRepository.php b/src/Bundle/ChillActivityBundle/Repository/ActivityTypeRepository.php new file mode 100644 index 000000000..5e4076ce5 --- /dev/null +++ b/src/Bundle/ChillActivityBundle/Repository/ActivityTypeRepository.php @@ -0,0 +1,23 @@ + Date: Thu, 18 Nov 2021 10:15:27 +0100 Subject: [PATCH 09/31] fix: Inject newly created repository instead of having to deal with the container definitions. --- .../PersonHavingActivityBetweenDateFilter.php | 183 +++++++----------- .../Form/Type/TranslatableActivityType.php | 58 ++---- 2 files changed, 89 insertions(+), 152 deletions(-) diff --git a/src/Bundle/ChillActivityBundle/Export/Filter/PersonHavingActivityBetweenDateFilter.php b/src/Bundle/ChillActivityBundle/Export/Filter/PersonHavingActivityBetweenDateFilter.php index cf444bd0a..8773c95a0 100644 --- a/src/Bundle/ChillActivityBundle/Export/Filter/PersonHavingActivityBetweenDateFilter.php +++ b/src/Bundle/ChillActivityBundle/Export/Filter/PersonHavingActivityBetweenDateFilter.php @@ -1,25 +1,14 @@ - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ +declare(strict_types=1); namespace Chill\ActivityBundle\Export\Filter; +use Chill\ActivityBundle\Repository\ActivityReasonRepository; use Chill\MainBundle\Export\FilterInterface; +use Chill\MainBundle\Templating\TranslatableStringHelperInterface; +use Doctrine\ORM\QueryBuilder; +use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormEvent; use Symfony\Component\Form\FormEvents; use Symfony\Component\Form\Extension\Core\Type\DateType; @@ -29,78 +18,58 @@ use Doctrine\ORM\Query\Expr; use Chill\MainBundle\Templating\TranslatableStringHelper; use Symfony\Bridge\Doctrine\Form\Type\EntityType; use Chill\ActivityBundle\Entity\ActivityReason; -use Doctrine\ORM\EntityRepository; -use Doctrine\ORM\EntityManager; use Chill\PersonBundle\Export\Declarations; +use Symfony\Component\Form\FormInterface; use Symfony\Component\Translation\TranslatorInterface; use Symfony\Component\Validator\Context\ExecutionContextInterface; use Chill\MainBundle\Export\ExportElementValidatedInterface; -/** - * - * - * @author Julien Fastré - */ -class PersonHavingActivityBetweenDateFilter implements FilterInterface, - ExportElementValidatedInterface +class PersonHavingActivityBetweenDateFilter implements FilterInterface, ExportElementValidatedInterface { - - /** - * - * @var TranslatableStringHelper - */ - protected $translatableStringHelper; - - /** - * - * @var EntityRepository - */ - protected $activityReasonRepository; - - /** - * - * @var TranslatorInterface - */ - protected $translator; - + protected TranslatableStringHelperInterface $translatableStringHelper; + + protected ActivityReasonRepository $activityReasonRepository; + + protected TranslatorInterface $translator; + public function __construct( TranslatableStringHelper $translatableStringHelper, - EntityRepository $activityReasonRepository, + ActivityReasonRepository $activityReasonRepository, TranslatorInterface $translator ) { $this->translatableStringHelper = $translatableStringHelper; $this->activityReasonRepository = $activityReasonRepository; - $this->translator = $translator; + $this->translator = $translator; } - public function addRole() { return null; } - public function alterQuery(\Doctrine\ORM\QueryBuilder $qb, $data) + public function alterQuery(QueryBuilder $qb, $data) { // create a query for activity $sqb = $qb->getEntityManager()->createQueryBuilder(); - $sqb->select("person_person_having_activity.id") - ->from("ChillActivityBundle:Activity", "activity_person_having_activity") - ->join("activity_person_having_activity.person", "person_person_having_activity") - ; + $sqb->select('person_person_having_activity.id') + ->from('ChillActivityBundle:Activity', 'activity_person_having_activity') + ->join('activity_person_having_activity.person', 'person_person_having_activity'); + // add clause between date - $sqb->where("activity_person_having_activity.date BETWEEN " - . ":person_having_activity_between_date_from" - . " AND " - . ":person_having_activity_between_date_to"); + $sqb->where('activity_person_having_activity.date BETWEEN ' + . ':person_having_activity_between_date_from' + . ' AND ' + . ':person_having_activity_between_date_to'); + // add clause activity reason - $sqb->join('activity_person_having_activity.reasons', - 'reasons_person_having_activity'); + $sqb->join('activity_person_having_activity.reasons', 'reasons_person_having_activity'); + $sqb->andWhere( - $sqb->expr()->in( - 'reasons_person_having_activity', - ":person_having_activity_reasons") - ); - + $sqb->expr()->in( + 'reasons_person_having_activity', ':person_having_activity_reasons' + ) + ); + $where = $qb->getDQLPart('where'); $clause = $qb->expr()->in('person.id', $sqb->getDQL()); @@ -109,11 +78,11 @@ class PersonHavingActivityBetweenDateFilter implements FilterInterface, } else { $where = $qb->expr()->andX($clause); } - + $qb->add('where', $where); - $qb->setParameter('person_having_activity_between_date_from', + $qb->setParameter('person_having_activity_between_date_from', $data['date_from']); - $qb->setParameter('person_having_activity_between_date_to', + $qb->setParameter('person_having_activity_between_date_to', $data['date_to']); $qb->setParameter('person_having_activity_reasons', $data['reasons']); } @@ -123,51 +92,45 @@ class PersonHavingActivityBetweenDateFilter implements FilterInterface, return Declarations::PERSON_IMPLIED_IN; } - public function buildForm(\Symfony\Component\Form\FormBuilderInterface $builder) + public function buildForm(FormBuilderInterface $builder) { - $builder->add('date_from', DateType::class, array( - 'label' => "Implied in an activity after this date", + $builder->add('date_from', DateType::class, [ + 'label' => 'Implied in an activity after this date', 'data' => new \DateTime(), - 'attr' => array('class' => 'datepicker'), + 'attr' => ['class' => 'datepicker'], 'widget'=> 'single_text', 'format' => 'dd-MM-yyyy', - )); - - $builder->add('date_to', DateType::class, array( - 'label' => "Implied in an activity before this date", + ]); + + $builder->add('date_to', DateType::class, [ + 'label' => 'Implied in an activity before this date', 'data' => new \DateTime(), - 'attr' => array('class' => 'datepicker'), + 'attr' => ['class' => 'datepicker'], 'widget'=> 'single_text', 'format' => 'dd-MM-yyyy', - )); - - $builder->add('reasons', EntityType::class, array( - 'class' => 'ChillActivityBundle:ActivityReason', - 'choice_label' => function (ActivityReason $reason) { - return $this->translatableStringHelper - ->localize($reason->getName()); - }, - 'group_by' => function(ActivityReason $reason) { - return $this->translatableStringHelper - ->localize($reason->getCategory()->getName()); - }, + ]); + + $builder->add('reasons', EntityType::class, [ + 'class' => ActivityReason::class, + 'choice_label' => static fn (ActivityReason $reason): ?string => $this->translatableStringHelper->localize($reason->getName()), + 'group_by' => static fn(ActivityReason $reason): ?string => $this->translatableStringHelper->localize($reason->getCategory()->getName()), 'data' => $this->activityReasonRepository->findAll(), 'multiple' => true, 'expanded' => false, - 'label' => "Activity reasons for those activities" - )); - + 'label' => 'Activity reasons for those activities' + ]); + $builder->addEventListener(FormEvents::POST_SUBMIT, function(FormEvent $event) { - /* @var $filterForm \Symfony\Component\Form\FormInterface */ + /* @var FormInterface $filterForm */ $filterForm = $event->getForm()->getParent(); $enabled = $filterForm->get(FilterType::ENABLED_FIELD)->getData(); - + if ($enabled === true) { // if the filter is enabled, add some validation $form = $event->getForm(); $date_from = $form->get('date_from')->getData(); $date_to = $form->get('date_to')->getData(); - + // check that fields are not empty if ($date_from === null) { $form->get('date_from')->addError(new FormError( @@ -178,8 +141,8 @@ class PersonHavingActivityBetweenDateFilter implements FilterInterface, $form->get('date_to')->addError(new FormError( $this->translator->trans('This field ' . 'should not be empty'))); - } - + } + // check that date_from is before date_to if ( ($date_from !== null && $date_to !== null) @@ -194,30 +157,32 @@ class PersonHavingActivityBetweenDateFilter implements FilterInterface, } }); } - + public function validateForm($data, ExecutionContextInterface $context) { if ($data['reasons'] === null || count($data['reasons']) === 0) { - $context->buildViolation("At least one reason must be choosen") + $context->buildViolation('At least one reason must be chosen') ->addViolation(); } } public function describeAction($data, $format = 'string') { - return array( - "Filtered by person having an activity between %date_from% and " - . "%date_to% with reasons %reasons_name%", - array( - "%date_from%" => $data['date_from']->format('d-m-Y'), + return [ + 'Filtered by person having an activity between %date_from% and ' + . '%date_to% with reasons %reasons_name%', + [ + '%date_from%' => $data['date_from']->format('d-m-Y'), '%date_to%' => $data['date_to']->format('d-m-Y'), - "%reasons_name%" => implode(", ", array_map( - function (ActivityReason $r) { - return '"'.$this->translatableStringHelper-> - localize($r->getName()).'"'; - }, - $data['reasons'])) - )); + '%reasons_name%' => implode( + ", ", + array_map( + static fn(ActivityReason $r): string => '"' . $this->translatableStringHelper->localize($r->getName()) . '"', + $data['reasons'] + ) + ) + ] + ]; } public function getTitle() diff --git a/src/Bundle/ChillActivityBundle/Form/Type/TranslatableActivityType.php b/src/Bundle/ChillActivityBundle/Form/Type/TranslatableActivityType.php index fa4b23212..f930d3c1a 100644 --- a/src/Bundle/ChillActivityBundle/Form/Type/TranslatableActivityType.php +++ b/src/Bundle/ChillActivityBundle/Form/Type/TranslatableActivityType.php @@ -1,56 +1,29 @@ , - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ +declare(strict_types=1); namespace Chill\ActivityBundle\Form\Type; +use Chill\ActivityBundle\Repository\ActivityTypeRepository; +use Chill\MainBundle\Templating\TranslatableStringHelperInterface; +use Doctrine\DBAL\Types\Types; +use Doctrine\ORM\QueryBuilder; use Symfony\Component\Form\AbstractType; +use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolver; -use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Bridge\Doctrine\Form\Type\EntityType; -use Chill\MainBundle\Templating\TranslatableStringHelper; -use Doctrine\ORM\EntityRepository; use Chill\ActivityBundle\Entity\ActivityType; -/** - * Description of TranslatableActivityType - * - * @author Champs-Libres Coop - */ class TranslatableActivityType extends AbstractType { + protected TranslatableStringHelperInterface $translatableStringHelper; - /** - * - * @var TranslatableStringHelper - */ - protected $translatableStringHelper; - - protected $activityTypeRepository; + protected ActivityTypeRepository $activityTypeRepository; public function __construct( - TranslatableStringHelper $helper, - EntityRepository $activityTypeRepository - ) - { + TranslatableStringHelperInterface $helper, + ActivityTypeRepository $activityTypeRepository + ) { $this->translatableStringHelper = $helper; $this->activityTypeRepository = $activityTypeRepository; } @@ -65,22 +38,21 @@ class TranslatableActivityType extends AbstractType return EntityType::class; } - public function buildForm(\Symfony\Component\Form\FormBuilderInterface $builder, array $options) { - /* @var $qb \Doctrine\ORM\QueryBuilder */ + public function buildForm(FormBuilderInterface $builder, array $options) { + /* @var QueryBuilder $qb */ $qb = $options['query_builder']; if ($options['active_only'] === true) { $qb->where($qb->expr()->eq('at.active', ':active')); - $qb->setParameter('active', true, \Doctrine\DBAL\Types\Types::BOOLEAN); + $qb->setParameter('active', true, Types::BOOLEAN); } } public function configureOptions(OptionsResolver $resolver) { - $resolver->setDefaults( array( - 'class' => 'ChillActivityBundle:ActivityType', + 'class' => ActivityType::class, 'active_only' => true, 'query_builder' => $this->activityTypeRepository ->createQueryBuilder('at'), From d9b862925f11d9c530fe4c77ccecc69daaab1c89 Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Thu, 18 Nov 2021 10:28:22 +0100 Subject: [PATCH 10/31] fix: Let Symfony inject dependencies automatically. --- .../Aggregator/ActivityReasonAggregator.php | 143 +++++++----------- .../Aggregator/ActivityTypeAggregator.php | 60 ++------ .../Aggregator/ActivityUserAggregator.php | 68 +++------ .../Export/Export/CountActivity.php | 96 ++++-------- .../Export/Export/ListActivity.php | 139 ++++++----------- .../Export/Export/StatActivityDuration.php | 22 +-- .../Export/Filter/ActivityReasonFilter.php | 116 +++++--------- .../Export/Filter/ActivityTypeFilter.php | 114 ++++++-------- .../config/services/export.yaml | 50 ++---- 9 files changed, 282 insertions(+), 526 deletions(-) diff --git a/src/Bundle/ChillActivityBundle/Export/Aggregator/ActivityReasonAggregator.php b/src/Bundle/ChillActivityBundle/Export/Aggregator/ActivityReasonAggregator.php index 6614caace..3e5cab378 100644 --- a/src/Bundle/ChillActivityBundle/Export/Aggregator/ActivityReasonAggregator.php +++ b/src/Bundle/ChillActivityBundle/Export/Aggregator/ActivityReasonAggregator.php @@ -1,70 +1,39 @@ - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ +declare(strict_types=1); namespace Chill\ActivityBundle\Export\Aggregator; +use Chill\ActivityBundle\Repository\ActivityReasonCategoryRepository; +use Chill\ActivityBundle\Repository\ActivityReasonRepository; +use Chill\MainBundle\Templating\TranslatableStringHelperInterface; use Symfony\Component\Form\FormBuilderInterface; use Doctrine\ORM\QueryBuilder; use Chill\MainBundle\Export\AggregatorInterface; use Symfony\Component\Security\Core\Role\Role; use Chill\ActivityBundle\Security\Authorization\ActivityStatsVoter; -use Doctrine\ORM\EntityRepository; use Chill\MainBundle\Templating\TranslatableStringHelper; use Doctrine\ORM\Query\Expr\Join; use Chill\MainBundle\Export\ExportElementValidatedInterface; use Symfony\Component\Validator\Context\ExecutionContextInterface; use Symfony\Component\Form\Extension\Core\Type\ChoiceType; -/** - * - * - * @author Julien Fastré - */ -class ActivityReasonAggregator implements AggregatorInterface, - ExportElementValidatedInterface +class ActivityReasonAggregator implements AggregatorInterface, ExportElementValidatedInterface { - /** - * - * @var EntityRepository - */ - protected $categoryRepository; + protected ActivityReasonCategoryRepository $activityReasonCategoryRepository; - /** - * - * @var EntityRepository - */ - protected $reasonRepository; + protected ActivityReasonRepository $activityReasonRepository; - /** - * - * @var TranslatableStringHelper - */ - protected $stringHelper; + protected TranslatableStringHelperInterface $translatableStringHelper; public function __construct( - EntityRepository $categoryRepository, - EntityRepository $reasonRepository, - TranslatableStringHelper $stringHelper + ActivityReasonCategoryRepository $activityReasonCategoryRepository, + ActivityReasonRepository $activityReasonRepository, + TranslatableStringHelper $translatableStringHelper ) { - $this->categoryRepository = $categoryRepository; - $this->reasonRepository = $reasonRepository; - $this->stringHelper = $stringHelper; + $this->activityReasonCategoryRepository = $activityReasonCategoryRepository; + $this->activityReasonRepository = $activityReasonRepository; + $this->translatableStringHelper = $translatableStringHelper; } public function alterQuery(QueryBuilder $qb, $data) @@ -77,7 +46,7 @@ class ActivityReasonAggregator implements AggregatorInterface, $elem = 'category.id'; $alias = 'activity_categories_id'; } else { - throw new \RuntimeException('the data provided are not recognized'); + throw new \RuntimeException('The data provided are not recognized.'); } $qb->addSelect($elem.' as '.$alias); @@ -93,11 +62,12 @@ class ActivityReasonAggregator implements AggregatorInterface, (! array_key_exists('activity', $join)) ) { $qb->add( - 'join', - array('activity' => - new Join(Join::INNER_JOIN, 'activity.reasons', 'reasons') - ), - true); + 'join', + [ + 'activity' => new Join(Join::INNER_JOIN, 'activity.reasons', 'reasons') + ], + true + ); } // join category if necessary @@ -143,28 +113,33 @@ class ActivityReasonAggregator implements AggregatorInterface, public function buildForm(FormBuilderInterface $builder) { - $builder->add('level', ChoiceType::class, array( - 'choices' => array( - 'By reason' => 'reasons', - 'By category of reason' => 'categories' - ), - 'multiple' => false, - 'expanded' => true, - 'label' => 'Reason\'s level' - )); + $builder->add( + 'level', + ChoiceType::class, + [ + 'choices' => [ + 'By reason' => 'reasons', + 'By category of reason' => 'categories' + ], + 'multiple' => false, + 'expanded' => true, + 'label' => "Reason's level" + ] + ); } public function validateForm($data, ExecutionContextInterface $context) { if ($data['level'] === null) { - $context->buildViolation("The reasons's level should not be empty") + $context + ->buildViolation("The reasons's level should not be empty.") ->addViolation(); } } - public function getTitle() + public function getTitle() { - return "Aggregate by activity reason"; + return 'Aggregate by activity reason'; } public function addRole() @@ -177,41 +152,33 @@ class ActivityReasonAggregator implements AggregatorInterface, // for performance reason, we load data from db only once switch ($data['level']) { case 'reasons': - $this->reasonRepository->findBy(array('id' => $values)); + $this->activityReasonRepository->findBy(['id' => $values]); break; case 'categories': - $this->categoryRepository->findBy(array('id' => $values)); + $this->activityReasonCategoryRepository->findBy(['id' => $values]); break; default: - throw new \RuntimeException(sprintf("the level data '%s' is invalid", - $data['level'])); + throw new \RuntimeException(sprintf("The level data '%s' is invalid.", $data['level'])); } return function($value) use ($data) { if ($value === '_header') { - return $data['level'] === 'reasons' ? - 'Group by reasons' - : - 'Group by categories of reason' - ; + return $data['level'] === 'reasons' ? 'Group by reasons' : 'Group by categories of reason'; } switch ($data['level']) { case 'reasons': - /* @var $r \Chill\ActivityBundle\Entity\ActivityReason */ - $r = $this->reasonRepository->find($value); + $r = $this->activityReasonRepository->find($value); - return $this->stringHelper->localize($r->getCategory()->getName()) - ." > " - . $this->stringHelper->localize($r->getName()); - ; - break; + return sprintf( + "%s > %s", + $this->translatableStringHelper->localize($r->getCategory()->getName()), + $this->translatableStringHelper->localize($r->getName()) + ); case 'categories': - $c = $this->categoryRepository->find($value); + $c = $this->activityReasonCategoryRepository->find($value); - return $this->stringHelper->localize($c->getName()); - break; - // no need for a default : the default was already set above + return $this->translatableStringHelper->localize($c->getName()); } }; @@ -222,12 +189,14 @@ class ActivityReasonAggregator implements AggregatorInterface, // add select element if ($data['level'] === 'reasons') { return array('activity_reasons_id'); - } elseif ($data['level'] === 'categories') { - return array ('activity_categories_id'); - } else { - throw new \RuntimeException('the data provided are not recognised'); } + if ($data['level'] === 'categories') { + return array ('activity_categories_id'); + } + + throw new \RuntimeException('The data provided are not recognised.'); + } } diff --git a/src/Bundle/ChillActivityBundle/Export/Aggregator/ActivityTypeAggregator.php b/src/Bundle/ChillActivityBundle/Export/Aggregator/ActivityTypeAggregator.php index a0e6d3966..bd90e8eb6 100644 --- a/src/Bundle/ChillActivityBundle/Export/Aggregator/ActivityTypeAggregator.php +++ b/src/Bundle/ChillActivityBundle/Export/Aggregator/ActivityTypeAggregator.php @@ -1,61 +1,32 @@ - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ +declare(strict_types=1); namespace Chill\ActivityBundle\Export\Aggregator; +use Chill\ActivityBundle\Repository\ActivityTypeRepository; +use Chill\MainBundle\Templating\TranslatableStringHelperInterface; use Symfony\Component\Form\FormBuilderInterface; use Doctrine\ORM\QueryBuilder; use Chill\MainBundle\Export\AggregatorInterface; use Symfony\Component\Security\Core\Role\Role; use Chill\ActivityBundle\Security\Authorization\ActivityStatsVoter; -use Doctrine\ORM\EntityRepository; -use Chill\MainBundle\Templating\TranslatableStringHelper; use Doctrine\ORM\Query\Expr\Join; -/** - * - * - * @author Julien Fastré - */ class ActivityTypeAggregator implements AggregatorInterface { + protected ActivityTypeRepository $activityTypeRepository; - /** - * - * @var EntityRepository - */ - protected $typeRepository; + protected TranslatableStringHelperInterface $translatableStringHelper; - /** - * - * @var TranslatableStringHelper - */ - protected $stringHelper; - - const KEY = 'activity_type_aggregator'; + public const KEY = 'activity_type_aggregator'; public function __construct( - EntityRepository $typeRepository, - TranslatableStringHelper $stringHelper + ActivityTypeRepository $activityTypeRepository, + TranslatableStringHelperInterface $translatableStringHelper ) { - $this->typeRepository = $typeRepository; - $this->stringHelper = $stringHelper; + $this->activityTypeRepository = $activityTypeRepository; + $this->translatableStringHelper = $translatableStringHelper; } public function alterQuery(QueryBuilder $qb, $data) @@ -64,7 +35,7 @@ class ActivityTypeAggregator implements AggregatorInterface $qb->addSelect(sprintf('IDENTITY(activity.type) AS %s', self::KEY)); // add the "group by" part - $groupBy = $qb->addGroupBy(self::KEY); + $qb->addGroupBy(self::KEY); } /** @@ -97,7 +68,7 @@ class ActivityTypeAggregator implements AggregatorInterface public function getTitle() { - return "Aggregate by activity type"; + return 'Aggregate by activity type'; } public function addRole() @@ -108,17 +79,16 @@ class ActivityTypeAggregator implements AggregatorInterface public function getLabels($key, array $values, $data): \Closure { // for performance reason, we load data from db only once - $this->typeRepository->findBy(array('id' => $values)); + $this->activityTypeRepository->findBy(['id' => $values]); return function($value): string { if ($value === '_header') { return 'Activity type'; } - /* @var $r \Chill\ActivityBundle\Entity\ActivityType */ - $t = $this->typeRepository->find($value); + $t = $this->activityTypeRepository->find($value); - return $this->stringHelper->localize($t->getName()); + return $this->translatableStringHelper->localize($t->getName()); }; } diff --git a/src/Bundle/ChillActivityBundle/Export/Aggregator/ActivityUserAggregator.php b/src/Bundle/ChillActivityBundle/Export/Aggregator/ActivityUserAggregator.php index ca01e0ae5..8e4635ef2 100644 --- a/src/Bundle/ChillActivityBundle/Export/Aggregator/ActivityUserAggregator.php +++ b/src/Bundle/ChillActivityBundle/Export/Aggregator/ActivityUserAggregator.php @@ -1,51 +1,26 @@ - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ + namespace Chill\ActivityBundle\Export\Aggregator; +use Chill\MainBundle\Repository\UserRepository; use Symfony\Component\Form\FormBuilderInterface; use Doctrine\ORM\QueryBuilder; use Chill\MainBundle\Export\AggregatorInterface; use Symfony\Component\Security\Core\Role\Role; -use Doctrine\ORM\Query\Expr\Join; use Chill\ActivityBundle\Security\Authorization\ActivityStatsVoter; -use Doctrine\ORM\EntityManagerInterface; -use Chill\MainBundle\Entity\User; -/** - * - * - * @author Julien Fastré - */ class ActivityUserAggregator implements AggregatorInterface { - /** - * - * @var EntityManagerInterface - */ - protected $em; - - const KEY = 'activity_user_id'; - - function __construct(EntityManagerInterface $em) - { - $this->em = $em; + public const KEY = 'activity_user_id'; + + private UserRepository $userRepository; + + public function __construct( + UserRepository $userRepository + ) { + $this->userRepository = $userRepository; } - + public function addRole() { return new Role(ActivityStatsVoter::STATS); @@ -53,9 +28,9 @@ class ActivityUserAggregator implements AggregatorInterface public function alterQuery(QueryBuilder $qb, $data) { - // add select element + // add select element $qb->addSelect(sprintf('IDENTITY(activity.user) AS %s', self::KEY)); - + // add the "group by" part $qb->addGroupBy(self::KEY); } @@ -73,17 +48,14 @@ class ActivityUserAggregator implements AggregatorInterface public function getLabels($key, $values, $data): \Closure { // preload users at once - $this->em->getRepository(User::class) - ->findBy(['id' => $values]); - + $this->userRepository->findBy(['id' => $values]); + return function($value) { - switch ($value) { - case '_header': - return 'activity user'; - default: - return $this->em->getRepository(User::class)->find($value) - ->getUsername(); + if ($value === '_header') { + return 'activity user'; } + + return $this->userRepository->find($value)->getUsername(); }; } @@ -94,6 +66,6 @@ class ActivityUserAggregator implements AggregatorInterface public function getTitle(): string { - return "Aggregate by activity user"; + return 'Aggregate by activity user'; } } diff --git a/src/Bundle/ChillActivityBundle/Export/Export/CountActivity.php b/src/Bundle/ChillActivityBundle/Export/Export/CountActivity.php index 3498d7a13..3d5d798f8 100644 --- a/src/Bundle/ChillActivityBundle/Export/Export/CountActivity.php +++ b/src/Bundle/ChillActivityBundle/Export/Export/CountActivity.php @@ -1,64 +1,40 @@ - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ +declare(strict_types=1); namespace Chill\ActivityBundle\Export\Export; +use Chill\ActivityBundle\Repository\ActivityRepository; use Chill\MainBundle\Export\ExportInterface; -use Doctrine\ORM\QueryBuilder; +use Chill\MainBundle\Export\FormatterInterface; +use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Security\Core\Role\Role; use Doctrine\ORM\Query; use Chill\ActivityBundle\Security\Authorization\ActivityStatsVoter; -use Doctrine\ORM\EntityManagerInterface; -/** - * - * - * @author Julien Fastré - */ class CountActivity implements ExportInterface { - /** - * - * @var EntityManagerInterface - */ - protected $entityManager; - + protected ActivityRepository $activityRepository; + public function __construct( - EntityManagerInterface $em - ) - { - $this->entityManager = $em; + ActivityRepository $activityRepository + ) { + $this->activityRepository = $activityRepository; } - - public function buildForm(\Symfony\Component\Form\FormBuilderInterface $builder) + + public function buildForm(FormBuilderInterface $builder) { - + } public function getDescription() { - return "Count activities by various parameters."; + return 'Count activities by various parameters.'; } public function getTitle() { - return "Count activities"; + return 'Count activities'; } public function getType() @@ -68,26 +44,26 @@ class CountActivity implements ExportInterface public function initiateQuery(array $requiredModifiers, array $acl, array $data = array()) { - $qb = $this->entityManager->createQueryBuilder(); - $centers = array_map(function($el) { return $el['center']; }, $acl); - - $qb->select('COUNT(activity.id) as export_count_activity') - ->from('ChillActivityBundle:Activity', 'activity') - ->join('activity.person', 'person') - ; - - $qb->where($qb->expr()->in('person.center', ':centers')) - ->setParameter('centers', $centers) - ; - + $centers = array_map(static fn($el) => $el['center'], $acl); + + $qb = $this + ->activityRepository + ->createQueryBuilder('activity') + ->select('COUNT(activity.id) as export_count_activity') + ->join('activity.person', 'person'); + + $qb + ->where($qb->expr()->in('person.center', ':centers')) + ->setParameter('centers', $centers); + return $qb; } - + public function supportsModifiers() { - return array('person', 'activity'); + return ['person', 'activity']; } - + public function requiredRole() { return new Role(ActivityStatsVoter::STATS); @@ -95,7 +71,7 @@ class CountActivity implements ExportInterface public function getAllowedFormattersTypes() { - return array(\Chill\MainBundle\Export\FormatterInterface::TYPE_TABULAR); + return [FormatterInterface::TYPE_TABULAR]; } public function getLabels($key, array $values, $data) @@ -103,19 +79,13 @@ class CountActivity implements ExportInterface if ($key !== 'export_count_activity') { throw new \LogicException("the key $key is not used by this export"); } - - return function($value) { - return $value === '_header' ? - 'Number of activities' - : - $value - ; - }; + + return static fn($value) => $value === '_header' ? 'Number of activities' : $value; } public function getQueryKeys($data) { - return array('export_count_activity'); + return ['export_count_activity']; } public function getResult($qb, $data) diff --git a/src/Bundle/ChillActivityBundle/Export/Export/ListActivity.php b/src/Bundle/ChillActivityBundle/Export/Export/ListActivity.php index 6e5d7b0b8..12338e225 100644 --- a/src/Bundle/ChillActivityBundle/Export/Export/ListActivity.php +++ b/src/Bundle/ChillActivityBundle/Export/Export/ListActivity.php @@ -1,31 +1,14 @@ - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ +declare(strict_types=1); namespace Chill\ActivityBundle\Export\Export; +use Chill\ActivityBundle\Repository\ActivityRepository; use Chill\MainBundle\Export\ListInterface; use Chill\ActivityBundle\Entity\ActivityReason; -use Chill\MainBundle\Entity\User; -use Chill\MainBundle\Entity\Scope; -use Chill\ActivityBundle\Entity\ActivityType; -use Doctrine\ORM\Query\Expr; -use Chill\MainBundle\Templating\TranslatableStringHelper; +use Chill\MainBundle\Templating\TranslatableStringHelperInterface; +use Doctrine\DBAL\Exception\InvalidArgumentException; use Symfony\Component\Security\Core\Role\Role; use Chill\ActivityBundle\Security\Authorization\ActivityStatsVoter; use Symfony\Component\Form\FormBuilderInterface; @@ -37,33 +20,17 @@ use Chill\MainBundle\Export\FormatterInterface; use Symfony\Component\Form\Extension\Core\Type\ChoiceType; use Symfony\Component\Validator\Context\ExecutionContextInterface; -/** - * Create a list for all activities - * - * @author Julien Fastré - */ class ListActivity implements ListInterface { + private ActivityRepository $activityRepository; - /** - * - * @var EntityManagerInterface - */ - protected $entityManager; + protected EntityManagerInterface $entityManager; - /** - * - * @var TranslatorInterface - */ - protected $translator; + protected TranslatorInterface $translator; - /** - * - * @var TranslatableStringHelper - */ - protected $translatableStringHelper; + protected TranslatableStringHelperInterface $translatableStringHelper; - protected $fields = array( + protected array $fields = [ 'id', 'date', 'durationTime', @@ -75,32 +42,28 @@ class ListActivity implements ListInterface 'person_firstname', 'person_lastname', 'person_id' - ); + ]; public function __construct( - EntityManagerInterface $em, - TranslatorInterface $translator, - TranslatableStringHelper $translatableStringHelper - ) - { + EntityManagerInterface $em, + TranslatorInterface $translator, + TranslatableStringHelperInterface $translatableStringHelper, + ActivityRepository $activityRepository + ) { $this->entityManager = $em; $this->translator = $translator; $this->translatableStringHelper = $translatableStringHelper; + $this->activityRepository = $activityRepository; } - /** - * {@inheritDoc} - * - * @param FormBuilderInterface $builder - */ public function buildForm(FormBuilderInterface $builder) { - $builder->add('fields', ChoiceType::class, array( + $builder->add('fields', ChoiceType::class, [ 'multiple' => true, 'expanded' => true, 'choices' => array_combine($this->fields, $this->fields), 'label' => 'Fields to include in export', - 'constraints' => [new Callback(array( + 'constraints' => [new Callback([ 'callback' => function($selected, ExecutionContextInterface $context) { if (count($selected) === 0) { $context->buildViolation('You must select at least one element') @@ -108,19 +71,14 @@ class ListActivity implements ListInterface ->addViolation(); } } - ))] - )); + ])] + ]); } - /** - * {@inheritDoc} - * - * @return type - */ public function getAllowedFormattersTypes() { - return array(FormatterInterface::TYPE_LIST); + return [FormatterInterface::TYPE_LIST]; } public function getDescription() @@ -133,29 +91,32 @@ class ListActivity implements ListInterface switch ($key) { case 'date' : - return function($value) { - if ($value === '_header') return 'date'; + return static function($value) { + if ($value === '_header') { + return 'date'; + } $date = \DateTime::createFromFormat('Y-m-d H:i:s', $value); return $date->format('d-m-Y'); }; case 'attendee': - return function($value) { - if ($value === '_header') return 'attendee'; + return static function($value) { + if ($value === '_header') { + return 'attendee'; + } return $value ? 1 : 0; }; case 'list_reasons' : - /* @var $activityReasonsRepository EntityRepository */ - $activityRepository = $this->entityManager - ->getRepository('ChillActivityBundle:Activity'); + $activityRepository = $this->activityRepository; - return function($value) use ($activityRepository) { - if ($value === '_header') return 'activity reasons'; + return function($value) use ($activityRepository): string { + if ($value === '_header') { + return 'activity reasons'; + } - $activity = $activityRepository - ->find($value); + $activity = $activityRepository->find($value); return implode(", ", array_map(function(ActivityReason $r) { @@ -168,21 +129,25 @@ class ListActivity implements ListInterface }; case 'circle_name' : return function($value) { - if ($value === '_header') return 'circle'; + if ($value === '_header') { + return 'circle'; + } - return $this->translatableStringHelper - ->localize(json_decode($value, true)); + return $this->translatableStringHelper->localize(json_decode($value, true)); }; case 'type_name' : return function($value) { - if ($value === '_header') return 'activity type'; + if ($value === '_header') { + return 'activity type'; + } - return $this->translatableStringHelper - ->localize(json_decode($value, true)); + return $this->translatableStringHelper->localize(json_decode($value, true)); }; default: - return function($value) use ($key) { - if ($value === '_header') return $key; + return static function($value) use ($key) { + if ($value === '_header') { + return $key; + } return $value; }; @@ -209,14 +174,13 @@ class ListActivity implements ListInterface return 'activity'; } - public function initiateQuery(array $requiredModifiers, array $acl, array $data = array()) + public function initiateQuery(array $requiredModifiers, array $acl, array $data = []) { $centers = array_map(function($el) { return $el['center']; }, $acl); // throw an error if any fields are present if (!\array_key_exists('fields', $data)) { - throw new \Doctrine\DBAL\Exception\InvalidArgumentException("any fields " - . "have been checked"); + throw new InvalidArgumentException('Any fields have been checked.'); } $qb = $this->entityManager->createQueryBuilder(); @@ -227,7 +191,6 @@ class ListActivity implements ListInterface ->join('person.center', 'center') ->andWhere('center IN (:authorized_centers)') ->setParameter('authorized_centers', $centers); - ; foreach ($this->fields as $f) { if (in_array($f, $data['fields'])) { @@ -269,8 +232,6 @@ class ListActivity implements ListInterface } } - - return $qb; } @@ -281,7 +242,7 @@ class ListActivity implements ListInterface public function supportsModifiers() { - return array('activity', 'person'); + return ['activity', 'person']; } } diff --git a/src/Bundle/ChillActivityBundle/Export/Export/StatActivityDuration.php b/src/Bundle/ChillActivityBundle/Export/Export/StatActivityDuration.php index 0d48130b6..f22623d9f 100644 --- a/src/Bundle/ChillActivityBundle/Export/Export/StatActivityDuration.php +++ b/src/Bundle/ChillActivityBundle/Export/Export/StatActivityDuration.php @@ -4,12 +4,13 @@ declare(strict_types=1); namespace Chill\ActivityBundle\Export\Export; +use Chill\ActivityBundle\Repository\ActivityRepository; use Chill\MainBundle\Export\ExportInterface; -use Doctrine\ORM\QueryBuilder; +use Chill\MainBundle\Export\FormatterInterface; +use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Security\Core\Role\Role; use Doctrine\ORM\Query; use Chill\ActivityBundle\Security\Authorization\ActivityStatsVoter; -use Doctrine\ORM\EntityManagerInterface; /** * This export allow to compute stats on activity duration. @@ -18,7 +19,7 @@ use Doctrine\ORM\EntityManagerInterface; */ class StatActivityDuration implements ExportInterface { - protected EntityManagerInterface $entityManager; + private ActivityRepository $activityRepository; public const SUM = 'sum'; @@ -30,13 +31,15 @@ class StatActivityDuration implements ExportInterface /** * @param string $action the stat to perform */ - public function __construct(EntityManagerInterface $em, string $action = 'sum') - { - $this->entityManager = $em; + public function __construct( + ActivityRepository $activityRepository, + string $action = 'sum' + ) { $this->action = $action; + $this->activityRepository = $activityRepository; } - public function buildForm(\Symfony\Component\Form\FormBuilderInterface $builder) + public function buildForm(FormBuilderInterface $builder) { } @@ -68,7 +71,7 @@ class StatActivityDuration implements ExportInterface $acl ); - $qb = $this->entityManager->createQueryBuilder(); + $qb = $this->activityRepository->createQueryBuilder('activity'); $select = null; @@ -77,7 +80,6 @@ class StatActivityDuration implements ExportInterface } return $qb->select($select) - ->from('ChillActivityBundle:Activity', 'activity') ->join('activity.person', 'person') ->join('person.center', 'center') ->where($qb->expr()->in('center', ':centers')) @@ -96,7 +98,7 @@ class StatActivityDuration implements ExportInterface public function getAllowedFormattersTypes() { - return array(\Chill\MainBundle\Export\FormatterInterface::TYPE_TABULAR); + return [FormatterInterface::TYPE_TABULAR]; } public function getLabels($key, array $values, $data) diff --git a/src/Bundle/ChillActivityBundle/Export/Filter/ActivityReasonFilter.php b/src/Bundle/ChillActivityBundle/Export/Filter/ActivityReasonFilter.php index 37157af60..f63178077 100644 --- a/src/Bundle/ChillActivityBundle/Export/Filter/ActivityReasonFilter.php +++ b/src/Bundle/ChillActivityBundle/Export/Filter/ActivityReasonFilter.php @@ -1,25 +1,12 @@ - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ +declare(strict_types=1); namespace Chill\ActivityBundle\Export\Filter; +use Chill\ActivityBundle\Repository\ActivityReasonRepository; use Chill\MainBundle\Export\FilterInterface; +use Chill\MainBundle\Templating\TranslatableStringHelperInterface; use Doctrine\ORM\QueryBuilder; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Bridge\Doctrine\Form\Type\EntityType; @@ -28,41 +15,24 @@ use Chill\MainBundle\Templating\TranslatableStringHelper; use Doctrine\ORM\Query\Expr; use Symfony\Component\Security\Core\Role\Role; use Chill\ActivityBundle\Security\Authorization\ActivityStatsVoter; -use Doctrine\ORM\EntityRepository; use Doctrine\ORM\Query\Expr\Join; use Symfony\Component\Validator\Context\ExecutionContextInterface; use Chill\MainBundle\Export\ExportElementValidatedInterface; -/** - * - * - * @author Julien Fastré - */ -class ActivityReasonFilter implements FilterInterface, - ExportElementValidatedInterface +class ActivityReasonFilter implements FilterInterface, ExportElementValidatedInterface { - /** - * - * @var TranslatableStringHelper - */ - protected $translatableStringHelper; - - /** - * The repository for activity reasons - * - * @var EntityRepository - */ - protected $reasonRepository; - + protected TranslatableStringHelperInterface $translatableStringHelper; + + protected ActivityReasonRepository $activityReasonRepository; + public function __construct( - TranslatableStringHelper $helper, - EntityRepository $reasonRepository + TranslatableStringHelper $helper, + ActivityReasonRepository $activityReasonRepository ) { $this->translatableStringHelper = $helper; - $this->reasonRepository = $reasonRepository; + $this->activityReasonRepository = $activityReasonRepository; } - - + public function alterQuery(QueryBuilder $qb, $data) { $where = $qb->getDQLPart('where'); @@ -75,12 +45,12 @@ class ActivityReasonFilter implements FilterInterface, && !$this->checkJoinAlreadyDefined($join['activity'], 'reasons') ) - OR + || (! array_key_exists('activity', $join)) ) { $qb->add( - 'join', - array('activity' => new Join(Join::INNER_JOIN, 'activity.reasons', 'reasons')), + 'join', + array('activity' => new Join(Join::INNER_JOIN, 'activity.reasons', 'reasons')), true ); } @@ -90,25 +60,25 @@ class ActivityReasonFilter implements FilterInterface, } else { $where = $qb->expr()->andX($clause); } - + $qb->add('where', $where); $qb->setParameter('selected_activity_reasons', $data['reasons']); } - + /** * Check if a join between Activity and Reason is already defined - * + * * @param Join[] $joins * @return boolean */ - private function checkJoinAlreadyDefined(array $joins, $alias) + private function checkJoinAlreadyDefined(array $joins, $alias): bool { foreach ($joins as $join) { if ($join->getAlias() === $alias) { return true; } } - + return false; } @@ -119,51 +89,47 @@ class ActivityReasonFilter implements FilterInterface, public function buildForm(FormBuilderInterface $builder) { - //create a local copy of translatableStringHelper - $helper = $this->translatableStringHelper; - - $builder->add('reasons', EntityType::class, array( - 'class' => 'ChillActivityBundle:ActivityReason', - 'choice_label' => function (ActivityReason $reason) use ($helper) { - return $helper->localize($reason->getName()); - }, - 'group_by' => function(ActivityReason $reason) use ($helper) { - return $helper->localize($reason->getCategory()->getName()); - }, + $builder->add('reasons', EntityType::class, [ + 'class' => ActivityReason::class, + 'choice_label' => static fn(ActivityReason $reason) => $this->translatableStringHelper->localize($reason->getName()), + 'group_by' => static fn(ActivityReason $reason) => $this->translatableStringHelper->localize($reason->getCategory()->getName()), 'multiple' => true, 'expanded' => false - )); + ]); } - + public function validateForm($data, ExecutionContextInterface $context) { if ($data['reasons'] === null || count($data['reasons']) === 0) { - $context->buildViolation("At least one reason must be choosen") + $context + ->buildViolation('At least one reason must be chosen') ->addViolation(); } } - public function getTitle() + public function getTitle() { return 'Filter by reason'; } - + public function addRole() { return new Role(ActivityStatsVoter::STATS); } - + public function describeAction($data, $format = 'string') { // collect all the reasons'name used in this filter in one array $reasonsNames = array_map( - function(ActivityReason $r) { - return "\"".$this->translatableStringHelper->localize($r->getName())."\""; - }, - $this->reasonRepository->findBy(array('id' => $data['reasons']->toArray())) - ); - - return array("Filtered by reasons: only %list%", - ["%list%" => implode(", ", $reasonsNames)]); + static fn(ActivityReason $r): string => '"' . $this->translatableStringHelper->localize($r->getName()) . '"', + $this->activityReasonRepository->findBy(array('id' => $data['reasons']->toArray())) + ); + + return [ + 'Filtered by reasons: only %list%', + [ + '%list%' => implode(", ", $reasonsNames), + ] + ]; } } diff --git a/src/Bundle/ChillActivityBundle/Export/Filter/ActivityTypeFilter.php b/src/Bundle/ChillActivityBundle/Export/Filter/ActivityTypeFilter.php index b3616da10..2d45d32c1 100644 --- a/src/Bundle/ChillActivityBundle/Export/Filter/ActivityTypeFilter.php +++ b/src/Bundle/ChillActivityBundle/Export/Filter/ActivityTypeFilter.php @@ -1,67 +1,37 @@ - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ +declare(strict_types=1); namespace Chill\ActivityBundle\Export\Filter; +use Chill\ActivityBundle\Repository\ActivityTypeRepository; use Chill\MainBundle\Export\FilterInterface; +use Chill\MainBundle\Templating\TranslatableStringHelperInterface; use Doctrine\ORM\QueryBuilder; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Bridge\Doctrine\Form\Type\EntityType; -use Chill\MainBundle\Templating\TranslatableStringHelper; use Doctrine\ORM\Query\Expr; use Symfony\Component\Security\Core\Role\Role; use Chill\ActivityBundle\Security\Authorization\ActivityStatsVoter; -use Doctrine\ORM\EntityRepository; use Doctrine\ORM\Query\Expr\Join; use Symfony\Component\Validator\Context\ExecutionContextInterface; use Chill\MainBundle\Export\ExportElementValidatedInterface; use Chill\ActivityBundle\Entity\ActivityType; -/** - * - * - */ -class ActivityTypeFilter implements FilterInterface, - ExportElementValidatedInterface +class ActivityTypeFilter implements FilterInterface, ExportElementValidatedInterface { - /** - * - * @var TranslatableStringHelper - */ - protected $translatableStringHelper; - - /** - * The repository for activity reasons - * - * @var EntityRepository - */ - protected $typeRepository; - + protected TranslatableStringHelperInterface $translatableStringHelper; + + protected ActivityTypeRepository $activityTypeRepository; + public function __construct( - TranslatableStringHelper $helper, - EntityRepository $typeRepository + TranslatableStringHelperInterface $translatableStringHelper, + ActivityTypeRepository $activityTypeRepository ) { - $this->translatableStringHelper = $helper; - $this->typeRepository = $typeRepository; + $this->translatableStringHelper = $translatableStringHelper; + $this->activityTypeRepository = $activityTypeRepository; } - - + public function alterQuery(QueryBuilder $qb, $data) { $where = $qb->getDQLPart('where'); @@ -72,14 +42,14 @@ class ActivityTypeFilter implements FilterInterface, } else { $where = $qb->expr()->andX($clause); } - + $qb->add('where', $where); $qb->setParameter('selected_activity_types', $data['types']); } - + /** * Check if a join between Activity and Reason is already defined - * + * * @param Join[] $joins * @return boolean */ @@ -90,7 +60,7 @@ class ActivityTypeFilter implements FilterInterface, return true; } } - + return false; } @@ -101,48 +71,50 @@ class ActivityTypeFilter implements FilterInterface, public function buildForm(FormBuilderInterface $builder) { - //create a local copy of translatableStringHelper - $helper = $this->translatableStringHelper; - - $builder->add('types', EntityType::class, array( - 'class' => ActivityType::class, - 'choice_label' => function (ActivityType $type) use ($helper) { - return $helper->localize($type->getName()); - }, - 'multiple' => true, - 'expanded' => false - )); + $builder->add( + 'types', + EntityType::class, + [ + 'class' => ActivityType::class, + 'choice_label' => static fn(ActivityType $type) => $this->translatableStringHelper->localize($type->getName()), + 'multiple' => true, + 'expanded' => false + ] + ); } - + public function validateForm($data, ExecutionContextInterface $context) { if ($data['types'] === null || count($data['types']) === 0) { - $context->buildViolation("At least one type must be choosen") + $context + ->buildViolation('At least one type must be chosen') ->addViolation(); } } - public function getTitle() + public function getTitle() { return 'Filter by activity type'; } - + public function addRole() { return new Role(ActivityStatsVoter::STATS); } - + public function describeAction($data, $format = 'string') { // collect all the reasons'name used in this filter in one array $reasonsNames = array_map( - function(ActivityType $t) { - return "\"".$this->translatableStringHelper->localize($t->getName())."\""; - }, - $this->typeRepository->findBy(array('id' => $data['types']->toArray())) - ); - - return array("Filtered by activity type: only %list%", - ["%list%" => implode(", ", $reasonsNames)]); + static fn(ActivityType $t): string => '"' . $this->translatableStringHelper->localize($t->getName()) . '"', + $this->activityTypeRepository->findBy(['id' => $data['types']->toArray()]) + ); + + return [ + 'Filtered by activity type: only %list%', + [ + '%list%' => implode(", ", $reasonsNames), + ] + ]; } } diff --git a/src/Bundle/ChillActivityBundle/config/services/export.yaml b/src/Bundle/ChillActivityBundle/config/services/export.yaml index 222e8b5e0..d8aa13098 100644 --- a/src/Bundle/ChillActivityBundle/config/services/export.yaml +++ b/src/Bundle/ChillActivityBundle/config/services/export.yaml @@ -1,82 +1,56 @@ services: + _defaults: + autowire: true + autoconfigure: true + chill.activity.export.count_activity: class: Chill\ActivityBundle\Export\Export\CountActivity - arguments: - - "@doctrine.orm.entity_manager" tags: - { name: chill.export, alias: 'count_activity' } - + chill.activity.export.sum_activity_duration: class: Chill\ActivityBundle\Export\Export\StatActivityDuration - arguments: - - "@doctrine.orm.entity_manager" - - "sum" tags: - { name: chill.export, alias: 'sum_activity_duration' } - + chill.activity.export.list_activity: class: Chill\ActivityBundle\Export\Export\ListActivity - arguments: - - "@doctrine.orm.entity_manager" - - "@translator" - - "@chill.main.helper.translatable_string" tags: - { name: chill.export, alias: 'list_activity' } - + chill.activity.export.reason_filter: class: Chill\ActivityBundle\Export\Filter\ActivityReasonFilter - arguments: - - "@chill.main.helper.translatable_string" - - "@chill_activity.repository.reason" tags: - { name: chill.export_filter, alias: 'activity_reason_filter' } - + chill.activity.export.type_filter: class: Chill\ActivityBundle\Export\Filter\ActivityTypeFilter - arguments: - - "@chill.main.helper.translatable_string" - - "@chill_activity.repository.activity_type" tags: - { name: chill.export_filter, alias: 'activity_type_filter' } - + chill.activity.export.date_filter: class: Chill\ActivityBundle\Export\Filter\ActivityDateFilter - arguments: - - "@translator" tags: - { name: chill.export_filter, alias: 'activity_date_filter' } chill.activity.export.person_having_an_activity_between_date_filter: class: Chill\ActivityBundle\Export\Filter\PersonHavingActivityBetweenDateFilter - arguments: - - "@chill.main.helper.translatable_string" - - "@chill_activity.repository.reason" - - "@translator" tags: - #0 register as a filter name: chill.export_filter alias: 'activity_person_having_ac_bw_date_filter' - + chill.activity.export.reason_aggregator: class: Chill\ActivityBundle\Export\Aggregator\ActivityReasonAggregator - arguments: - - "@chill_activity.repository.reason_category" - - "@chill_activity.repository.reason" - - "@chill.main.helper.translatable_string" tags: - { name: chill.export_aggregator, alias: activity_reason_aggregator } - + chill.activity.export.type_aggregator: class: Chill\ActivityBundle\Export\Aggregator\ActivityTypeAggregator - arguments: - - "@chill_activity.repository.activity_type" - - "@chill.main.helper.translatable_string" tags: - { name: chill.export_aggregator, alias: activity_type_aggregator } - + chill.activity.export.user_aggregator: class: Chill\ActivityBundle\Export\Aggregator\ActivityUserAggregator - arguments: - $em: "@doctrine.orm.entity_manager" tags: - { name: chill.export_aggregator, alias: activity_user_aggregator } From 6ccc8d4cb8027e1ff5a48abaf856e6dde97f09e7 Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Thu, 18 Nov 2021 11:46:30 +0100 Subject: [PATCH 11/31] fix: Let Symfony inject dependencies automatically. --- .../Export/Filter/ActivityDateFilter.php | 104 ++++++++---------- .../PersonHavingActivityBetweenDateFilter.php | 8 +- 2 files changed, 49 insertions(+), 63 deletions(-) diff --git a/src/Bundle/ChillActivityBundle/Export/Filter/ActivityDateFilter.php b/src/Bundle/ChillActivityBundle/Export/Filter/ActivityDateFilter.php index dca4cec30..2e0149a38 100644 --- a/src/Bundle/ChillActivityBundle/Export/Filter/ActivityDateFilter.php +++ b/src/Bundle/ChillActivityBundle/Export/Filter/ActivityDateFilter.php @@ -1,25 +1,12 @@ - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ +declare(strict_types=1); namespace Chill\ActivityBundle\Export\Filter; use Chill\MainBundle\Export\FilterInterface; +use Doctrine\ORM\QueryBuilder; +use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormEvent; use Symfony\Component\Form\FormEvents; use Symfony\Component\Form\Extension\Core\Type\DateType; @@ -28,34 +15,24 @@ use Chill\MainBundle\Form\Type\Export\FilterType; use Doctrine\ORM\Query\Expr; use Symfony\Component\Translation\TranslatorInterface; -/** - * - * - * @author Julien Fastré - */ class ActivityDateFilter implements FilterInterface { - /** - * - * @var TranslatorInterface - */ - protected $translator; - + protected TranslatorInterface $translator; + function __construct(TranslatorInterface $translator) { $this->translator = $translator; } - public function addRole() { return null; } - public function alterQuery(\Doctrine\ORM\QueryBuilder $qb, $data) + public function alterQuery(QueryBuilder $qb, $data) { $where = $qb->getDQLPart('where'); - $clause = $qb->expr()->between('activity.date', ':date_from', + $clause = $qb->expr()->between('activity.date', ':date_from', ':date_to'); if ($where instanceof Expr\Andx) { @@ -63,7 +40,7 @@ class ActivityDateFilter implements FilterInterface } else { $where = $qb->expr()->andX($clause); } - + $qb->add('where', $where); $qb->setParameter('date_from', $data['date_from']); $qb->setParameter('date_to', $data['date_to']); @@ -74,35 +51,43 @@ class ActivityDateFilter implements FilterInterface return 'activity'; } - public function buildForm(\Symfony\Component\Form\FormBuilderInterface $builder) + public function buildForm(FormBuilderInterface $builder) { - $builder->add('date_from', DateType::class, array( - 'label' => "Activities after this date", - 'data' => new \DateTime(), - 'attr' => array('class' => 'datepicker'), - 'widget'=> 'single_text', - 'format' => 'dd-MM-yyyy', - )); - - $builder->add('date_to', DateType::class, array( - 'label' => "Activities before this date", - 'data' => new \DateTime(), - 'attr' => array('class' => 'datepicker'), - 'widget'=> 'single_text', - 'format' => 'dd-MM-yyyy', - )); - + $builder->add( + 'date_from', + DateType::class, + [ + 'label' => 'Activities after this date', + 'data' => new \DateTime(), + 'attr' => ['class' => 'datepicker'], + 'widget'=> 'single_text', + 'format' => 'dd-MM-yyyy', + ] + ); + + $builder->add( + 'date_to', + DateType::class, + [ + 'label' => 'Activities before this date', + 'data' => new \DateTime(), + 'attr' => ['class' => 'datepicker'], + 'widget'=> 'single_text', + 'format' => 'dd-MM-yyyy', + ] + ); + $builder->addEventListener(FormEvents::POST_SUBMIT, function(FormEvent $event) { /* @var $filterForm \Symfony\Component\Form\FormInterface */ $filterForm = $event->getForm()->getParent(); $enabled = $filterForm->get(FilterType::ENABLED_FIELD)->getData(); - + if ($enabled === true) { // if the filter is enabled, add some validation $form = $event->getForm(); $date_from = $form->get('date_from')->getData(); $date_to = $form->get('date_to')->getData(); - + // check that fields are not empty if ($date_from === null) { $form->get('date_from')->addError(new FormError( @@ -113,8 +98,8 @@ class ActivityDateFilter implements FilterInterface $form->get('date_to')->addError(new FormError( $this->translator->trans('This field ' . 'should not be empty'))); - } - + } + // check that date_from is before date_to if ( ($date_from !== null && $date_to !== null) @@ -132,17 +117,18 @@ class ActivityDateFilter implements FilterInterface public function describeAction($data, $format = 'string') { - return array( - "Filtered by date of activity: only between %date_from% and %date_to%", - array( - "%date_from%" => $data['date_from']->format('d-m-Y'), - '%date_to%' => $data['date_to']->format('d-m-Y') - )); + return [ + 'Filtered by date of activity: only between %date_from% and %date_to%', + [ + '%date_from%' => $data['date_from']->format('d-m-Y'), + '%date_to%' => $data['date_to']->format('d-m-Y') + ] + ]; } public function getTitle() { - return "Filtered by date activity"; + return 'Filtered by date activity'; } } diff --git a/src/Bundle/ChillActivityBundle/Export/Filter/PersonHavingActivityBetweenDateFilter.php b/src/Bundle/ChillActivityBundle/Export/Filter/PersonHavingActivityBetweenDateFilter.php index 8773c95a0..e197e1220 100644 --- a/src/Bundle/ChillActivityBundle/Export/Filter/PersonHavingActivityBetweenDateFilter.php +++ b/src/Bundle/ChillActivityBundle/Export/Filter/PersonHavingActivityBetweenDateFilter.php @@ -33,9 +33,9 @@ class PersonHavingActivityBetweenDateFilter implements FilterInterface, ExportEl protected TranslatorInterface $translator; public function __construct( - TranslatableStringHelper $translatableStringHelper, - ActivityReasonRepository $activityReasonRepository, - TranslatorInterface $translator + TranslatableStringHelper $translatableStringHelper, + ActivityReasonRepository $activityReasonRepository, + TranslatorInterface $translator ) { $this->translatableStringHelper = $translatableStringHelper; $this->activityReasonRepository = $activityReasonRepository; @@ -187,7 +187,7 @@ class PersonHavingActivityBetweenDateFilter implements FilterInterface, ExportEl public function getTitle() { - return "Filtered by person having an activity in a period"; + return 'Filtered by person having an activity in a period'; } } From a32692c37a25347119f214ccea74725ab5dd411b Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Thu, 18 Nov 2021 11:48:35 +0100 Subject: [PATCH 12/31] fix: `RoleScope` might or might not have a `Scope`. --- src/Bundle/ChillMainBundle/Entity/RoleScope.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Bundle/ChillMainBundle/Entity/RoleScope.php b/src/Bundle/ChillMainBundle/Entity/RoleScope.php index 315e8f594..824c211cd 100644 --- a/src/Bundle/ChillMainBundle/Entity/RoleScope.php +++ b/src/Bundle/ChillMainBundle/Entity/RoleScope.php @@ -32,7 +32,7 @@ class RoleScope * @ORM\JoinColumn(nullable=true, name="scope_id") * @ORM\Cache(usage="NONSTRICT_READ_WRITE") */ - private Scope $scope; + private ?Scope $scope; /** * @var Collection From f9d36cc8a9bf5955d97217bf39aa95bf6fc1688a Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Thu, 18 Nov 2021 12:03:49 +0100 Subject: [PATCH 13/31] fix: Fix bug reported by the tests. --- .../ChillActivityBundle/Timeline/TimelineActivityProvider.php | 3 +-- src/Bundle/ChillPersonBundle/Entity/Person.php | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Bundle/ChillActivityBundle/Timeline/TimelineActivityProvider.php b/src/Bundle/ChillActivityBundle/Timeline/TimelineActivityProvider.php index fb0a5c45c..041978421 100644 --- a/src/Bundle/ChillActivityBundle/Timeline/TimelineActivityProvider.php +++ b/src/Bundle/ChillActivityBundle/Timeline/TimelineActivityProvider.php @@ -79,8 +79,7 @@ class TimelineActivityProvider implements TimelineProviderInterface $metadataActivity = $this->em->getClassMetadata(Activity::class); $associationMapping = $metadataActivity->getAssociationMapping('person'); $role = new Role('CHILL_ACTIVITY_SEE'); - $reachableScopes = $this->helper->getReachableScopes($this->user, - $role, $person->getCenter()); + $reachableScopes = $this->helper->getReachableScopes($this->user, $role->getRole(), $person->getCenter()); $whereClause = sprintf(' {activity.person_id} = ? AND {activity.scope_id} IN ({scopes_ids}) '); $scopes_ids = []; diff --git a/src/Bundle/ChillPersonBundle/Entity/Person.php b/src/Bundle/ChillPersonBundle/Entity/Person.php index df2f8ac51..1c2842b6a 100644 --- a/src/Bundle/ChillPersonBundle/Entity/Person.php +++ b/src/Bundle/ChillPersonBundle/Entity/Person.php @@ -63,7 +63,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI * @ORM\Column(name="id", type="integer") * @ORM\GeneratedValue(strategy="AUTO") */ - private int $id; + private ?int $id = null; /** * The person's first name From c1a4454a08ac3f1e54ab12965deed11eef688926 Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Thu, 18 Nov 2021 12:10:54 +0100 Subject: [PATCH 14/31] fix: Fix bug reported by the tests. --- src/Bundle/ChillPersonBundle/Entity/Person.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Bundle/ChillPersonBundle/Entity/Person.php b/src/Bundle/ChillPersonBundle/Entity/Person.php index 1c2842b6a..4e8e1d0e2 100644 --- a/src/Bundle/ChillPersonBundle/Entity/Person.php +++ b/src/Bundle/ChillPersonBundle/Entity/Person.php @@ -712,7 +712,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI return false; } - public function getId(): int + public function getId(): ?int { return $this->id; } From 11ad94ee096c8d31461a08758b0f8c4ba8294758 Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Thu, 18 Nov 2021 12:17:04 +0100 Subject: [PATCH 15/31] fix: Fix bug reported by the tests. --- .../Timeline/TimelineReportProvider.php | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/Bundle/ChillReportBundle/Timeline/TimelineReportProvider.php b/src/Bundle/ChillReportBundle/Timeline/TimelineReportProvider.php index a0e77bbaa..448232e4f 100644 --- a/src/Bundle/ChillReportBundle/Timeline/TimelineReportProvider.php +++ b/src/Bundle/ChillReportBundle/Timeline/TimelineReportProvider.php @@ -87,8 +87,7 @@ class TimelineReportProvider implements TimelineProviderInterface $report = $this->em->getClassMetadata(Report::class); $person = $this->em->getClassMetadata(Person::class); $role = new Role('CHILL_REPORT_SEE'); - $reachableCenters = $this->helper->getReachableCenters($this->security->getUser(), - $role); + $reachableCenters = $this->helper->getReachableCenters($this->security->getUser(), $role->getRole()); $reportPersonId = $report->getAssociationMapping('person')['joinColumns'][0]['name']; $reportScopeId = $report->getAssociationMapping('scope')['joinColumns'][0]['name']; $personCenterId = $person->getAssociationMapping('center')['joinColumns'][0]['name']; @@ -111,8 +110,7 @@ class TimelineReportProvider implements TimelineProviderInterface $parameters[] = $center->getId(); // loop over scopes $scopeIds = []; - foreach ($this->helper->getReachableScopes($this->security->getUser(), - $role, $center) as $scope) { + foreach ($this->helper->getReachableScopes($this->security->getUser(), $role->getRole(), $center) as $scope) { if (\in_array($scope->getId(), $scopeIds)) { continue; } @@ -158,8 +156,7 @@ class TimelineReportProvider implements TimelineProviderInterface // this is the final clause that we are going to fill $clause = "{report}.{person_id} = ? AND {report}.{scopes_id} IN ({scopes_ids})"; // iterate over reachable scopes - $scopes = $this->helper->getReachableScopes($this->security->getUser(), $role, - $args['person']->getCenter()); + $scopes = $this->helper->getReachableScopes($this->security->getUser(), $role->getRole(), $args['person']->getCenter()); foreach ($scopes as $scope) { if (\in_array($scope->getId(), $parameters)) { From 1e05bd31d89e4722016fc23024e774aae12047c3 Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Thu, 18 Nov 2021 12:18:16 +0100 Subject: [PATCH 16/31] fix: Fix bug reported by the tests. --- .../src/Entity/AsideActivityCategory.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Bundle/ChillAsideActivityBundle/src/Entity/AsideActivityCategory.php b/src/Bundle/ChillAsideActivityBundle/src/Entity/AsideActivityCategory.php index 143e430f7..6c00274ad 100644 --- a/src/Bundle/ChillAsideActivityBundle/src/Entity/AsideActivityCategory.php +++ b/src/Bundle/ChillAsideActivityBundle/src/Entity/AsideActivityCategory.php @@ -44,7 +44,7 @@ class AsideActivityCategory * @ORM\ManyToOne(targetEntity=AsideActivityCategory::class, inversedBy="children") * @ORM\JoinColumn(nullable=true) */ - private AsideActivityCategory $parent; + private ?AsideActivityCategory $parent = null; /** * @ORM\OneToMany(targetEntity=AsideActivityCategory::class, mappedBy="parent") From 370a24d3f5180baff9b32f724ad40b18dd85cbd4 Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Thu, 18 Nov 2021 12:36:50 +0100 Subject: [PATCH 17/31] fix: Fix PHPStan issues. --- phpstan-critical.neon | 4 ++++ .../Export/Filter/ActivityReasonFilter.php | 6 +++--- .../Export/Filter/ActivityTypeFilter.php | 4 ++-- .../Export/Filter/PersonHavingActivityBetweenDateFilter.php | 6 +++--- .../Controller/FamilyMemberController.php | 3 +-- .../ChillPersonBundle/Form/SocialWork/SocialIssueType.php | 2 +- 6 files changed, 14 insertions(+), 11 deletions(-) diff --git a/phpstan-critical.neon b/phpstan-critical.neon index 2e2f778d8..9e7bf51d2 100644 --- a/phpstan-critical.neon +++ b/phpstan-critical.neon @@ -130,3 +130,7 @@ parameters: count: 1 path: src/Bundle/ChillThirdPartyBundle/Form/Type/PickThirdPartyTypeCategoryType.php + - + message: "#^Undefined variable\\: \\$id$#" + count: 1 + path: src/Bundle/ChillFamilyMembersBundle/Controller/FamilyMemberController.php diff --git a/src/Bundle/ChillActivityBundle/Export/Filter/ActivityReasonFilter.php b/src/Bundle/ChillActivityBundle/Export/Filter/ActivityReasonFilter.php index f63178077..dbdceaaab 100644 --- a/src/Bundle/ChillActivityBundle/Export/Filter/ActivityReasonFilter.php +++ b/src/Bundle/ChillActivityBundle/Export/Filter/ActivityReasonFilter.php @@ -91,8 +91,8 @@ class ActivityReasonFilter implements FilterInterface, ExportElementValidatedInt { $builder->add('reasons', EntityType::class, [ 'class' => ActivityReason::class, - 'choice_label' => static fn(ActivityReason $reason) => $this->translatableStringHelper->localize($reason->getName()), - 'group_by' => static fn(ActivityReason $reason) => $this->translatableStringHelper->localize($reason->getCategory()->getName()), + 'choice_label' => fn(ActivityReason $reason) => $this->translatableStringHelper->localize($reason->getName()), + 'group_by' => fn(ActivityReason $reason) => $this->translatableStringHelper->localize($reason->getCategory()->getName()), 'multiple' => true, 'expanded' => false ]); @@ -121,7 +121,7 @@ class ActivityReasonFilter implements FilterInterface, ExportElementValidatedInt { // collect all the reasons'name used in this filter in one array $reasonsNames = array_map( - static fn(ActivityReason $r): string => '"' . $this->translatableStringHelper->localize($r->getName()) . '"', + fn(ActivityReason $r): string => '"' . $this->translatableStringHelper->localize($r->getName()) . '"', $this->activityReasonRepository->findBy(array('id' => $data['reasons']->toArray())) ); diff --git a/src/Bundle/ChillActivityBundle/Export/Filter/ActivityTypeFilter.php b/src/Bundle/ChillActivityBundle/Export/Filter/ActivityTypeFilter.php index 2d45d32c1..7bf1e7210 100644 --- a/src/Bundle/ChillActivityBundle/Export/Filter/ActivityTypeFilter.php +++ b/src/Bundle/ChillActivityBundle/Export/Filter/ActivityTypeFilter.php @@ -76,7 +76,7 @@ class ActivityTypeFilter implements FilterInterface, ExportElementValidatedInter EntityType::class, [ 'class' => ActivityType::class, - 'choice_label' => static fn(ActivityType $type) => $this->translatableStringHelper->localize($type->getName()), + 'choice_label' => fn(ActivityType $type) => $this->translatableStringHelper->localize($type->getName()), 'multiple' => true, 'expanded' => false ] @@ -106,7 +106,7 @@ class ActivityTypeFilter implements FilterInterface, ExportElementValidatedInter { // collect all the reasons'name used in this filter in one array $reasonsNames = array_map( - static fn(ActivityType $t): string => '"' . $this->translatableStringHelper->localize($t->getName()) . '"', + fn(ActivityType $t): string => '"' . $this->translatableStringHelper->localize($t->getName()) . '"', $this->activityTypeRepository->findBy(['id' => $data['types']->toArray()]) ); diff --git a/src/Bundle/ChillActivityBundle/Export/Filter/PersonHavingActivityBetweenDateFilter.php b/src/Bundle/ChillActivityBundle/Export/Filter/PersonHavingActivityBetweenDateFilter.php index e197e1220..d150c68e6 100644 --- a/src/Bundle/ChillActivityBundle/Export/Filter/PersonHavingActivityBetweenDateFilter.php +++ b/src/Bundle/ChillActivityBundle/Export/Filter/PersonHavingActivityBetweenDateFilter.php @@ -112,8 +112,8 @@ class PersonHavingActivityBetweenDateFilter implements FilterInterface, ExportEl $builder->add('reasons', EntityType::class, [ 'class' => ActivityReason::class, - 'choice_label' => static fn (ActivityReason $reason): ?string => $this->translatableStringHelper->localize($reason->getName()), - 'group_by' => static fn(ActivityReason $reason): ?string => $this->translatableStringHelper->localize($reason->getCategory()->getName()), + 'choice_label' => fn (ActivityReason $reason): ?string => $this->translatableStringHelper->localize($reason->getName()), + 'group_by' => fn(ActivityReason $reason): ?string => $this->translatableStringHelper->localize($reason->getCategory()->getName()), 'data' => $this->activityReasonRepository->findAll(), 'multiple' => true, 'expanded' => false, @@ -177,7 +177,7 @@ class PersonHavingActivityBetweenDateFilter implements FilterInterface, ExportEl '%reasons_name%' => implode( ", ", array_map( - static fn(ActivityReason $r): string => '"' . $this->translatableStringHelper->localize($r->getName()) . '"', + fn(ActivityReason $r): string => '"' . $this->translatableStringHelper->localize($r->getName()) . '"', $data['reasons'] ) ) diff --git a/src/Bundle/ChillFamilyMembersBundle/Controller/FamilyMemberController.php b/src/Bundle/ChillFamilyMembersBundle/Controller/FamilyMemberController.php index 3ee9d4dd5..a6378fa5c 100644 --- a/src/Bundle/ChillFamilyMembersBundle/Controller/FamilyMemberController.php +++ b/src/Bundle/ChillFamilyMembersBundle/Controller/FamilyMemberController.php @@ -62,8 +62,7 @@ class FamilyMemberController extends Controller public function newAction(Person $person, Request $request) { $familyMember = (new FamilyMember()) - ->setPerson($person) - ; + ->setPerson($person); $this->denyAccessUnlessGranted(FamilyMemberVoter::CREATE, $familyMember); diff --git a/src/Bundle/ChillPersonBundle/Form/SocialWork/SocialIssueType.php b/src/Bundle/ChillPersonBundle/Form/SocialWork/SocialIssueType.php index f41d843c2..430514d21 100644 --- a/src/Bundle/ChillPersonBundle/Form/SocialWork/SocialIssueType.php +++ b/src/Bundle/ChillPersonBundle/Form/SocialWork/SocialIssueType.php @@ -32,7 +32,7 @@ class SocialIssueType extends AbstractType ->add('parent', EntityType::class, [ 'class' => SocialIssue::class, 'required' => false, - 'choice_label' => static fn (SocialIssue $issue): ?string => $this->translatableStringHelper->localize($issue->getTitle()) + 'choice_label' => fn (SocialIssue $issue): ?string => $this->translatableStringHelper->localize($issue->getTitle()) ]) ->add('desactivationDate', DateType::class, [ 'attr' => ['class' => 'datepicker'], From 674bf614dd250a0da187ab6bc1dba717d6a43215 Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Thu, 18 Nov 2021 14:15:51 +0100 Subject: [PATCH 18/31] fix: Add a deprecation and the new service that goes with it as replacement. --- .../Resolver/CenterResolverDispatcher.php | 29 ++++++++++++----- .../Resolver/CenterResolverManager.php | 31 +++++++++++++++++++ .../CenterResolverManagerInterface.php | 15 +++++++++ 3 files changed, 68 insertions(+), 7 deletions(-) create mode 100644 src/Bundle/ChillMainBundle/Security/Resolver/CenterResolverManager.php create mode 100644 src/Bundle/ChillMainBundle/Security/Resolver/CenterResolverManagerInterface.php diff --git a/src/Bundle/ChillMainBundle/Security/Resolver/CenterResolverDispatcher.php b/src/Bundle/ChillMainBundle/Security/Resolver/CenterResolverDispatcher.php index 1e2f9c02b..1042f3931 100644 --- a/src/Bundle/ChillMainBundle/Security/Resolver/CenterResolverDispatcher.php +++ b/src/Bundle/ChillMainBundle/Security/Resolver/CenterResolverDispatcher.php @@ -1,27 +1,42 @@ resolvers = $resolvers; } /** - * @param mixed $entity - * @param array|null $options * @return null|Center|Center[] */ public function resolveCenter($entity, ?array $options = []) { - foreach($this->resolvers as $priority => $resolver) { + trigger_deprecation( + 'ChillMainBundle', + 'dev-master', + ' + Use the service CenterResolverManager through the interface CenterResolverManagerInterface. + The new method "CenterResolverManagerInterface::resolveCenters(): array" is available and the typing + has been improved in order to avoid mixing types. + ' + ); + + foreach($this->resolvers as $resolver) { if ($resolver->supports($entity, $options)) { return $resolver->resolveCenter($entity, $options); } diff --git a/src/Bundle/ChillMainBundle/Security/Resolver/CenterResolverManager.php b/src/Bundle/ChillMainBundle/Security/Resolver/CenterResolverManager.php new file mode 100644 index 000000000..9f09398a5 --- /dev/null +++ b/src/Bundle/ChillMainBundle/Security/Resolver/CenterResolverManager.php @@ -0,0 +1,31 @@ +resolvers = $resolvers; + } + + public function resolveCenters($entity, ?array $options = []): array + { + foreach($this->resolvers as $resolver) { + if ($resolver->supports($entity, $options)) { + return (array) $resolver->resolveCenter($entity, $options); + } + } + + return []; + } +} diff --git a/src/Bundle/ChillMainBundle/Security/Resolver/CenterResolverManagerInterface.php b/src/Bundle/ChillMainBundle/Security/Resolver/CenterResolverManagerInterface.php new file mode 100644 index 000000000..deaaff182 --- /dev/null +++ b/src/Bundle/ChillMainBundle/Security/Resolver/CenterResolverManagerInterface.php @@ -0,0 +1,15 @@ + Date: Thu, 18 Nov 2021 14:16:02 +0100 Subject: [PATCH 19/31] fix: Replace tabs with spaces. --- phpstan-critical.neon | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/phpstan-critical.neon b/phpstan-critical.neon index 9e7bf51d2..b92189776 100644 --- a/phpstan-critical.neon +++ b/phpstan-critical.neon @@ -130,7 +130,7 @@ parameters: count: 1 path: src/Bundle/ChillThirdPartyBundle/Form/Type/PickThirdPartyTypeCategoryType.php - - - message: "#^Undefined variable\\: \\$id$#" - count: 1 - path: src/Bundle/ChillFamilyMembersBundle/Controller/FamilyMemberController.php + - + message: "#^Undefined variable\\: \\$id$#" + count: 1 + path: src/Bundle/ChillFamilyMembersBundle/Controller/FamilyMemberController.php From 162db60f592954a26263af12c273f192b00be226 Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Thu, 18 Nov 2021 14:28:51 +0100 Subject: [PATCH 20/31] fix: Fix FamilyMemberController and Repository. --- .../Controller/FamilyMemberController.php | 97 +++++++++---------- .../Repository/FamilyMemberRepository.php | 25 ++++- 2 files changed, 66 insertions(+), 56 deletions(-) diff --git a/src/Bundle/ChillFamilyMembersBundle/Controller/FamilyMemberController.php b/src/Bundle/ChillFamilyMembersBundle/Controller/FamilyMemberController.php index a6378fa5c..1e25915ac 100644 --- a/src/Bundle/ChillFamilyMembersBundle/Controller/FamilyMemberController.php +++ b/src/Bundle/ChillFamilyMembersBundle/Controller/FamilyMemberController.php @@ -1,38 +1,46 @@ em = $em; + $this->em = $entityManager; $this->translator = $translator; $this->chillMainLogger = $chillMainLogger; + $this->familyMemberRepository = $familyMemberRepository; } - /** * @Route( * "{_locale}/family-members/family-members/by-person/{id}", @@ -43,14 +51,12 @@ class FamilyMemberController extends Controller { $this->denyAccessUnlessGranted(FamilyMemberVoter::SHOW, $person); - $familyMembers = $this->em - ->getRepository(FamilyMember::class) - ->findByPerson($person); + $familyMembers = $this->familyMemberRepository->findByPerson($person); - return $this->render('ChillAMLIFamilyMembersBundle:FamilyMember:index.html.twig', array( + return $this->render('ChillAMLIFamilyMembersBundle:FamilyMember:index.html.twig', [ 'person' => $person, 'familyMembers' => $familyMembers - )); + ]); } /** @@ -61,8 +67,7 @@ class FamilyMemberController extends Controller */ public function newAction(Person $person, Request $request) { - $familyMember = (new FamilyMember()) - ->setPerson($person); + $familyMember = (new FamilyMember())->setPerson($person); $this->denyAccessUnlessGranted(FamilyMemberVoter::CREATE, $familyMember); @@ -71,10 +76,9 @@ class FamilyMemberController extends Controller $form->handleRequest($request); - if ($form->isSubmitted() and $form->isValid()) { - $em = $this->getDoctrine()->getManager(); - $em->persist($familyMember); - $em->flush(); + if ($form->isSubmitted() && $form->isValid()) { + $this->em->persist($familyMember); + $this->em->flush(); $this->addFlash('success', $this->translator->trans('Family member created')); @@ -83,10 +87,10 @@ class FamilyMemberController extends Controller ]); } - return $this->render('ChillAMLIFamilyMembersBundle:FamilyMember:new.html.twig', array( + return $this->render('ChillAMLIFamilyMembersBundle:FamilyMember:new.html.twig', [ 'form' => $form->createView(), 'person' => $person - )); + ]); } /** @@ -104,9 +108,8 @@ class FamilyMemberController extends Controller $form->handleRequest($request); - if ($form->isSubmitted() and $form->isValid()) { - $em = $this->getDoctrine()->getManager(); - $em->flush(); + if ($form->isSubmitted() && $form->isValid()) { + $this->em->flush(); $this->addFlash('success', $this->translator->trans('Family member updated')); @@ -115,11 +118,11 @@ class FamilyMemberController extends Controller ]); } - return $this->render('ChillAMLIFamilyMembersBundle:FamilyMember:edit.html.twig', array( + return $this->render('ChillAMLIFamilyMembersBundle:FamilyMember:edit.html.twig', [ 'familyMember' => $familyMember, 'form' => $form->createView(), 'person' => $familyMember->getPerson() - )); + ]); } /** @@ -128,47 +131,42 @@ class FamilyMemberController extends Controller * "{_locale}/family-members/family-members/{id}/delete", * name="chill_family_members_family_members_delete" * ) - * - * @param FamilyMember $familyMember - * @param Request $request - * @return \Symfony\Component\BrowserKit\Response */ - public function deleteAction(FamilyMember $familyMember, Request $request) + public function deleteAction(FamilyMember $familyMember, Request $request): Response { $this->denyAccessUnlessGranted(FamilyMemberVoter::DELETE, $familyMember, 'You are not ' . 'allowed to delete this family membership'); - $form = $this->createDeleteForm($id); + $form = $this->createDeleteForm(); if ($request->getMethod() === Request::METHOD_DELETE) { $form->handleRequest($request); if ($form->isValid()) { - $this->chillMainLogger->notice("A family member has been removed", array( + $this->chillMainLogger->notice("A family member has been removed", [ 'by_user' => $this->getUser()->getUsername(), 'family_member_id' => $familyMember->getId(), 'name' => $familyMember->getFirstname()." ".$familyMember->getLastname(), 'link' => $familyMember->getLink() - )); + ]); - $em = $this->getDoctrine()->getManager(); - $em->remove($familyMember); - $em->flush(); + $this->em->remove($familyMember); + $this->em->flush(); $this->addFlash('success', $this->translator ->trans("The family member has been successfully removed.")); - return $this->redirectToRoute('chill_family_members_family_members_index', array( + return $this->redirectToRoute('chill_family_members_family_members_index', [ 'id' => $familyMember->getPerson()->getId() - )); + ]); } } - return $this->render('ChillAMLIFamilyMembersBundle:FamilyMember:confirm_delete.html.twig', array( + return $this->render('ChillAMLIFamilyMembersBundle:FamilyMember:confirm_delete.html.twig', [ 'familyMember' => $familyMember, 'delete_form' => $form->createView() - )); + ]); } /** @@ -181,23 +179,20 @@ class FamilyMemberController extends Controller { $this->denyAccessUnlessGranted(FamilyMemberVoter::SHOW, $familyMember); - return $this->render('ChillAMLIFamilyMembersBundle:FamilyMember:view.html.twig', array( + return $this->render('ChillAMLIFamilyMembersBundle:FamilyMember:view.html.twig', [ 'familyMember' => $familyMember - )); + ]); } /** * Creates a form to delete a help request entity by id. - * - * @param mixed $id The entity id - * - * @return \Symfony\Component\Form\Form The form */ - private function createDeleteForm($id) + private function createDeleteForm(): FormInterface { - return $this->createFormBuilder() + return $this + ->createFormBuilder() ->setMethod(Request::METHOD_DELETE) - ->add('submit', SubmitType::class, array('label' => 'Delete')) + ->add('submit', SubmitType::class, ['label' => 'Delete']) ->getForm() ; } diff --git a/src/Bundle/ChillFamilyMembersBundle/Repository/FamilyMemberRepository.php b/src/Bundle/ChillFamilyMembersBundle/Repository/FamilyMemberRepository.php index 618128c96..a6754981b 100644 --- a/src/Bundle/ChillFamilyMembersBundle/Repository/FamilyMemberRepository.php +++ b/src/Bundle/ChillFamilyMembersBundle/Repository/FamilyMemberRepository.php @@ -1,17 +1,32 @@ findBy([ 'person' => $person ]); + parent::__construct($registry, FamilyMember::class); + } + + /** + * @return FamilyMember[] + */ + public function findByPerson(Person $person): array + { + return $this->findBy(['person' => $person]); } } From ae79ebc2992ced02de46009189aaf8c634a1cced Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Thu, 18 Nov 2021 14:29:11 +0100 Subject: [PATCH 21/31] fix: Strict type RoleScope. --- .../ChillMainBundle/Entity/RoleScope.php | 38 +++++-------------- 1 file changed, 10 insertions(+), 28 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Entity/RoleScope.php b/src/Bundle/ChillMainBundle/Entity/RoleScope.php index 824c211cd..a92184917 100644 --- a/src/Bundle/ChillMainBundle/Entity/RoleScope.php +++ b/src/Bundle/ChillMainBundle/Entity/RoleScope.php @@ -1,5 +1,7 @@ new = true; $this->permissionsGroups = new ArrayCollection(); } - /** - * @return int - */ - public function getId() + public function getId(): ?int { return $this->id; } - /** - * @return string - */ - public function getRole() + public function getRole(): ?string { return $this->role; } - /** - * @return Scope - */ - public function getScope() + public function getScope(): ?Scope { return $this->scope; } - /** - * @param type $role - * @return RoleScope - */ - public function setRole($role) + public function setRole(?string $role = null): self { $this->role = $role; return $this; } - /** - * @param Scope $scope - * @return RoleScope - */ - public function setScope(Scope $scope = null) + public function setScope(?Scope $scope = null): self { $this->scope = $scope; From 7fd45d57358ce7ceca95832c4caf2b1a616e043d Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Thu, 18 Nov 2021 14:33:06 +0100 Subject: [PATCH 22/31] fix: Remove deprecations. --- .../Timeline/TimelineReportProvider.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/Bundle/ChillReportBundle/Timeline/TimelineReportProvider.php b/src/Bundle/ChillReportBundle/Timeline/TimelineReportProvider.php index 448232e4f..04f4ba346 100644 --- a/src/Bundle/ChillReportBundle/Timeline/TimelineReportProvider.php +++ b/src/Bundle/ChillReportBundle/Timeline/TimelineReportProvider.php @@ -22,7 +22,6 @@ use Chill\MainBundle\Timeline\TimelineSingleQuery; */ class TimelineReportProvider implements TimelineProviderInterface { - protected EntityManager $em; protected AuthorizationHelper $helper; @@ -84,10 +83,12 @@ class TimelineReportProvider implements TimelineProviderInterface private function getWhereClauseForCenter(string $context, array $args): array { + $role = 'CHILL_REPORT_SEE'; + $report = $this->em->getClassMetadata(Report::class); $person = $this->em->getClassMetadata(Person::class); - $role = new Role('CHILL_REPORT_SEE'); - $reachableCenters = $this->helper->getReachableCenters($this->security->getUser(), $role->getRole()); + + $reachableCenters = $this->helper->getReachableCenters($this->security->getUser(), $role); $reportPersonId = $report->getAssociationMapping('person')['joinColumns'][0]['name']; $reportScopeId = $report->getAssociationMapping('scope')['joinColumns'][0]['name']; $personCenterId = $person->getAssociationMapping('center')['joinColumns'][0]['name']; @@ -110,7 +111,7 @@ class TimelineReportProvider implements TimelineProviderInterface $parameters[] = $center->getId(); // loop over scopes $scopeIds = []; - foreach ($this->helper->getReachableScopes($this->security->getUser(), $role->getRole(), $center) as $scope) { + foreach ($this->helper->getReachableScopes($this->security->getUser(), $role, $center) as $scope) { if (\in_array($scope->getId(), $scopeIds)) { continue; } @@ -144,9 +145,9 @@ class TimelineReportProvider implements TimelineProviderInterface private function getWhereClauseForPerson(string $context, array $args): array { + $role = 'CHILL_REPORT_SEE'; $report = $this->em->getClassMetadata(Report::class); $person = $this->em->getClassMetadata(Person::class); - $role = new Role('CHILL_REPORT_SEE'); $reportPersonId = $report->getAssociationMapping('person')['joinColumns'][0]['name']; $reportScopeId = $report->getAssociationMapping('scope')['joinColumns'][0]['name']; $personCenterId = $person->getAssociationMapping('center')['joinColumns'][0]['name']; @@ -156,7 +157,7 @@ class TimelineReportProvider implements TimelineProviderInterface // this is the final clause that we are going to fill $clause = "{report}.{person_id} = ? AND {report}.{scopes_id} IN ({scopes_ids})"; // iterate over reachable scopes - $scopes = $this->helper->getReachableScopes($this->security->getUser(), $role->getRole(), $args['person']->getCenter()); + $scopes = $this->helper->getReachableScopes($this->security->getUser(), $role, $args['person']->getCenter()); foreach ($scopes as $scope) { if (\in_array($scope->getId(), $parameters)) { From 1509fcc2e911436f41614a93448f46ae2463c8fa Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Thu, 18 Nov 2021 14:33:14 +0100 Subject: [PATCH 23/31] fix: Fix tests. --- .../Person/PersonHasCenterValidatorTest.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Tests/Validator/Person/PersonHasCenterValidatorTest.php b/src/Bundle/ChillPersonBundle/Tests/Validator/Person/PersonHasCenterValidatorTest.php index 8cd0e6b83..a237b3571 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Validator/Person/PersonHasCenterValidatorTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Validator/Person/PersonHasCenterValidatorTest.php @@ -1,14 +1,18 @@ [ 'center_required' => true ] - ]) - ; + ]); - return new PersonHasCenterValidator($parameterBag); + $centerResolverDispatcher = $this->createMock(CenterResolverDispatcher::class); + + return new PersonHasCenterValidator($parameterBag, $centerResolverDispatcher); } } From 7a07b8bef70dd550f4244711ef62959c144f083f Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Thu, 18 Nov 2021 14:45:32 +0100 Subject: [PATCH 24/31] fix: Autowire and autoconfigure the new service. --- .../Authorization/ChillExportVoter.php | 49 +++++-------------- .../config/services/security.yaml | 9 ++-- 2 files changed, 16 insertions(+), 42 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Security/Authorization/ChillExportVoter.php b/src/Bundle/ChillMainBundle/Security/Authorization/ChillExportVoter.php index 39af35706..f4dd9ba7c 100644 --- a/src/Bundle/ChillMainBundle/Security/Authorization/ChillExportVoter.php +++ b/src/Bundle/ChillMainBundle/Security/Authorization/ChillExportVoter.php @@ -1,48 +1,24 @@ - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ + +declare(strict_types=1); + namespace Chill\MainBundle\Security\Authorization; use Symfony\Component\Security\Core\Authorization\Voter\Voter; use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; -use Chill\MainBundle\Security\Authorization\AuthorizationHelper; use Chill\MainBundle\Entity\User; -use Symfony\Component\Security\Core\Role\Role; -/** - * - * - * @author Julien Fastré - */ class ChillExportVoter extends Voter { - const EXPORT = 'chill_export'; - - /** - * - * @var AuthorizationHelper - */ - protected $authorizationHelper; - - public function __construct(AuthorizationHelper $authorizationHelper) + public const EXPORT = 'chill_export'; + + protected AuthorizationHelperInterface $authorizationHelper; + + public function __construct(AuthorizationHelperInterface $authorizationHelper) { $this->authorizationHelper = $authorizationHelper; } - + protected function supports($attribute, $subject): bool { return $attribute === self::EXPORT; @@ -53,10 +29,7 @@ class ChillExportVoter extends Voter if (!$token->getUser() instanceof User) { return false; } - - $centers = $this->authorizationHelper - ->getReachableCenters($token->getUser(), new Role($attribute)); - - return count($centers) > 0; + + return [] !== $this->authorizationHelper->getReachableCenters($token->getUser(), $attribute); } } diff --git a/src/Bundle/ChillMainBundle/config/services/security.yaml b/src/Bundle/ChillMainBundle/config/services/security.yaml index 8dcd15f5d..163b86d8e 100644 --- a/src/Bundle/ChillMainBundle/config/services/security.yaml +++ b/src/Bundle/ChillMainBundle/config/services/security.yaml @@ -3,11 +3,15 @@ services: autowire: true autoconfigure: true - # do not autowire the directory Security/Resolver Chill\MainBundle\Security\Resolver\CenterResolverDispatcher: arguments: - !tagged_iterator chill_main.center_resolver + Chill\MainBundle\Security\Resolver\CenterResolverManager: + arguments: + - !tagged_iterator chill_main.center_resolver + Chill\MainBundle\Security\Resolver\CenterResolverManagerInterface: '@Chill\MainBundle\Security\Resolver\CenterResolverManager' + Chill\MainBundle\Security\Resolver\ScopeResolverDispatcher: arguments: - !tagged_iterator chill_main.scope_resolver @@ -20,7 +24,6 @@ services: Chill\MainBundle\Security\Authorization\DefaultVoterHelperFactory: ~ - # do not autowire the directory Security/Resolver Chill\MainBundle\Security\Authorization\VoterHelperFactoryInterface: '@Chill\MainBundle\Security\Authorization\DefaultVoterHelperFactory' chill.main.security.authorization.helper: @@ -40,8 +43,6 @@ services: Symfony\Component\Security\Core\User\UserProviderInterface: "@chill.main.user_provider" Chill\MainBundle\Security\Authorization\ChillExportVoter: - arguments: - $authorizationHelper: '@Chill\MainBundle\Security\Authorization\AuthorizationHelper' tags: - { name: security.voter } From 56b15f26b2777767b8fe418d722f27fe176e3858 Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Thu, 18 Nov 2021 14:47:58 +0100 Subject: [PATCH 25/31] fix: Get rid of a single PHPStan critical issue. --- phpstan-critical.neon | 5 ----- 1 file changed, 5 deletions(-) diff --git a/phpstan-critical.neon b/phpstan-critical.neon index b92189776..6147f2022 100644 --- a/phpstan-critical.neon +++ b/phpstan-critical.neon @@ -129,8 +129,3 @@ parameters: message: "#^Call to an undefined method Chill\\\\ThirdPartyBundle\\\\Form\\\\Type\\\\PickThirdPartyTypeCategoryType\\:\\:transform\\(\\)\\.$#" count: 1 path: src/Bundle/ChillThirdPartyBundle/Form/Type/PickThirdPartyTypeCategoryType.php - - - - message: "#^Undefined variable\\: \\$id$#" - count: 1 - path: src/Bundle/ChillFamilyMembersBundle/Controller/FamilyMemberController.php From 597a12b0850aa4b1e0ff58c383053c3d419a8b32 Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Thu, 18 Nov 2021 14:50:16 +0100 Subject: [PATCH 26/31] fix: Get rid of obsolete import. --- .../ChillMainBundle/Security/Resolver/CenterResolverManager.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Security/Resolver/CenterResolverManager.php b/src/Bundle/ChillMainBundle/Security/Resolver/CenterResolverManager.php index 9f09398a5..2dc947c8b 100644 --- a/src/Bundle/ChillMainBundle/Security/Resolver/CenterResolverManager.php +++ b/src/Bundle/ChillMainBundle/Security/Resolver/CenterResolverManager.php @@ -4,8 +4,6 @@ declare(strict_types=1); namespace Chill\MainBundle\Security\Resolver; -use Chill\MainBundle\Entity\Center; - final class CenterResolverManager implements CenterResolverManagerInterface { /** From 17ef96392494bdb997048ccab185d3f0e4298214 Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Thu, 18 Nov 2021 15:14:00 +0100 Subject: [PATCH 27/31] fix: Fix wrong entity class and a few other fixes. --- .../Controller/ActivityController.php | 99 +++++++++++-------- 1 file changed, 57 insertions(+), 42 deletions(-) diff --git a/src/Bundle/ChillActivityBundle/Controller/ActivityController.php b/src/Bundle/ChillActivityBundle/Controller/ActivityController.php index 543aa1f6b..47ebebd09 100644 --- a/src/Bundle/ChillActivityBundle/Controller/ActivityController.php +++ b/src/Bundle/ChillActivityBundle/Controller/ActivityController.php @@ -5,18 +5,20 @@ declare(strict_types=1); namespace Chill\ActivityBundle\Controller; use Chill\ActivityBundle\Entity\ActivityReason; -use Chill\ActivityBundle\Entity\ActivityTypeCategory; use Chill\ActivityBundle\Repository\ActivityACLAwareRepositoryInterface; +use Chill\ActivityBundle\Repository\ActivityRepository; +use Chill\ActivityBundle\Repository\ActivityTypeRepository; use Chill\ActivityBundle\Security\Authorization\ActivityVoter; -use Chill\MainBundle\Entity\Location; -use Chill\MainBundle\Security\Authorization\AuthorizationHelper; +use Chill\MainBundle\Repository\LocationRepository; use Chill\PersonBundle\Entity\AccompanyingPeriod; use Chill\PersonBundle\Entity\Person; use Chill\PersonBundle\Privacy\PrivacyEvent; -use Chill\ThirdPartyBundle\Entity\ThirdParty; +use Chill\PersonBundle\Repository\AccompanyingPeriodRepository; +use Chill\PersonBundle\Repository\PersonRepository; +use Chill\ThirdPartyBundle\Repository\ThirdPartyRepository; +use Doctrine\ORM\EntityManagerInterface; use Psr\Log\LoggerInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface; -use Symfony\Component\Form\Form; use Symfony\Component\Form\FormInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; @@ -30,26 +32,50 @@ use Symfony\Component\Serializer\SerializerInterface; final class ActivityController extends AbstractController { - protected EventDispatcherInterface $eventDispatcher; + private EventDispatcherInterface $eventDispatcher; - protected AuthorizationHelper $authorizationHelper; + private LoggerInterface $logger; - protected LoggerInterface $logger; + private SerializerInterface $serializer; - protected SerializerInterface $serializer; + private ActivityACLAwareRepositoryInterface $activityACLAwareRepository; - protected ActivityACLAwareRepositoryInterface $activityACLAwareRepository; + private ActivityTypeRepository $activityTypeRepository; + + private ThirdPartyRepository $thirdPartyRepository; + + private PersonRepository $personRepository; + + private LocationRepository $locationRepository; + + private EntityManagerInterface $entityManager; + + private ActivityRepository $activityRepository; + + private AccompanyingPeriodRepository $accompanyingPeriodRepository; public function __construct( ActivityACLAwareRepositoryInterface $activityACLAwareRepository, + ActivityTypeRepository $activityTypeRepository, + PersonRepository $personRepository, + ThirdPartyRepository $thirdPartyRepository, + LocationRepository $locationRepository, + ActivityRepository $activityRepository, + AccompanyingPeriodRepository $accompanyingPeriodRepository, + EntityManagerInterface $entityManager, EventDispatcherInterface $eventDispatcher, - AuthorizationHelper $authorizationHelper, LoggerInterface $logger, SerializerInterface $serializer ) { $this->activityACLAwareRepository = $activityACLAwareRepository; + $this->activityTypeRepository = $activityTypeRepository; + $this->personRepository = $personRepository; + $this->thirdPartyRepository = $thirdPartyRepository; + $this->locationRepository = $locationRepository; + $this->activityRepository = $activityRepository; + $this->accompanyingPeriodRepository = $accompanyingPeriodRepository; + $this->entityManager = $entityManager; $this->eventDispatcher = $eventDispatcher; - $this->authorizationHelper = $authorizationHelper; $this->logger = $logger; $this->serializer = $serializer; } @@ -98,7 +124,6 @@ final class ActivityController extends AbstractController public function selectTypeAction(Request $request): Response { - $em = $this->getDoctrine()->getManager(); $view = null; [$person, $accompanyingPeriod] = $this->getEntity($request); @@ -111,12 +136,10 @@ final class ActivityController extends AbstractController $data = []; - $activityTypeCategories = $em->getRepository(ActivityTypeCategory::class) - ->findBy(['active' => true], ['ordering' => 'ASC']); + $activityTypeCategories = $this->activityTypeRepository->findBy(['active' => true], ['ordering' => 'ASC']); foreach ($activityTypeCategories as $activityTypeCategory) { - $activityTypes = $em->getRepository(ActivityType::class) - ->findBy(['active' => true, 'category' => $activityTypeCategory], ['ordering' => 'ASC']); + $activityTypes = $this->activityTypeRepository->findBy(['active' => true, 'category' => $activityTypeCategory], ['ordering' => 'ASC']); $data[] = [ 'activityTypeCategory' => $activityTypeCategory, @@ -139,7 +162,6 @@ final class ActivityController extends AbstractController public function newAction(Request $request): Response { $view = null; - $em = $this->getDoctrine()->getManager(); [$person, $accompanyingPeriod] = $this->getEntity($request); @@ -150,8 +172,7 @@ final class ActivityController extends AbstractController } $activityType_id = $request->get('activityType_id', 0); - $activityType = $em->getRepository(ActivityType::class) - ->find($activityType_id); + $activityType = $this->activityTypeRepository->find($activityType_id); if (isset($activityType) && !$activityType->isActive()) { throw new \InvalidArgumentException('Activity type must be active'); @@ -209,20 +230,20 @@ final class ActivityController extends AbstractController if (array_key_exists('personsId', $activityData)) { foreach($activityData['personsId'] as $personId){ - $concernedPerson = $em->getRepository(Person::class)->find($personId); + $concernedPerson = $this->personRepository->find($personId); $entity->addPerson($concernedPerson); } } if (array_key_exists('professionalsId', $activityData)) { foreach($activityData['professionalsId'] as $professionalsId){ - $professional = $em->getRepository(ThirdParty::class)->find($professionalsId); + $professional = $this->thirdPartyRepository->find($professionalsId); $entity->addThirdParty($professional); } } if (array_key_exists('location', $activityData)) { - $location = $em->getRepository(Location::class)->find($activityData['location']); + $location = $this->locationRepository->find($activityData['location']); $entity->setLocation($location); } @@ -247,8 +268,8 @@ final class ActivityController extends AbstractController ])->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { - $em->persist($entity); - $em->flush(); + $this->entityManager->persist($entity); + $this->entityManager->flush(); $this->addFlash('success', $this->get('translator')->trans('Success : activity created!')); @@ -277,7 +298,6 @@ final class ActivityController extends AbstractController public function showAction(Request $request, $id): Response { $view = null; - $em = $this->getDoctrine()->getManager(); [$person, $accompanyingPeriod] = $this->getEntity($request); @@ -287,8 +307,7 @@ final class ActivityController extends AbstractController $view = 'ChillActivityBundle:Activity:showPerson.html.twig'; } - /** @var Activity $entity */ - $entity = $em->getRepository(Activity::class)->find($id); + $entity = $this->activityRepository->find($id); if (null === $entity) { throw $this->createNotFoundException('Unable to find Activity entity.'); @@ -333,7 +352,6 @@ final class ActivityController extends AbstractController public function editAction($id, Request $request): Response { $view = null; - $em = $this->getDoctrine()->getManager(); [$person, $accompanyingPeriod] = $this->getEntity($request); @@ -343,8 +361,7 @@ final class ActivityController extends AbstractController $view = 'ChillActivityBundle:Activity:editPerson.html.twig'; } - /** @var Activity $entity */ - $entity = $em->getRepository(Activity::class)->find($id); + $entity = $this->activityRepository->find($id); if (null === $entity) { throw $this->createNotFoundException('Unable to find Activity entity.'); @@ -361,8 +378,8 @@ final class ActivityController extends AbstractController ])->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { - $em->persist($entity); - $em->flush(); + $this->entityManager->persist($entity); + $this->entityManager->flush(); $this->addFlash('success', $this->get('translator')->trans('Success : activity updated!')); @@ -406,7 +423,6 @@ final class ActivityController extends AbstractController public function deleteAction(Request $request, $id) { $view = null; - $em = $this->getDoctrine()->getManager(); [$person, $accompanyingPeriod] = $this->getEntity($request); @@ -416,8 +432,7 @@ final class ActivityController extends AbstractController $view = 'ChillActivityBundle:Activity:confirm_deletePerson.html.twig'; } - /* @var Activity $activity */ - $activity = $em->getRepository(Activity::class)->find($id); + $activity = $this->activityRepository->find($id); if (!$activity) { throw $this->createNotFoundException('Unable to find Activity entity.'); @@ -449,8 +464,8 @@ final class ActivityController extends AbstractController 'attendee' => $activity->getAttendee() ]); - $em->remove($activity); - $em->flush(); + $this->entityManager->remove($activity); + $this->entityManager->flush(); $this->addFlash('success', $this->get('translator') ->trans("The activity has been successfully removed.")); @@ -490,12 +505,11 @@ final class ActivityController extends AbstractController private function getEntity(Request $request): array { - $em = $this->getDoctrine()->getManager(); $person = $accompanyingPeriod = null; if ($request->query->has('person_id')) { $person_id = $request->get('person_id'); - $person = $em->getRepository(Person::class)->find($person_id); + $person = $this->personRepository->find($person_id); if ($person === null) { throw $this->createNotFoundException('Person not found'); @@ -504,7 +518,7 @@ final class ActivityController extends AbstractController $this->denyAccessUnlessGranted('CHILL_PERSON_SEE', $person); } elseif ($request->query->has('accompanying_period_id')) { $accompanying_period_id = $request->get('accompanying_period_id'); - $accompanyingPeriod = $em->getRepository(AccompanyingPeriod::class)->find($accompanying_period_id); + $accompanyingPeriod = $this->accompanyingPeriodRepository->find($accompanying_period_id); if ($accompanyingPeriod === null) { throw $this->createNotFoundException('Accompanying Period not found'); @@ -522,7 +536,8 @@ final class ActivityController extends AbstractController ]; } - private function buildParamsToUrl(?Person $person, ?AccompanyingPeriod $accompanyingPeriod): array { + private function buildParamsToUrl(?Person $person, ?AccompanyingPeriod $accompanyingPeriod): array + { $params = []; if (null !== $person) { From d1935f96e71dafe1f722841e25918124714757dc Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Thu, 18 Nov 2021 15:23:44 +0100 Subject: [PATCH 28/31] fix: Add more typing informations. --- .../Security/Resolver/CenterResolverDispatcher.php | 1 + .../Security/Resolver/CenterResolverInterface.php | 8 +++++--- .../Security/Resolver/CenterResolverManagerInterface.php | 1 + 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Security/Resolver/CenterResolverDispatcher.php b/src/Bundle/ChillMainBundle/Security/Resolver/CenterResolverDispatcher.php index 1042f3931..e6cdd8b0c 100644 --- a/src/Bundle/ChillMainBundle/Security/Resolver/CenterResolverDispatcher.php +++ b/src/Bundle/ChillMainBundle/Security/Resolver/CenterResolverDispatcher.php @@ -22,6 +22,7 @@ final class CenterResolverDispatcher } /** + * @param object $entity * @return null|Center|Center[] */ public function resolveCenter($entity, ?array $options = []) diff --git a/src/Bundle/ChillMainBundle/Security/Resolver/CenterResolverInterface.php b/src/Bundle/ChillMainBundle/Security/Resolver/CenterResolverInterface.php index db49874b7..f3bf44b5a 100644 --- a/src/Bundle/ChillMainBundle/Security/Resolver/CenterResolverInterface.php +++ b/src/Bundle/ChillMainBundle/Security/Resolver/CenterResolverInterface.php @@ -6,12 +6,14 @@ use Chill\MainBundle\Entity\Center; interface CenterResolverInterface { + /** + * @param object $entity + */ public function supports($entity, ?array $options = []): bool; /** - * @param $entity - * @param array|null $options - * @return Center|array|Center[] + * @param object $entity + * @return Center|Center[] */ public function resolveCenter($entity, ?array $options = []); diff --git a/src/Bundle/ChillMainBundle/Security/Resolver/CenterResolverManagerInterface.php b/src/Bundle/ChillMainBundle/Security/Resolver/CenterResolverManagerInterface.php index deaaff182..1ca145b99 100644 --- a/src/Bundle/ChillMainBundle/Security/Resolver/CenterResolverManagerInterface.php +++ b/src/Bundle/ChillMainBundle/Security/Resolver/CenterResolverManagerInterface.php @@ -9,6 +9,7 @@ use Chill\MainBundle\Entity\Center; interface CenterResolverManagerInterface { /** + * @param object $entity * @return Center[] */ public function resolveCenters($entity, ?array $options = []): array; From 5a6a15a35126e7f7008bd61cd5e0bab3ba063606 Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Fri, 19 Nov 2021 12:31:48 +0100 Subject: [PATCH 29/31] fix: Add missing repository. --- .../ActivityTypeCategoryRepository.php | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/Bundle/ChillActivityBundle/Repository/ActivityTypeCategoryRepository.php diff --git a/src/Bundle/ChillActivityBundle/Repository/ActivityTypeCategoryRepository.php b/src/Bundle/ChillActivityBundle/Repository/ActivityTypeCategoryRepository.php new file mode 100644 index 000000000..62a6a9a0d --- /dev/null +++ b/src/Bundle/ChillActivityBundle/Repository/ActivityTypeCategoryRepository.php @@ -0,0 +1,23 @@ + Date: Fri, 19 Nov 2021 12:32:05 +0100 Subject: [PATCH 30/31] fix: Fix wrong repository. --- .../Controller/ActivityController.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/Bundle/ChillActivityBundle/Controller/ActivityController.php b/src/Bundle/ChillActivityBundle/Controller/ActivityController.php index 47ebebd09..5e7e0de21 100644 --- a/src/Bundle/ChillActivityBundle/Controller/ActivityController.php +++ b/src/Bundle/ChillActivityBundle/Controller/ActivityController.php @@ -7,6 +7,7 @@ namespace Chill\ActivityBundle\Controller; use Chill\ActivityBundle\Entity\ActivityReason; use Chill\ActivityBundle\Repository\ActivityACLAwareRepositoryInterface; use Chill\ActivityBundle\Repository\ActivityRepository; +use Chill\ActivityBundle\Repository\ActivityTypeCategoryRepository; use Chill\ActivityBundle\Repository\ActivityTypeRepository; use Chill\ActivityBundle\Security\Authorization\ActivityVoter; use Chill\MainBundle\Repository\LocationRepository; @@ -54,9 +55,12 @@ final class ActivityController extends AbstractController private AccompanyingPeriodRepository $accompanyingPeriodRepository; + private ActivityTypeCategoryRepository $activityTypeCategoryRepository; + public function __construct( ActivityACLAwareRepositoryInterface $activityACLAwareRepository, ActivityTypeRepository $activityTypeRepository, + ActivityTypeCategoryRepository $activityTypeCategoryRepository, PersonRepository $personRepository, ThirdPartyRepository $thirdPartyRepository, LocationRepository $locationRepository, @@ -69,6 +73,7 @@ final class ActivityController extends AbstractController ) { $this->activityACLAwareRepository = $activityACLAwareRepository; $this->activityTypeRepository = $activityTypeRepository; + $this->activityTypeCategoryRepository = $activityTypeCategoryRepository; $this->personRepository = $personRepository; $this->thirdPartyRepository = $thirdPartyRepository; $this->locationRepository = $locationRepository; @@ -136,10 +141,17 @@ final class ActivityController extends AbstractController $data = []; - $activityTypeCategories = $this->activityTypeRepository->findBy(['active' => true], ['ordering' => 'ASC']); + $activityTypeCategories = $this + ->activityTypeCategoryRepository + ->findBy(['active' => true], ['ordering' => 'ASC']); foreach ($activityTypeCategories as $activityTypeCategory) { - $activityTypes = $this->activityTypeRepository->findBy(['active' => true, 'category' => $activityTypeCategory], ['ordering' => 'ASC']); + $activityTypes = $this + ->activityTypeRepository + ->findBy( + ['active' => true, 'category' => $activityTypeCategory], + ['ordering' => 'ASC'] + ); $data[] = [ 'activityTypeCategory' => $activityTypeCategory, From 0a522b465fbb28eec9c3fa9c162a24930c945b9e Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Fri, 19 Nov 2021 12:32:21 +0100 Subject: [PATCH 31/31] fix: Update typing information. --- .../Entity/ActivityTypeCategory.php | 28 ++----------------- 1 file changed, 3 insertions(+), 25 deletions(-) diff --git a/src/Bundle/ChillActivityBundle/Entity/ActivityTypeCategory.php b/src/Bundle/ChillActivityBundle/Entity/ActivityTypeCategory.php index a95424312..4b06ca9b5 100644 --- a/src/Bundle/ChillActivityBundle/Entity/ActivityTypeCategory.php +++ b/src/Bundle/ChillActivityBundle/Entity/ActivityTypeCategory.php @@ -1,31 +1,12 @@ - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ +declare(strict_types=1); namespace Chill\ActivityBundle\Entity; use Doctrine\ORM\Mapping as ORM; /** - * Class ActivityTypeCateogry - * - * @package Chill\ActivityBundle\Entity * @ORM\Entity() * @ORM\Table(name="activitytypecategory") * @ORM\HasLifecycleCallbacks() @@ -37,7 +18,7 @@ class ActivityTypeCategory * @ORM\Column(name="id", type="integer") * @ORM\GeneratedValue(strategy="AUTO") */ - private ?int $id; + private ?int $id = null; /** * @ORM\Column(type="json") @@ -54,10 +35,7 @@ class ActivityTypeCategory */ private float $ordering = 0.0; - /** - * Get id - */ - public function getId(): int + public function getId(): ?int { return $this->id; }