Skip to content

Commit

Permalink
Rework service-definitions and split it up in multiple files so we su…
Browse files Browse the repository at this point in the history
…pport sf 4.x-7.x
  • Loading branch information
Zombaya committed Dec 9, 2023
1 parent e93cce7 commit 2649be2
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 16 deletions.
19 changes: 16 additions & 3 deletions src/DependencyInjection/DoctrineEncryptExtension.php
Expand Up @@ -8,6 +8,7 @@
use Symfony\Component\Config\FileLocator;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\Loader;
use Symfony\Component\HttpKernel\Kernel;

/**
* Initialization of bundle.
Expand Down Expand Up @@ -58,9 +59,21 @@ public function load(array $configs, ContainerBuilder $container): void
$loader->load('services_with_secret.yml');
}

// Remove usage of AttributeAnnotationReader when using php < 8.0
if (PHP_VERSION_ID < 80000) {
$container->setAlias('ambta_doctrine_annotation_reader','annotations.reader');
// Symfony 1-3
if (Kernel::MAJOR_VERSION < 4) {
throw new \RuntimeException('doctrineencryptbundle/doctrine-encrypt-bundle expects symfony-version >= 4.1!');
// Symfony 4-6
} elseif (Kernel::MAJOR_VERSION < 7) {
// PHP 7.x (no attributes)
if (PHP_VERSION_ID < 80000) {
$loader->load('services_subscriber_sf4_php7.yml');
// PHP 8.x (annotations and attributes)
} else {
$loader->load('services_subscriber_sf4_php8.yml');
}
// Symfony 7 (only attributes)
} else {
$loader->load('services_subscriber_sf7.yml');
}
}

Expand Down
13 changes: 0 additions & 13 deletions src/Resources/config/services.yml
@@ -1,17 +1,4 @@
services:
ambta_doctrine_attribute_reader:
class: Ambta\DoctrineEncryptBundle\Mapping\AttributeReader

ambta_doctrine_annotation_reader:
class: Ambta\DoctrineEncryptBundle\Mapping\AttributeAnnotationReader
arguments: ["@ambta_doctrine_attribute_reader", "@annotations.reader", "%kernel.cache_dir%"]

ambta_doctrine_encrypt.orm_subscriber:
class: Ambta\DoctrineEncryptBundle\Subscribers\DoctrineEncryptSubscriber
arguments: ["@ambta_doctrine_annotation_reader", "@ambta_doctrine_encrypt.encryptor"]
tags:
- { name: doctrine.event_subscriber }

ambta_doctrine_encrypt.subscriber:
alias: ambta_doctrine_encrypt.orm_subscriber

Expand Down
9 changes: 9 additions & 0 deletions src/Resources/config/services_subscriber_sf4_php7.yml
@@ -0,0 +1,9 @@
services:
# Use the regular annotation reader
ambta_doctrine_annotation_reader: "@annotations.reader"

ambta_doctrine_encrypt.orm_subscriber:
class: Ambta\DoctrineEncryptBundle\Subscribers\DoctrineEncryptSubscriber
arguments: ["@ambta_doctrine_annotation_reader", "@ambta_doctrine_encrypt.encryptor"]
tags:
- { name: doctrine.event_subscriber }
13 changes: 13 additions & 0 deletions src/Resources/config/services_subscriber_sf4_php8.yml
@@ -0,0 +1,13 @@
services:
ambta_doctrine_attribute_reader:
class: Ambta\DoctrineEncryptBundle\Mapping\AttributeReader

ambta_doctrine_annotation_reader:
class: Ambta\DoctrineEncryptBundle\Mapping\AttributeAnnotationReader
arguments: ["@ambta_doctrine_attribute_reader", "@annotations.reader", "%kernel.cache_dir%"]

ambta_doctrine_encrypt.orm_subscriber:
class: Ambta\DoctrineEncryptBundle\Subscribers\DoctrineEncryptSubscriber
arguments: ["@ambta_doctrine_annotation_reader", "@ambta_doctrine_encrypt.encryptor"]
tags:
- { name: doctrine.event_subscriber }
15 changes: 15 additions & 0 deletions src/Resources/config/services_subscriber_sf7.yml
@@ -0,0 +1,15 @@
services:
ambta_doctrine_attribute_reader:
class: Ambta\DoctrineEncryptBundle\Mapping\AttributeReader

ambta_doctrine_annotation_reader: '@ambta_doctrine_attribute_reader'

ambta_doctrine_encrypt.orm_subscriber:
class: Ambta\DoctrineEncryptBundle\Subscribers\DoctrineEncryptSubscriber
arguments: [ '@ambta_doctrine_attribute_reader', '@ambta_doctrine_encrypt.encryptor' ]
tags:
- { name: 'doctrine.event_listener', event: 'postLoad' }
- { name: 'doctrine.event_listener', event: 'onFlush' }
- { name: 'doctrine.event_listener', event: 'preFlush' }
- { name: 'doctrine.event_listener', event: 'postFlush' }
- { name: 'doctrine.event_listener', event: 'onClear' }

0 comments on commit 2649be2

Please sign in to comment.