PHP code example of gabbro-php / identity

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

    

gabbro-php / identity example snippets


use gabbro\identity\GenericIdentity;
use gabbro\identity\Identity;

// Create a privileged identity
$admin = new GenericIdentity(Identity::ID_PRIVILEGED);

var_dump($admin->hasRole("anything")); // true

// Create a normal user identity
$user = new GenericIdentity(42, "jdoe", "John Doe");
$user->addRoles("editor", "contributor");

var_dump($user->getId());        // 42
var_dump($user->getName());      // "jdoe"
var_dump($user->getLabel());     // "John Doe"
var_dump($user->hasRole("editor")); // true
var_dump($user->hasRole("admin"));  // false