Login   Register  
PHP Classes
elePHPant
Icontem

File: example.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Eduardo Alonso Albella  >  Easy Access Control Layer ACL  >  example.php  >  Download  
File: example.php
Role: Example script
Content type: text/plain
Description: example of how to use the class
Class: Easy Access Control Layer ACL
Control the access to resources based in roles
Author: By
Last change:
Date: 2 years ago
Size: 2,360 bytes
 

Contents

Class file image Download
<?php
include 'easy_acl.php';

$acl = new Easy_Acl();

//We add some roles
$acl->addRole('grand_father');
$acl->addRole('dad','grand_father');
$acl->addRole('mom');
$acl->addRole('son',array('dad','mom'));

//We add some resources
$acl->addResource('grandpas_house');
$acl->addResource('dads_house');
$acl->addResource('moms_house');
$acl->addResource('my_house');

//We set some rules
$acl->allow('grand_father','grandpas_house');
$acl->allow('dad','dads_house');
$acl->allow('mom','moms_house');

echo 
'Son allowed into grandpas?<br />';
var_dump($acl->isAllowed('son','grandpas_house')); //Should be true
echo 'Dad allowed into grandpas?<br />';
var_dump($acl->isAllowed('dad','grandpas_house')); //Should be true
echo 'grand_father allowed into grandpas?<br />';
var_dump($acl->isAllowed('grand_father','grandpas_house')); //Should be true
echo 'Mom allowed into grandpas? He doesn\'t like her<br />';
var_dump($acl->isAllowed('mom','grandpas_house')); //False

echo 'Dad allowed into dads_house?<br />';
var_dump($acl->isAllowed('dad','dads_house')); //Should be true
echo 'son allowed into dads_house?<br />';
var_dump($acl->isAllowed('son','dads_house')); //Should be true
echo 'mom allowed into dads_house?<br />';
var_dump($acl->isAllowed('mom','moms_house')); //Should be true
echo 'son allowed into moms_house?<br />';
var_dump($acl->isAllowed('son','moms_house')); //Should be true

/* Another test, we are not allowing dad to enter grandpas house, it 
means that his son will not be allowed to enter either. */
echo '<hr />';
$acl->deny('dad','grandpas_house');

echo 
'Son allowed into grandpas?<br />';
var_dump($acl->isAllowed('son','grandpas_house')); //Should be false
echo 'Dad allowed into grandpas?<br />';
var_dump($acl->isAllowed('dad','grandpas_house')); //Should be false
echo 'grand_father allowed into grandpas?<br />';
var_dump($acl->isAllowed('grand_father','grandpas_house')); //Should be true
echo 'Mom allowed into grandpas? He doesn\'t like her<br />';
var_dump($acl->isAllowed('mom','grandpas_house')); //False

//But now if we allow his mother, he should be able to enter his grandpas house
echo '<hr />';
$acl->allow('mom','grandpas_house');

echo 
'Son allowed into grandpas?<br />';
var_dump($acl->isAllowed('son','grandpas_house')); //Should be false

echo $acl;