PHP code example of phpdot / iam

1. Go to this page and download the library: Download phpdot/iam 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/ */

    

phpdot / iam example snippets


use PHPdot\Iam\Authorization\Attribute\Permission;

final class Permissions
{
    #[Permission(name: 'Edit employees', description: 'Edit employee records')]
    public const string EmployeeEdit = 'hr.employee.edit';

    #[Permission(name: 'Restart the server', root: true)]
    public const string ServerRestart = 'system.server.restart';
}

$authorizer->has('hr.employee.edit');
$authorizer->hasAll(['hr.employee.edit', 'hr.employee.view']);
$authorizer->can(SalaryVisiblePolicy::class, $identity, $employeeResource);

$engine->attempt(new PasswordCredentials($email, $password)); // → pending, OTP expected
$engine->attempt(new OtpCredentials($code));                  // → authenticated