Login   Register  
PHP Classes
elePHPant
Icontem

File: bitwise/index.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Mahmut Namli  >  Bitwise on String Operations  >  bitwise/index.php  >  Download  
File: bitwise/index.php
Role: Example script
Content type: text/plain
Description: string.bitwise file examples
Class: Bitwise on String Operations
Define user permissions with bitwise operations
Author: By
Last change: 1) Ruler limited to 120 words
2) Removed unnecessary single and double quotes
3) Made documentations and comment lines clear
Date: 2014-01-04 06:33
Size: 2,296 bytes
 

Contents

Class file image Download
<?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>';
}