Open danaki opened 4 years ago
It is not possible without overriding BlameableListener
, but additionaly you need compiler pass if you need to inject custom dependencies, for example using process
function from your app kernel. You will need to inject them using setters instead of constructors because of endless loop:
/**
* You can modify the container here before it is dumped to PHP code.
*/
public function process(ContainerBuilder $container): void
{
$container
->getDefinition('stof_doctrine_extensions.listener.blameable')
->addMethodCall('setEntityManager', [$container->getDefinition(EntityManagerInterface::class)])
;
}
Custom blameable listener need to extend default class, example of it:
class BlameableListenerDecorator extends BlameableListener
{
/**
* @var EntityManagerInterface
*/
private $em;
public function setEntityManager(EntityManagerInterface $em): void
{
$this->em = $em;
}
public function setUserValue($user): void
{
if ($user instanceof CustomUser) {
$user = $this->em->find(UserEntity::class, $user->getId());
}
parent::setUserValue($user);
}
}
BTW Consider moving to supported fork https://github.com/antishov/StofDoctrineExtensionsBundle
Didn't know about the fork. Ok, I'll reopen this issue there.
Hi, I'm using decoupled Entity and security user like it's described here https://stovepipe.systems/post/decoupling-your-security-user
The reason for that is that I want to keep domain separated following DDD principles.
Now my entity looks like:
while class 'App\Security\User\SecurityUser' implements actual UserInterface.
When I try to save the entity, it produces an error:
Which is because of this line of code:
$token->getUser()
returns an object of classApp\\Security\\User\\SecurityUser
not the Entity. Is it possible to override this behavior introducing a configuration option?