Ecodev /
felix
| 1 | <?php |
||
| 2 | |||
| 3 | declare(strict_types=1); |
||
| 4 | |||
| 5 | namespace Ecodev\Felix\Acl\Assertion; |
||
| 6 | |||
| 7 | use Ecodev\Felix\Model\CurrentUser; |
||
| 8 | use Ecodev\Felix\Model\HasOwner; |
||
| 9 | use Laminas\Permissions\Acl\Acl; |
||
| 10 | use Laminas\Permissions\Acl\Resource\ResourceInterface; |
||
| 11 | use Laminas\Permissions\Acl\Role\RoleInterface; |
||
| 12 | |||
| 13 | final class IsOwner implements NamedAssertion |
||
| 14 | { |
||
| 15 | /** |
||
| 16 | * Assert that the object belongs to the current user. |
||
| 17 | * |
||
| 18 | * @param \Ecodev\Felix\Acl\Acl $acl |
||
| 19 | * @param RoleInterface $role |
||
| 20 | * @param ResourceInterface $resource |
||
| 21 | * @param string $privilege |
||
| 22 | * |
||
| 23 | * @return bool |
||
| 24 | */ |
||
| 25 | public function assert(Acl $acl, ?RoleInterface $role = null, ?ResourceInterface $resource = null, $privilege = null) |
||
| 26 | { |
||
| 27 | /** @var HasOwner $object */ |
||
| 28 | $object = $resource->getInstance(); |
||
| 29 | |||
| 30 | if (CurrentUser::get() && CurrentUser::get() === $object->getOwner()) { |
||
| 31 | return true; |
||
| 32 | } |
||
| 33 | |||
| 34 | return $acl->reject('the object does not belong to the user'); |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 35 | } |
||
| 36 | |||
| 37 | public function getName(): string |
||
| 38 | { |
||
| 39 | return _tr("l'objet m'appartient"); |
||
| 40 | } |
||
| 41 | } |
||
| 42 |