|
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 |
|
|
|
|
|
|
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
|
|
|
|
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.