Db.php 1.8 KB
Newer Older
Bertrand Gauthier's avatar
Bertrand Gauthier committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<?php

namespace UnicaenAuth\Authentication\Storage;

use Zend\Authentication\Exception\InvalidArgumentException;

/**
 * Db authentication storage.
 *
 * @author Bertrand GAUTHIER <bertrand.gauthier at unicaen.fr>
 */
class Db extends \ZfcUser\Authentication\Storage\Db
{
    /**
     * Returns the contents of storage
     *
     * Behavior is undefined when storage is empty.
     *
     * @throws InvalidArgumentException If reading contents from storage is impossible
     * @return \ZfcUser\Entity\UserInterface
     */
    public function read()
    {
        $id = $this->getStorage()->read();
        
        try {
            $identity = parent::read();
        }
        catch (\PDOException $pdoe) {
Bertrand Gauthier's avatar
Bertrand Gauthier committed
30
31
32
33
            // throw new \UnicaenApp\Exception(
            //         "Erreur lors de la recherche de l'utilisateur $id dans la base de données : " . $pdoe->getMessage(),
            //         null,
            //         $pdoe);
Bertrand Gauthier's avatar
Bertrand Gauthier committed
34
35
36
37
38
39
40
41
42
43
44
45
46
            $identity = null;
        }
        if ($identity && !is_scalar($identity)) {
            return $identity;
        }
        
        $username = $this->getStorage()->read();
        
        if (is_string($username)) {
            try {
                $identity = $this->getMapper()->findByUsername($username);
            }
            catch (\PDOException $pdoe) {
Bertrand Gauthier's avatar
Bertrand Gauthier committed
47
48
49
50
                // throw new \UnicaenApp\Exception(
                //         "Erreur lors de la recherche de l'utilisateur '$username' dans la base de données : " . $pdoe->getMessage(),
                //         null,
                //         $pdoe);
Bertrand Gauthier's avatar
Bertrand Gauthier committed
51
52
53
54
55
56
57
58
59
60
61
62
63
                $identity = null;
            }
        }

        if ($identity) {
            $this->resolvedIdentity = $identity;
        } else {
            $this->resolvedIdentity = null;
        }
        
        return $this->resolvedIdentity;
    }
}