2014-09-11 2 views
2

je comme auditeurSymfony2: abonné Doctrine lance ContextErrorException - doit être une instance de Doctrine Common persistance Event PreUpdateEventArgs

use Doctrine\Common\EventSubscriber; 
use Doctrine\Common\Persistence\Event\LifecycleEventArgs; 
use Doctrine\Common\Persistence\Event\PreUpdateEventArgs; 
use Doctrine\Common\Persistence\ObjectManager; 
use Doctrine\ORM\Events; 

class MachineSubscriber implements EventSubscriber 

et méthode

/** 
    * @param PreUpdateEventArgs $args 
    */ 
    public function preUpdate(PreUpdateEventArgs $args) 

et Doctrine jet Exception

ContextErrorException: Catchable Fatal Error: Argument 1 passed to Certificate\MachineBundle\Event\MachineSubscriber::preUpdate() must be an instance of Doctrine\Common\Persistence\Event\PreUpdateEventArgs, instance of Doctrine\ORM\Event\PreUpdateEventArgs given,

Son étrange parce que j'utilise la bonne classe.

Répondre

3

Vous utilisez le mauvais espace de noms/classe pour taper l'argument de la fonction preUpdate(). Le bon hierarchy est:

Doctrine\Common\EventArgs 
|_ Doctrine\ORM\Event\LifecycleEventArgs 
    |_ Doctrine\ORM\Event\PreUpdateEventArgs 

Typehint avec ...

use Doctrine\Common\EventArgs; 

public function preUpdate(EventArgs $args) 
{ 
    // ... 

... ou ...

use Doctrine\ORM\Event\LifecycleEventArgs; 

public function preUpdate(LifecycleEventArgs $args) 
{ 
    // ... 

... ou ...

use Doctrine\ORM\Event\PreUpdateEventArgs; 

public function preUpdate(PreUpdateEventArgs $args) 
{ 
    // ... 

... mais pas avec:

use Doctrine\Common\Persistence\Event\PreUpdateEventArgs; 
Questions connexes