Based on this message , and after correcting the situation, I have another question / problem / problem.
As you can see in another post, I'm trying to inject a security context into a listener, but if I leave the code unchanged, I get this error:
ServiceCircularReferenceException: A circular reference was found for service "doctrine.orm.default_entity_manager"
So, reading and researching, I found a solution, but it is not clear to me whether it is correct or if it is protected for my application. So here is what I did:
Instead of input, [@security.context]I did this:
services:
orderhascomment.listener:
class: PL\OrderBundle\Listener\OrderHasCommentListener
arguments: [@service_container]
tags:
- { name: doctrine.event_listener, event: prePersist, method: onPrePersist }
OrderHasCommentListener.php :
namespace PL\OrderBundle\Listener;
use Doctrine\ORM\Event\LifecycleEventArgs;
use Symfony\Component\DependencyInjection\ContainerInterface;
class OrderHasCommentListener {
protected $container;
public function __construct(ContainerInterface $container = null) {
$this->container = $container;
}
public function onPrePersist(LifecycleEventArgs $args) {
$entity = $args->getEntity();
$user = $this->container->get('security.context')->getToken()->getUser();
$entity->setUser($user);
}
}
? ? , , , ? (https://insight.sensiolabs.com/what-we-analyse)
UserCallable
UserCallable , DoctrineBehaviors orm-services.yml , BlameableListener, , :
ContextErrorException: Catchable Fatal Error: 1 PL\OrderBundle\Listener\OrderHasCommentListener:: __ construct() , ,
app/config/config.yml:
services:
orderhascomment.listener:
class: PL\OrderBundle\Listener\OrderHasCommentListener
arguments:
- user_callable
tags:
- { name: doctrine.event_listener, event: prePersist, method: onPrePersist }
user_callable:
class: PL\OrderBundle\Util\UserCallable
arguments:
- "@service_container"
public: false
__construct() OrderHasCommentListener.php:
public function __construct(callable $user_callable = null) {
$this->userCallable = $user_callable;
}
?