<?php
/**
* BitOperator Class operation examples
*
* @author Mahmut Namli <mahmudnamli@gmail.com>
*/
/* Firstly, need to integrate the class for examples.. */
require_once 'string.bitwise.php';
/************ I have NormalAdmin (so have User privileges), Reading and Writing permissions, so: ************/
$myPerms = BitOperator::mOrInt( array(
BitOperator::NormalAdmin,
BitOperator::Reading,
BitOperator::Writing
) ); //gives 27
echo "
Your rights: $myPerms<br />
<ul>";
foreach (BitOperator::showConstant() as $key => $value) {
if ( BitOperator::mAndInt( array( $myPerms, $value ) ) == $value ) {
echo "
<li>$key</li>";
}
}
echo '
</ul>';
/************ I give permissions to user which have NormalAdmin and Reading rights for WEB SERVICE, so: ************/
$neededPermsWS = BitOperator::mOrInt( array(
BitOperator::NormalAdmin,
BitOperator::Reading
) );
echo "
Needed permissions for entering the WEB SERVICE section: $neededPermsWS<br />
<ul>";
foreach (BitOperator::showConstant() as $key => $value) {
if ( BitOperator::mAndInt( array( $neededPermsWS, $value ) ) == $value ) {
echo "
<li>$key</li>";
}
}
echo '
</ul>';
if (BitOperator::mAndInt( array( $myPerms, $neededPermsWS) ) == $neededPermsWS) {
echo '<h1><em style="color:green;">You have rights for enter WEB SERVICE section</em></h1>';
} else {
echo '<h1><em style="color:red;">You don\'t have rights for enter WEB SERVICE section</em></h1>';
}
/************ I give permissions to user which have SysAdmin and Reading rights for ADMIN PANEL, so: ************/
$neededPermsAP = BitOperator::mOrInt( array(
BitOperator::SysAdmin,
BitOperator::Reading
) );
echo "
Needed permissions for entering the ADMIN PANEL section: $neededPermsAP<br />
<ul>";
foreach (BitOperator::showConstant() as $key => $value) {
if ( BitOperator::mAndInt( array( $neededPermsAP, $value ) ) == $value ) {
echo "
<li>$key</li>";
}
}
echo '
</ul>';
if (BitOperator::mAndInt( array( $myPerms, $neededPermsAP) ) == $neededPermsAP) {
echo '<h1><em style="color:green;">You have rights for enter ADMIN PANEL section</em></h1>';
} else {
echo '<h1><em style="color:red;">You don\'t have rights for enter ADMIN PANEL section</em></h1>';
}
|