1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Application\Acl\Assertion; |
6
|
|
|
|
7
|
|
|
use Application\Model\AbstractModel; |
8
|
|
|
use Application\Model\User; |
9
|
|
|
use Ecodev\Felix\Acl\Assertion\NamedAssertion; |
10
|
|
|
use Laminas\Permissions\Acl\Acl; |
11
|
|
|
use Laminas\Permissions\Acl\Resource\ResourceInterface; |
12
|
|
|
use Laminas\Permissions\Acl\Role\RoleInterface; |
13
|
|
|
|
14
|
|
|
class IsFamily implements NamedAssertion |
15
|
|
|
{ |
16
|
|
|
public function getName(): string |
17
|
|
|
{ |
18
|
|
|
return "l'objet appartient à mon ménage"; |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Assert that the object belongs to someone in the current user family. |
23
|
|
|
* |
24
|
|
|
* @param \Application\Acl\Acl $acl |
25
|
|
|
* @param RoleInterface $role |
26
|
|
|
* @param ResourceInterface $resource |
27
|
|
|
* @param string $privilege |
28
|
|
|
* |
29
|
|
|
* @return bool |
30
|
|
|
*/ |
31
|
2 |
|
public function assert(Acl $acl, ?RoleInterface $role = null, ?ResourceInterface $resource = null, $privilege = null) |
32
|
|
|
{ |
33
|
2 |
|
if ($resource === null) { |
34
|
|
|
return false; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** @var AbstractModel $object */ |
38
|
2 |
|
$object = $resource->getInstance(); |
|
|
|
|
39
|
|
|
|
40
|
2 |
|
$currentFamilyOwner = User::getCurrent(); |
41
|
2 |
|
if ($currentFamilyOwner && $currentFamilyOwner->getOwner()) { |
42
|
|
|
$currentFamilyOwner = $currentFamilyOwner->getOwner(); |
43
|
|
|
} |
44
|
|
|
|
45
|
2 |
|
$objectFamilyOwner = $object->getOwner(); |
46
|
2 |
|
if ($objectFamilyOwner && $objectFamilyOwner->getOwner()) { |
47
|
|
|
$objectFamilyOwner = $objectFamilyOwner->getOwner(); |
48
|
|
|
} |
49
|
|
|
|
50
|
2 |
|
if ($currentFamilyOwner && $currentFamilyOwner === $objectFamilyOwner) { |
51
|
2 |
|
return true; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
return $acl->reject('the object does not belong to the family'); |
|
|
|
|
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.