Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow doctrine/orm 3 & doctrine/bdal 4 #30

Merged
merged 1 commit into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
"php": ">=8.0",
"ext-mbstring": "*",
"doctrine/annotations": "^1.10 || ^2.0",
"doctrine/doctrine-bundle": "^2.7.1",
"doctrine/orm": "^2.14",
"doctrine/doctrine-bundle": "^2.8.0",
"doctrine/orm": "^2.14 || ^3.0",
"paragonie/ciphersweet": "^3.0 || ^4.0",
"symfony/config": "^5.4 || ^6.4 || ^7.0",
"symfony/console": "^5.4 || ^6.4 || ^7.0",
Expand All @@ -41,7 +41,7 @@
"require-dev": {
"phpunit/phpunit": "^9.5",
"symfony/browser-kit": "^5.4 || ^6.4 || ^7.0",
"symfony/doctrine-bridge": "^6.4",
"symfony/doctrine-bridge": "^6.4 || ^7.0",
"symfony/phpunit-bridge": "^6.4",
"symfony/yaml": "^5.4 || ^6.4 || ^7.0"
},
Expand Down
5 changes: 4 additions & 1 deletion config/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,10 @@
service('encryption.indexable_field'),
service('encryption.property_hydrator')
])
->tag('doctrine.event_subscriber')
->tag('doctrine.event_listener', ['event' => 'postLoad'])
->tag('doctrine.event_listener', ['event' => 'onFlush'])
->tag('doctrine.event_listener', ['event' => 'postFlush'])
->tag('doctrine.event_listener', ['event' => 'onClear'])

->set('encryption.encrypted_fields', EncryptedFieldsService::class)
->args([
Expand Down
8 changes: 6 additions & 2 deletions src/Services/PropertyHydratorService.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,12 @@ public function setValueToMappedField(#[\SensitiveParameter] object $entity, #[\
return;
}

$propertyInfoType = $this->propertyInfoExtractor->getTypes(get_class($entity), $propertyName)[0];
$targetType = $propertyInfoType->getBuiltinType();
if (property_exists($this->propertyInfoExtractor, 'getType')) {
$targetType = (string) $this->propertyInfoExtractor->getType();
} else {
$propertyInfoType = $this->propertyInfoExtractor->getTypes(get_class($entity), $propertyName)[0];
$targetType = $propertyInfoType->getBuiltinType();
}

if ($targetType !== Type::BUILTIN_TYPE_STRING) {
settype($value, $targetType);
Expand Down
21 changes: 6 additions & 15 deletions src/Subscribers/DoctrineCiphersweetSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Odandb\DoctrineCiphersweetEncryptionBundle\Subscribers;

use Doctrine\Bundle\DoctrineBundle\EventSubscriber\EventSubscriberInterface;
use Doctrine\Bundle\DoctrineBundle\Attribute\AsDoctrineListener;
use Doctrine\ORM\Event\PostLoadEventArgs;
use Doctrine\Persistence\ObjectManager;
use Doctrine\ORM\UnitOfWork;
Expand All @@ -25,7 +25,11 @@
/**
* @internal
*/
class DoctrineCiphersweetSubscriber implements EventSubscriberInterface, ResetInterface
#[AsDoctrineListener(event: Events::postLoad)]
#[AsDoctrineListener(event: Events::onFlush)]
#[AsDoctrineListener(event: Events::postFlush)]
#[AsDoctrineListener(event: Events::onClear)]
class DoctrineCiphersweetSubscriber implements ResetInterface
{
public const ENCRYPTED_ANN_NAME = EncryptedField::class;
public const INDEXABLE_ANN_NAME = IndexableField::class;
Expand Down Expand Up @@ -91,19 +95,6 @@ public function __construct(
$this->propertyHydratorService = $propertyHydratorService;
}

/**
* {@inheritdoc}
*/
public function getSubscribedEvents(): array
{
return [
Events::postLoad,
Events::onFlush,
Events::postFlush,
Events::onClear,
];
}

public function reset(): void
{
$this->_originalValues = [];
Expand Down
2 changes: 1 addition & 1 deletion tests/App/Model/MyEntityAttributeIndexes.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ class MyEntityAttributeIndexes implements IndexedEntityInterface
use IndexedEntityAttributeTrait;

#[ORM\ManyToOne(targetEntity: MyEntityAttribute::class)]
#[ORM\JoinColumn(name: 'target_entity_id', referencedColumnName: 'id', onDelete: 'CASCADE', nullable: false)]
#[ORM\JoinColumn(name: 'target_entity_id', referencedColumnName: 'id', nullable: false, onDelete: 'CASCADE')]
protected object $targetEntity;
}
3 changes: 3 additions & 0 deletions tests/App/doctrine.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ doctrine:
orm:
default_entity_manager: default
auto_generate_proxy_classes: true
enable_lazy_ghost_objects: true
naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
controller_resolver:
auto_mapping: true
auto_mapping: true
mappings:
Attribute:
Expand Down