Skip to content

Latest commit

 

History

History
21 lines (15 loc) · 514 Bytes

File metadata and controls

21 lines (15 loc) · 514 Bytes

Basic Authorization

<?php

declare(strict_types=1);

use CommonPHP\Security\Authorizer;
use CommonPHP\Security\Role;
use CommonPHP\Security\SecurityContext;

$editor = new Role('editor', ['posts.view', 'posts.update']);
$context = SecurityContext::forIdentity($user, roles: [$editor]);
$authorizer = new Authorizer();

if ($authorizer->can($context, 'posts.update')) {
    // Update the post.
}

Use direct context grants for simple permission checks that do not need resource-specific policy logic.