Closed bertoost closed 1 year ago
Hi @bertoost, auditor
can be used outside of a Symfony project, that's why it doesn't require an autowired Symfony service for storage mapper.
A storage mapper has to be a closure/callable/invokable. It takes 2 parameters: an entity name and an array of storage services. It must return the storage service (from the provided array) handling the provided entity name.
There was a bug until version 2.4.2
which prevented using invokable classes, it's fixed now.
Let me give you an example:
<?php
namespace App;
use App\Entity\MyEntity1;
use App\Entity\MyEntity2;
use App\Entity\MyEntity3;
use DH\Auditor\Provider\Service\StorageServiceInterface;
/**
* MyStorageMapper is an invokable class/service
*
*/
class MyStorageMapper
{
// the service expects 2 parameters and should return an object
// implementing StorageServiceInterface
public function __invoke(string $entity, array $storageServices): StorageServiceInterface {
return \in_array($entity, [MyEntity1::class, MyEntity2::class], true) ? $storageServices['db1'] : $storageServices['db2'];
}
}
Then, if using auditor-bundle
, register it as a storage mapper
# config/packages/dh_auditor.yaml
dh_auditor:
providers:
doctrine:
# Invokable service that maps audit events to storage services
storage_mapper: App\MyStorageMapper
Thanks @DamienHarper ! The storage mapper now works. I had to report this on the bundle maybe ;-)
Therefore I am now running into this error when running schema-update command of doctrine.
In MappingException.php line 26:
[Doctrine\Persistence\Mapping\MappingException]
The class 'App\Entity\Tenant\Student' was not found in the chain configured namespaces App\Entity\Main
The namespace is configured on the second entity-manager which I do correctly map in the storage mapper.
@bertoost can you provide more debug trace?
@bertoost I close this issue since no feedback has been provided, feel free to reopen it if needed.
Hi there,
I have configured multiple entity-managers and therefore I understand I have to configure a storage mapper.
I have created one like the example in documentation, as follows;
And configured it like
And tried multiple configurations... but I always get this error;
How should I manage this?
In your DoctrineProvider it just does
return $storageMapper($entity, $this->getStorageServices());
, without new or something. Therefore... why not used a normal service class? which is auto-wired or default instantiated in Symfony?Kind regards, Bert