How to solve the "Circular link discovered for maintenance" problem?

I am trying to implement my repository service in EventListener, but this leads me to the next exception, which, with basic knowledge of Symfony2, I have no idea how to resolve it. The exception is:

ServiceCircularReferenceException on boot line 2129 loading bootstrap.php.cache:

A circular link was found for the service "doctrine.orm.default_entity_manager", path: "doctrine.orm.default_entity_manager → doctrine.dbal.default_connection → person.connect.listener → tag.repository.service".

And this is how I declared the repository and listener:

tag.repository.service:
    class: Application\Bundle\PersonBundle\Entity\TagRepository
    factory: ["@doctrine", getRepository]
    arguments: [ Application\Bundle\PersonBundle\Entity\Tag ]

person.connect.listener:
    class: Application\Bundle\PersonBundle\EventListener\ConnectListener
    arguments:
        tokenStorage: "@security.token_storage"
        tagRepo: "@tag.repository.service"
    tags:
        - { name: doctrine.event_listener, event: postPersist, connection: default }

, , , . ?

UPD: . , TagRepository

class ConnectListener
{
/**
 * @var TokenStorage
 */
private $tokenStorage;

/**
 * @var TagRepository
 */
private $tagRepo;

/**
 * @param TokenStorage $tokenStorage
 * @param TagRepository $tagRepo
 */
public function __construct(TokenStorage $tokenStorage, TagRepository $tagRepo)
{
    $this->tokenStorage = $tokenStorage;
}
/**
 * @param LifecycleEventArgs $args
 * @return void
 */
public function postPersist(LifecycleEventArgs $args)
{
    $entity = $args->getEntity();
    $entityManager = $args->getEntityManager();

    if ($entity instanceof Person) {
        $user = $this->tokenStorage->getToken()->getUser();
        $visibility = new PersonVisibility($entity, $user);
        $visibility->setVisibilityType(PersonVisibility::VT_CREATED);
        $entityManager->persist($visibility);
        $entityManager->flush();
    }
}
}
+4
1

TagRepository EntityRepository, postPersist. :

// using full classname:
$tagRepo = $entityManager->getRepository("Application\Bundle\PersonBundle\Entity\TagRepository");
// alternatively:
$tagRepo = $entityManager->getRepository("ApplicationPersonBundle:Tag");
+1

Source: https://habr.com/ru/post/1606493/


All Articles