1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Copyright 2014 SURFnet bv |
5
|
|
|
* |
6
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
7
|
|
|
* you may not use this file except in compliance with the License. |
8
|
|
|
* You may obtain a copy of the License at |
9
|
|
|
* |
10
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
11
|
|
|
* |
12
|
|
|
* Unless required by applicable law or agreed to in writing, software |
13
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
14
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
15
|
|
|
* See the License for the specific language governing permissions and |
16
|
|
|
* limitations under the License. |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
namespace Surfnet\StepupGateway\GatewayBundle\Entity; |
20
|
|
|
|
21
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
22
|
|
|
use Doctrine\ORM\EntityRepository; |
23
|
|
|
use Surfnet\StepupBundle\Service\SecondFactorTypeService; |
24
|
|
|
use Surfnet\StepupBundle\Value\Loa; |
25
|
|
|
|
26
|
|
|
class DoctrineSecondFactorRepository extends EntityRepository implements SecondFactorRepository |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* @var SecondFactor[] |
30
|
|
|
*/ |
31
|
|
|
private $secondFactorsById = []; |
32
|
|
|
|
33
|
|
|
public function getAllMatchingFor(Loa $highestLoa, $identityNameId, SecondFactorTypeService $service) |
34
|
|
|
{ |
35
|
|
|
/** @var \Surfnet\StepupGateway\GatewayBundle\Entity\SecondFactor[] $secondFactors */ |
36
|
|
|
$secondFactors = $this->findAllByIdentityNameId($identityNameId); |
|
|
|
|
37
|
|
|
|
38
|
|
|
$matches = new ArrayCollection(); |
39
|
|
|
foreach ($secondFactors as $secondFactor) { |
40
|
|
|
if ($secondFactor->canSatisfy($highestLoa, $service)) { |
41
|
|
|
$matches->add($secondFactor); |
42
|
|
|
} |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
return $matches; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function findOneBySecondFactorId($secondFactorId) |
49
|
|
|
{ |
50
|
|
|
if (!isset($this->secondFactorsById[$secondFactorId])) { |
51
|
|
|
$this->secondFactorsById[$secondFactorId] = $this->findOneBy(['secondFactorId' => $secondFactorId]); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
return $this->secondFactorsById[$secondFactorId]; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @param $identityNameId |
59
|
|
|
* @return string |
60
|
|
|
*/ |
61
|
|
|
public function getInstitutionByNameId($identityNameId) |
62
|
|
|
{ |
63
|
|
|
/** @var \Surfnet\StepupGateway\GatewayBundle\Entity\SecondFactor $secondFactor **/ |
64
|
|
|
$secondFactor = $this->createQueryBuilder('sf') |
65
|
|
|
->where('sf.nameId = :nameId') |
66
|
|
|
->setParameter('nameId', $identityNameId) |
67
|
|
|
->setMaxResults(1) |
68
|
|
|
->getQuery() |
69
|
|
|
->getOneOrNullResult(); |
70
|
|
|
|
71
|
|
|
if ($secondFactor) { |
72
|
|
|
return $secondFactor->institution; |
73
|
|
|
} |
74
|
|
|
return ''; |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
If you implement
__call
and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.This is often the case, when
__call
is implemented by a parent class and only the child class knows which methods exist: