My autowiring is not working for a basic file entity listener.
I have a File entity class which uses annotations to specify the listener, like:
/**
@Orm\Entity(repositoryClass="root\CoreBundle\Repository\FileRepository")
@Orm\EntityListeners({"root\CoreBundle\EventListener\Entity\FileEntityListener"})
@Orm\Table(
etc...
The FileEntityListener class starts off as follows:
class FileEntityListener
{
private $encoderFactory;
private $logger;
public function __construct(FilesystemMap $filesystemMap, LoggerInterface $logger)
{
$this->setFilesystemMap($filesystemMap);
$this->logger = $logger;
}
When the listener kicks in, the dependencies aren't injecting into the constructor of the listener and I get an error for the constructor, saying:
Type error: Too few arguments to function Epcvip\CoreBundle\EventListener\Entity\FileEntityListener::__construct(), 0 passed in /var/www/html/accounting/vendor/doctrine/doctrine-bundle/Mapping/ContainerAwareEntityListenerResolver.php on line 83 and exactly 2 expected
The bundle is autowired and yet the dependencies are not being injected.
Would anyone know why this isn't working? Maybe a slight configuration step I am missing?
You need to tag your entity listener like this in services.yaml:
services:
root\CoreBundle\EventListener\Entity\FileEntityListener
tags:
- { name: doctrine.orm.entity_listener }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With