Completed
Push — EZP-31644 ( 2e0a1e...93bb44 )
by
unknown
19:12
created

Identity   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 88
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 88
rs 10
c 0
b 0
f 0
wmc 9
lcom 1
cbo 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A addInformation() 0 5 1
A setInformation() 0 5 1
A replaceInformation() 0 5 1
A getInformation() 0 4 1
A resetHash() 0 4 1
A getHash() 0 13 3
1
<?php
2
3
/**
4
 * File containing the user Identity class.
5
 *
6
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
7
 * @license For full copyright and license information view LICENSE file distributed with this source code.
8
 */
9
namespace eZ\Publish\Core\MVC\Symfony\Security\User;
10
11
use eZ\Publish\SPI\User\Identity as IdentityInterface;
12
13
/**
14
 * Represents a user "identity", or footprint.
15
 * Instance can be transformed to a hash and used as an identity token.
16
 *
17
 * @deprecated since 5.4. Will be removed in 6.0. Use FOSHttpCacheBundle user context feature instead.
18
 */
19
class Identity implements IdentityInterface
0 ignored issues
show
Deprecated Code introduced by
The interface eZ\Publish\SPI\User\Identity has been deprecated with message: since 5.4. Will be removed in 6.0. Use FOSHttpCacheBundle user context feature instead.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
20
{
21
    /**
22
     * @var array
23
     */
24
    protected $identityInfo;
25
26
    /**
27
     * @var string
28
     */
29
    protected $hash;
30
31
    public function __construct()
32
    {
33
        $this->identityInfo = [];
34
    }
35
36
    /**
37
     * Registers several pieces of information in the identity.
38
     *
39
     * @param array $information Hash where key is the information type and value is a scalar.
40
     */
41
    public function addInformation(array $information)
42
    {
43
        $this->identityInfo += $information;
44
        $this->resetHash();
45
    }
46
47
    /**
48
     * Registers an information in the identity.
49
     *
50
     * @param string $informationName
51
     * @param scalar $informationValue
52
     */
53
    public function setInformation($informationName, $informationValue)
54
    {
55
        $this->identityInfo[$informationName] = $informationValue;
56
        $this->resetHash();
57
    }
58
59
    /**
60
     * Replaces the information already registered in the identity.
61
     *
62
     * @param array $information Hash where key is the information type and value is a scalar.
63
     */
64
    public function replaceInformation(array $information)
65
    {
66
        $this->identityInfo = $information;
67
        $this->resetHash();
68
    }
69
70
    /**
71
     * Returns registered information.
72
     *
73
     * @return array
74
     */
75
    public function getInformation()
76
    {
77
        return $this->identityInfo;
78
    }
79
80
    /**
81
     * Resets current hash.
82
     */
83
    protected function resetHash()
84
    {
85
        $this->hash = null;
86
    }
87
88
    /**
89
     * Returns the hash of the current identity (e.g. md5, sha1...).
90
     *
91
     * @return string
92
     */
93
    public function getHash()
94
    {
95
        if (!isset($this->hash)) {
96
            $hashArray = [];
97
            foreach ($this->identityInfo as $infoType => $infoValue) {
98
                $hashArray[] = "$infoType=$infoValue";
99
            }
100
101
            $this->hash = sha1(implode('-', $hashArray));
102
        }
103
104
        return $this->hash;
105
    }
106
}
107