Completed
Push — master ( 64fdfa...f07eb7 )
by Aimeos
02:02
created

FosUser::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 5
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2015-2016
6
 * @package MShop
7
 * @subpackage Customer
8
 */
9
10
11
namespace Aimeos\MShop\Customer\Item;
12
13
14
/**
15
 * Customer DTO object for the FosUserBundle.
16
 *
17
 * @package MShop
18
 * @subpackage Customer
19
 */
20
class FosUser
21
	extends \Aimeos\MShop\Customer\Item\Standard
0 ignored issues
show
Coding Style introduced by
The extends keyword must be on the same line as the class name
Loading history...
22
{
23
	private $values;
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
24
	private $helper;
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
25
26
27
	/**
28
	 * Initializes the customer item object
29
	 *
30
	 * @param \Aimeos\MShop\Common\Item\Address\Iface $address Payment address item object
31
	 * @param array $values List of attributes that belong to the customer item
32
	 * @param \Aimeos\MShop\Common\Lists\Item\Iface[] $listItems List of list items
33
	 * @param \Aimeos\MShop\Common\Item\Iface[] $refItems List of referenced items
34
	 * @param \Aimeos\MShop\Common\Item\Helper\Password\Iface|null $helper Password encryption helper object
35
	 */
36
	public function __construct( \Aimeos\MShop\Common\Item\Address\Iface $address, array $values = array(),
37
		array $listItems = array(), array $refItems = array(), \Aimeos\MShop\Common\Item\Helper\Password\Iface $helper = null )
38
	{
39
		parent::__construct( $address, $values, $listItems, $refItems, $helper );
40
41
		$this->values = $values;
42
		$this->helper = $helper;
43
	}
44
45
46
47
	/**
48
	 * Returns the password of the customer item.
49
	 *
50
	 * @return string Password string
51
	 */
52
	public function getPassword()
53
	{
54
		if( isset( $this->values['customer.password'] ) ) {
55
			return (string) $this->values['customer.password'];
56
		}
57
58
		return '';
59
	}
60
61
62
	/**
63
	 * Sets the password of the customer item.
64
	 *
65
	 * @param string $value Password of the customer item
66
	 * @return \Aimeos\MShop\Customer\Item\Iface Customer item for chaining method calls
67
	 */
68
	public function setPassword( $value )
69
	{
70
		if( $value == $this->getPassword() ) { return $this; }
71
72
		if( $this->helper !== null ) {
73
			$value = $this->helper->encode( $value, $this->getSalt() );
74
		}
75
76
		$this->values['customer.password'] = (string) $value;
77
		$this->setModified();
78
79
		return $this;
80
	}
81
82
83
	/**
84
	 * Returns the associated user roles
85
	 *
86
	 * @return array List of Symfony roles
87
	 */
88
	public function getRoles()
89
	{
90
		if( isset( $this->values['roles'] ) ) {
91
			return (array) $this->values['roles'];
92
		}
93
94
		return array();
95
	}
96
97
98
	/**
99
	 * Sets the associated user roles
100
	 *
101
	 * @param array $roles List of Symfony roles
102
	 */
103
	public function setRoles( array $roles )
104
	{
105
		$this->values['roles'] = $roles;
106
		$this->setModified();
107
108
		return $this;
109
	}
110
111
112
	/**
113
	 * Returns the password salt
114
	 *
115
	 * @return string Password salt
116
	 */
117
	public function getSalt()
118
	{
119
		if( !isset( $this->values['salt'] ) ) {
120
			$this->values['salt'] = sha1( microtime( true ) . getmypid() );
121
		}
122
123
		return $this->values['salt'];
124
	}
125
126
127
	/**
128
	 * Sets the password salt
129
	 *
130
	 * @param string $value Password salt
131
	 */
132
	public function setSalt( $value )
133
	{
134
		$this->values['salt'] = (string) $value;
135
		$this->setModified();
136
137
		return $this;
138
	}
139
}
140