|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Copyright 2018 SURFnet B.V. |
|
4
|
|
|
* |
|
5
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
6
|
|
|
* you may not use this file except in compliance with the License. |
|
7
|
|
|
* You may obtain a copy of the License at |
|
8
|
|
|
* |
|
9
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
|
10
|
|
|
* |
|
11
|
|
|
* Unless required by applicable law or agreed to in writing, software |
|
12
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
|
13
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
14
|
|
|
* See the License for the specific language governing permissions and |
|
15
|
|
|
* limitations under the License. |
|
16
|
|
|
*/ |
|
17
|
|
|
|
|
18
|
|
|
namespace Surfnet\StepupMiddleware\ApiBundle\Authorization\Repository; |
|
19
|
|
|
|
|
20
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
|
21
|
|
|
use Surfnet\StepupMiddleware\ApiBundle\Authorization\Filter\InstitutionAuthorizationRepositoryFilter; |
|
22
|
|
|
|
|
23
|
|
|
class AuthorizationRepositoryFactory |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* @var InstitutionAuthorizationRepositoryFilter |
|
27
|
|
|
*/ |
|
28
|
|
|
private $filter; |
|
29
|
|
|
/** |
|
30
|
|
|
* @var EntityManagerInterface |
|
31
|
|
|
*/ |
|
32
|
|
|
private $entityManager; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* AuthorizationRepositoryFactory constructor. |
|
36
|
|
|
* @param EntityManagerInterface $entityManager |
|
37
|
|
|
* @param InstitutionAuthorizationRepositoryFilter $filter |
|
38
|
|
|
*/ |
|
39
|
|
|
public function __construct(EntityManagerInterface $entityManager, InstitutionAuthorizationRepositoryFilter $filter) |
|
40
|
|
|
{ |
|
41
|
|
|
$this->entityManager = $entityManager; |
|
42
|
|
|
$this->filter = $filter; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @param string $entityName |
|
47
|
|
|
* @return \Doctrine\Common\Persistence\ObjectRepository |
|
48
|
|
|
*/ |
|
49
|
|
|
public function getRepository($entityName) |
|
50
|
|
|
{ |
|
51
|
|
|
/* @var $metadata \Doctrine\ORM\Mapping\ClassMetadata */ |
|
52
|
|
|
$metadata = $this->entityManager->getClassMetadata($entityName); |
|
53
|
|
|
$repositoryClassName = $metadata->customRepositoryClassName |
|
54
|
|
|
?: $this->entityManager->getConfiguration()->getDefaultRepositoryClassName(); |
|
55
|
|
|
|
|
56
|
|
|
return new $repositoryClassName($this->entityManager, $metadata, $this->filter); |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
|