Skip to content
Snippets Groups Projects
Select Git revision
  • d90b86ec2d690ea2f7f1424cafdf1506dd679aca
  • master default protected
  • 5.x
  • ll-php8-bs5
  • release_5_bs5
  • ll-php8
  • 4.x
  • laminas_migration
  • release_1.0.0.2
  • release_4.0.0
  • release_3.2.8
  • bootstrap4_migration
  • 1.0.0.3
  • 6.0.7
  • 6.0.6
  • 6.0.5
  • 6.0.4
  • 6.0.3
  • 6.0.2
  • 6.0.1
  • 5.1.1
  • 6.0.0
  • 5.1.0
  • 5.0.0
  • 4.0.2
  • 3.2.11
  • 4.0.1
  • 3.2.10
  • 4.0.0
  • 1.0.0.2
  • 3.2.9
  • 3.2.8
32 results

UserMapper.php

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    UserMapper.php 2.42 KiB
    <?php
    
    namespace UnicaenAuth\Service;
    
    use Doctrine\ORM\EntityManagerInterface;
    use UnicaenAuth\Entity\Db\AbstractUser;
    use UnicaenAuth\Options\ModuleOptions;
    use Zend\Stdlib\Hydrator\HydratorInterface;
    
    class UserMapper extends \ZfcUser\Mapper\User
    {
        //========== repris du module zf-commons/zfc-user-doctrine-orm abandonné =========
        /**
         * @var \Doctrine\ORM\EntityManagerInterface
         */
        protected $em;
    
        /**
         * @var ModuleOptions
         */
        protected $options;
    
        public function __construct(EntityManagerInterface $em, ModuleOptions $options)
        {
            $this->em      = $em;
            $this->options = $options;
        }
    
        public function findByEmail($email)
        {
            $er = $this->em->getRepository($this->options->getUserEntityClass());
    
            return $er->findOneBy(array('email' => $email));
        }
    
        public function findByUsername($username)
        {
            $er = $this->em->getRepository($this->options->getUserEntityClass());
    
            return $er->findOneBy(array('username' => $username));
        }
    
        public function findById($id)
        {
            $er = $this->em->getRepository($this->options->getUserEntityClass());
    
            return $er->find($id);
        }
    
        /**
         * {@inheritdoc}
         */
        public function insert($entity, $tableName = null, HydratorInterface $hydrator = null)
        {
            return $this->persist($entity);
        }
    
        /**
         * {@inheritdoc}
         */
        public function update($entity, $where = null, $tableName = null, HydratorInterface $hydrator = null)
        {
            return $this->persist($entity);
        }
    
        protected function persist($entity)
        {
            $this->em->persist($entity);
            $this->em->flush();