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
{
    /** @return int|string|list<int|string>|null */
    public function resolveGroupId(int|string $userId, array $context = []): int|string|array|null;
    public function resolveOwnerId(AccessRequest $req): int|string|null;
}

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: '01995d22-6bc8-72e4-92b7-8bca0e75f01f',
    entity: 'post',
    operation: 'read',
    recordId: '10',
    context: [
        'groupIds' => [
            '01995d3b-4d4a-710b-9f84-f08f05bd6f07',
            '01995d62-f585-710a-a688-c1da35cd47d9',
        ],
        'ownerId' => '01995d22-6bc8-72e4-92b7-8bca0e75f01f',
    ]
);

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