Commit f9bccb50 authored by Laurent Lecluse's avatar Laurent Lecluse
Browse files

Eradication de l'utilisation de l'ObjectManagerAware, devenu Deprecated.

A la place, injection automatique de l'entityManager aux entités implémentant EntityManagerAwareInterface
parent 6e9058bb
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -44,6 +44,7 @@ $config = [
                    \Doctrine\DBAL\Event\Listeners\OracleSessionInit::class,
                    ORM\Event\Listeners\HistoriqueListener::class,
                    ORM\Event\Listeners\ParametreEntityListener::class,
                    ORM\Event\Listeners\EntityManagerListener::class,
                ],
            ],
        ],
+2 −18
Original line number Diff line number Diff line
@@ -9,10 +9,9 @@ use Application\Entity\Db\Traits\PeriodeAwareTrait;
use Application\Entity\Db\Traits\SourceAwareTrait;
use Application\Entity\Db\Traits\StructureAwareTrait;
use Doctrine\Persistence\Mapping\ClassMetadata;
use Doctrine\Persistence\ObjectManager;
use Doctrine\Persistence\ObjectManagerAware;
use UnicaenApp\Entity\HistoriqueAwareInterface;
use UnicaenApp\Entity\HistoriqueAwareTrait;
use UnicaenApp\Service\EntityManagerAwareInterface;
use UnicaenApp\Service\EntityManagerAwareTrait;
use UnicaenImport\Entity\Db\Interfaces\ImportAwareInterface;
use UnicaenImport\Entity\Db\Traits\ImportAwareTrait;
@@ -22,7 +21,7 @@ use Laminas\Permissions\Acl\Resource\ResourceInterface;
/**
 * ElementPedagogique
 */
class ElementPedagogique implements HistoriqueAwareInterface, ResourceInterface, ImportAwareInterface, ObjectManagerAware
class ElementPedagogique implements HistoriqueAwareInterface, ResourceInterface, ImportAwareInterface, EntityManagerAwareInterface
{
    use HistoriqueAwareTrait;
    use DisciplineAwareTrait;
@@ -808,21 +807,6 @@ class ElementPedagogique implements HistoriqueAwareInterface, ResourceInterface,



    /**
     * Injects responsible ObjectManager and the ClassMetadata into this persistent object.
     *
     * @param ObjectManager $objectManager
     * @param ClassMetadata $classMetadata
     *
     * @return void
     */
    public function injectObjectManager(ObjectManager $objectManager, ClassMetadata $classMetadata)
    {
        $this->setEntityManager($objectManager);
    }



