1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace CultuurNet\UDB3\Offer\Security; |
4
|
|
|
|
5
|
|
|
use CultuurNet\UDB3\Role\ReadModel\Constraints\UserConstraintsReadRepositoryInterface; |
6
|
|
|
use CultuurNet\UDB3\Role\ValueObjects\Permission; |
7
|
|
|
use CultuurNet\UDB3\Search\SearchServiceInterface; |
8
|
|
|
use ValueObjects\StringLiteral\StringLiteral; |
9
|
|
|
|
10
|
|
|
class Sapi3UserPermissionMatcher implements UserPermissionMatcherInterface |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @var UserConstraintsReadRepositoryInterface |
14
|
|
|
*/ |
15
|
|
|
private $userConstraintsReadRepository; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @var SearchQueryFactoryInterface |
19
|
|
|
*/ |
20
|
|
|
private $searchQueryFactory; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var SearchServiceInterface |
24
|
|
|
*/ |
25
|
|
|
private $searchService; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* ConstraintsOfferFilter constructor. |
29
|
|
|
* @param UserConstraintsReadRepositoryInterface $userConstraintsReadRepository |
30
|
|
|
* @param SearchQueryFactoryInterface $searchQueryFactory |
31
|
|
|
* @param SearchServiceInterface $searchService |
32
|
|
|
*/ |
33
|
|
|
public function __construct( |
34
|
|
|
UserConstraintsReadRepositoryInterface $userConstraintsReadRepository, |
35
|
|
|
SearchQueryFactoryInterface $searchQueryFactory, |
36
|
|
|
SearchServiceInterface $searchService |
37
|
|
|
) { |
38
|
|
|
$this->userConstraintsReadRepository = $userConstraintsReadRepository; |
39
|
|
|
$this->searchQueryFactory = $searchQueryFactory; |
40
|
|
|
$this->searchService = $searchService; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @inheritdoc |
45
|
|
|
*/ |
46
|
|
|
public function itMatchesOffer( |
47
|
|
|
StringLiteral $userId, |
48
|
|
|
Permission $permission, |
49
|
|
|
StringLiteral $offerId |
50
|
|
|
) { |
51
|
|
|
$constraints = $this->userConstraintsReadRepository->getByUserAndPermission( |
52
|
|
|
$userId, |
53
|
|
|
$permission |
54
|
|
|
); |
55
|
|
|
if (count($constraints) < 1) { |
56
|
|
|
return false; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
$query = $this->searchQueryFactory->createFromConstraints( |
60
|
|
|
$constraints, |
61
|
|
|
$offerId |
62
|
|
|
); |
63
|
|
|
|
64
|
|
|
$results = $this->searchService->search($query); |
|
|
|
|
65
|
|
|
|
66
|
|
|
return ($results->getTotalItems()->toNative() === 1); |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: