PHP code example of illusiard / yii2-entity-acl

1. Go to this page and download the library: Download illusiard/yii2-entity-acl library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

illusiard / yii2-entity-acl example snippets


interface SubjectResolverInterface
{
    public function resolveGroupId(int $userId, array $context = []): ?int;
    public function resolveOwnerId(AccessRequest $req): ?int;
}

interface ConditionHandlerInterface
{
    public function supports(string $type): bool;
    public function evaluate(array $payload, AccessRequest $req, ConditionEngine $engine): bool;
}

use illusiard\entity_acl\models\dto\AccessRequest;
use illusiard\entity_acl\AclService;

$req = new AccessRequest(
    userId: 1,
    entity: 'post',
    operation: 'read',
    recordId: '10',
    context: [
        'groupId' => 5,
        'ownerId' => 1,
    ]
);

$allowed = AclService::instance()
    ->getPolicy()
    ->can($req);