    function __sleep()
    {
        return [];
+2 −18
Original line number Diff line number Diff line
@@ -11,12 +11,11 @@ use Application\Entity\Db\Traits\StructureAwareTrait;
use Application\Entity\Traits\AdresseTrait;
use Application\Interfaces\AdresseInterface;
use Doctrine\Persistence\Mapping\ClassMetadata;
use Doctrine\Persistence\ObjectManager;
use Doctrine\Persistence\ObjectManagerAware;
use Indicateur\Entity\Db\IndicModifDossier;
use Intervenant\Entity\Db\Statut;
use UnicaenApp\Entity\HistoriqueAwareInterface;
use UnicaenApp\Entity\HistoriqueAwareTrait;
use UnicaenApp\Service\EntityManagerAwareInterface;
use UnicaenApp\Service\EntityManagerAwareTrait;
use UnicaenImport\Entity\Db\Interfaces\ImportAwareInterface;
use UnicaenImport\Entity\Db\Traits\ImportAwareTrait;
@@ -27,7 +26,7 @@ use Laminas\Permissions\Acl\Resource\ResourceInterface;
 * Intervenant
 *
 */
class Intervenant implements HistoriqueAwareInterface, ResourceInterface, ImportAwareInterface, ObjectManagerAware, AdresseInterface
class Intervenant implements HistoriqueAwareInterface, ResourceInterface, ImportAwareInterface, EntityManagerAwareInterface, AdresseInterface
{
    use AnneeAwareTrait;
    use StructureAwareTrait;
@@ -364,21 +363,6 @@ class Intervenant implements HistoriqueAwareInterface, ResourceInterface, Import



    /**
     * Injects responsible ObjectManager and the ClassMetadata into this persistent object.
     *
     * @param ObjectManager $objectManager
     * @param ClassMetadata $classMetadata
     *
     * @return void
     */
    public function injectObjectManager(ObjectManager $objectManager, ClassMetadata $classMetadata)
    {
        $this->setEntityManager($objectManager);
    }



    /**
     * @param bool $demande
     */
+2 −18
Original line number Diff line number Diff line
@@ -7,11 +7,10 @@ use Application\Entity\Db\Traits\EmployeurAwareTrait;
use Application\Entity\Traits\AdresseTrait;
use Application\Interfaces\AdresseInterface;
use Doctrine\Persistence\Mapping\ClassMetadata;
use Doctrine\Persistence\ObjectManager;
use Doctrine\Persistence\ObjectManagerAware;
use Intervenant\Entity\Db\Statut;
use UnicaenApp\Entity\HistoriqueAwareInterface;
use UnicaenApp\Entity\HistoriqueAwareTrait;
use UnicaenApp\Service\EntityManagerAwareInterface;
use UnicaenApp\Service\EntityManagerAwareTrait;
use Laminas\Permissions\Acl\Resource\ResourceInterface;

@@ -19,7 +18,7 @@ use Laminas\Permissions\Acl\Resource\ResourceInterface;
 * IntervenantDossier
 *
 */
class IntervenantDossier implements HistoriqueAwareInterface, ResourceInterface, ObjectManagerAware, AdresseInterface
class IntervenantDossier implements HistoriqueAwareInterface, ResourceInterface, EntityManagerAwareInterface, AdresseInterface
{
    use CiviliteAwareTrait;
    use AdresseTrait;
@@ -217,21 +216,6 @@ class IntervenantDossier implements HistoriqueAwareInterface, ResourceInterface,



    /**
     * Injects responsible ObjectManager and the ClassMetadata into this persistent object.
     *
     * @param ObjectManager $objectManager
     * @param ClassMetadata $classMetadata
     *
     * @return void
     */
    public function injectObjectManager(ObjectManager $objectManager, ClassMetadata $classMetadata)
    {
        $this->setEntityManager($objectManager);
    }



    /**
     * Get statut
     *
+45 −0
Original line number Diff line number Diff line
<?php

namespace Application\ORM\Event\Listeners;


use Application\Interfaces\ParametreEntityInterface;
use Application\Service\Traits\ContextServiceAwareTrait;
use Application\Service\Traits\UtilisateurServiceAwareTrait;
use Doctrine\Common\EventSubscriber;
use Doctrine\ORM\Event\LifecycleEventArgs;
use Doctrine\ORM\Event\PreUpdateEventArgs;
use Doctrine\ORM\Events;
use Doctrine\ORM\Mapping\PostLoad;
use UnicaenApp\Entity\HistoriqueAwareInterface;
use UnicaenApp\Service\EntityManagerAwareInterface;

/**
 * Description of HistoriqueListener
 *
 * @author Laurent Lécluse <laurent.lecluse at unicaen.fr>
 */
class EntityManagerListener implements EventSubscriber
{

    public function postload(LifecycleEventArgs $args)
    {
        $entity = $args->getEntity();
        if ($entity instanceof EntityManagerAwareInterface) {
            if (!$entity->getEntityManager()) {
                $entity->setEntityManager($args->getEntityManager());
            }
        }
    }



    /**
     * {@inheritdoc}
     */
    public function getSubscribedEvents()
    {
        return [Events::postLoad];
    }

}
 No newline at end of file
Loading