|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of Jitamin. |
|
5
|
|
|
* |
|
6
|
|
|
* Copyright (C) Jitamin Team |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Jitamin\Foundation\Identity; |
|
13
|
|
|
|
|
14
|
|
|
use Jitamin\Bus\Event\UserProfileSyncEvent; |
|
15
|
|
|
use Jitamin\Foundation\Base; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* User Profile. |
|
19
|
|
|
*/ |
|
20
|
|
|
class UserProfile extends Base |
|
21
|
|
|
{ |
|
22
|
|
|
const EVENT_USER_PROFILE_AFTER_SYNC = 'user_profile.after.sync'; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Assign provider data to the local user. |
|
26
|
|
|
* |
|
27
|
|
|
* @param int $userId |
|
28
|
|
|
* @param UserProviderInterface $user |
|
29
|
|
|
* |
|
30
|
|
|
* @return bool |
|
31
|
|
|
*/ |
|
32
|
|
|
public function assign($userId, UserProviderInterface $user) |
|
33
|
|
|
{ |
|
34
|
|
|
$profile = $this->userModel->getById($userId); |
|
|
|
|
|
|
35
|
|
|
|
|
36
|
|
|
$values = UserProperty::filterProperties($profile, UserProperty::getProperties($user)); |
|
37
|
|
|
$values['id'] = $userId; |
|
38
|
|
|
|
|
39
|
|
|
if ($this->userModel->update($values)) { |
|
|
|
|
|
|
40
|
|
|
$profile = array_merge($profile, $values); |
|
41
|
|
|
$this->userSession->initialize($profile); |
|
|
|
|
|
|
42
|
|
|
|
|
43
|
|
|
return true; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
return false; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Synchronize user properties with the local database and create the user session. |
|
51
|
|
|
* |
|
52
|
|
|
* @param UserProviderInterface $user |
|
53
|
|
|
* |
|
54
|
|
|
* @return bool |
|
55
|
|
|
*/ |
|
56
|
|
|
public function initialize(UserProviderInterface $user) |
|
57
|
|
|
{ |
|
58
|
|
|
if ($user->getInternalId()) { |
|
59
|
|
|
$profile = $this->userModel->getById($user->getInternalId()); |
|
|
|
|
|
|
60
|
|
|
} elseif ($user->getExternalIdColumn() && $user->getExternalId()) { |
|
61
|
|
|
$profile = $this->userSync->synchronize($user); |
|
|
|
|
|
|
62
|
|
|
if ($profile && isset($profile['id'])) { |
|
63
|
|
|
$this->groupSync->synchronize($profile['id'], $user->getExternalGroupIds()); |
|
|
|
|
|
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
if (!empty($profile) && $profile['is_active'] == 1) { |
|
68
|
|
|
$this->userSession->initialize($profile); |
|
|
|
|
|
|
69
|
|
|
$this->dispatcher->dispatch(self::EVENT_USER_PROFILE_AFTER_SYNC, new UserProfileSyncEvent($profile, $user)); |
|
|
|
|
|
|
70
|
|
|
|
|
71
|
|
|
return true; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
return false; |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|
Since your code implements the magic getter
_get, this function will be called for any read access on an undefined variable. You can add the@propertyannotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.