|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* YAWIK |
|
4
|
|
|
* |
|
5
|
|
|
* @filesource |
|
6
|
|
|
* @copyright (c) 2013-2015 Cross Solution (http://cross-solution.de) |
|
7
|
|
|
* @license MIT |
|
8
|
|
|
*/ |
|
9
|
|
|
namespace Auth; |
|
10
|
|
|
|
|
11
|
|
|
use Zend\Authentication\AuthenticationService as ZendAuthService; |
|
12
|
|
|
use Zend\Authentication\Adapter\AdapterInterface; |
|
13
|
|
|
use Core\Repository\RepositoryInterface; |
|
14
|
|
|
use Auth\Entity\AnonymousUser; |
|
15
|
|
|
|
|
16
|
|
|
class AuthenticationService extends ZendAuthService |
|
17
|
|
|
{ |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @var AnonymousUser |
|
21
|
|
|
*/ |
|
22
|
|
|
protected $user; |
|
23
|
|
|
/** |
|
24
|
|
|
* @var RepositoryInterface; |
|
25
|
|
|
*/ |
|
26
|
|
|
protected $repository; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @param RepositoryInterface $repository |
|
30
|
|
|
*/ |
|
31
|
|
|
public function __construct(RepositoryInterface $repository) |
|
32
|
|
|
{ |
|
33
|
|
|
$this->setRepository($repository); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @return RepositoryInterface |
|
38
|
|
|
*/ |
|
39
|
|
|
public function getRepository() |
|
40
|
|
|
{ |
|
41
|
|
|
return $this->repository; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @param RepositoryInterface $repository |
|
46
|
|
|
* @return $this |
|
47
|
|
|
*/ |
|
48
|
|
|
public function setRepository($repository) |
|
49
|
|
|
{ |
|
50
|
|
|
$this->repository = $repository; |
|
51
|
|
|
return $this; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @return AnonymousUser |
|
56
|
|
|
* @throws \OutOfBoundsException |
|
57
|
|
|
*/ |
|
58
|
|
|
public function getUser() |
|
59
|
|
|
{ |
|
60
|
|
|
if (!$this->user) { |
|
61
|
|
|
if ($this->hasIdentity() && ($id = $this->getIdentity())) { |
|
62
|
|
|
$user = $this->getRepository()->find($id); |
|
63
|
|
|
if (!$user) { |
|
64
|
|
|
throw new \OutOfBoundsException('Unknown user id: ' . $id); |
|
65
|
|
|
} |
|
66
|
|
|
$this->user = $user; |
|
67
|
|
|
} else { |
|
68
|
|
|
$this->user = new AnonymousUser(); |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
return $this->user; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* @param AdapterInterface $adapter |
|
|
|
|
|
|
77
|
|
|
* @return \Zend\Authentication\Result |
|
78
|
|
|
*/ |
|
79
|
|
|
public function authenticate(AdapterInterface $adapter = null) |
|
80
|
|
|
{ |
|
81
|
|
|
$this->user = null; // clear user (especially guest user) |
|
82
|
|
|
return parent::authenticate($adapter); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
public function clearIdentity() |
|
86
|
|
|
{ |
|
87
|
|
|
parent::clearIdentity(); |
|
88
|
|
|
$this->user = null; |
|
89
|
|
|
|
|
90
|
|
|
return $this; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
|
|
94
|
|
|
} |
|
95
|
|
|
|
This check looks for
@paramannotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.