PHP code example of phalcon / incubator-acl

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

    

phalcon / incubator-acl example snippets


use Phalcon\Incubator\Acl\Adapter\Database as AclDb;
use Phalcon\Db\Adapter\Pdo\Sqlite;

$connection = new Sqlite(
    [
        'dbname' => 'sample.db',
    ]
);

$acl = AclDb(
    [
        'db'                => $connection,
        'roles'             => 'roles',
        'rolesInherits'     => 'roles_inherits',
        'resources'         => 'resources',
        'resourcesAccesses' => 'resources_accesses',
        'accessList'        => 'access_list',
    ]
);


// By default the action is deny access
$acl->setDefaultAction(
    \Phalcon\Acl\Enum::DENY
);

// You can add roles/resources/accesses to list or insert them directly in the tables

// Add roles
$acl->addRole(
    new \Phalcon\Acl\Role('Admins')
);

// Create the resource with its accesses
$acl->addResource(
    'Products',
    [
        'insert',
        'update',
        'delete',
    ]
);

// Allow Admins to insert products
$acl->allow('Admin', 'Products', 'insert');

// Do Admins are allowed to insert Products?
var_dump(
    $acl->isAllowed('Admins', 'Products', 'update')
);