CHMOD wrapping class [PHP]
Chmod wrapping class helps to "decode" chmod values. A piece of code from my old project SpineCord.
<?php
/**************************************************
*
* SpineCord V2.3 built 27
* Web Based File Manager
*
* @Version: 2.3 beta 2
* @Version-Built: 27
* @Date: 20th, October 2005
* @Licence: Freeware
* @Author: Piotr Polak (Pepis)
* @Homepage: http://www.pepis.prv.pl
* @E-mail: peterpepis@mail.ru
*
**************************************************/
class Chmod {
var $chmod;
var $chmod_owner;
var $chmod_group;
var $chmod_world;
/*
* readavle 4
* writable 2
* executable 1
*/
function Chmod($chmod) {
while(strlen($chmod)>3) {
$chmod = substr($chmod, 1, strlen($chmod));
}
$this->chmod_owner = $chmod{0};
$this->chmod_group = $chmod{1};
$this->chmod_world = $chmod{2};
$this->chmod = $chmod;
}
function getChmod() {
return $this->chmod;
}
function getFormatedChmod() {
return '0'.$this->chmod;
}
/*
*
* Owner
*
*/
function getOwnerReadable() {
if($this->chmod_owner==7||$this->chmod_owner==6||$this->chmod_owner==5||$this->chmod_owner==4) return true;
else return false;
}
function getOwnerWritable() {
if($this->chmod_owner==7||$this->chmod_owner==6||$this->chmod_owner==3||$this->chmod_owner==2) return true;
else return false;
}
function getOwnerExecutable() {
if($this->chmod_owner==7||$this->chmod_owner==5||$this->chmod_owner==3||$this->chmod_owner==1) return true;
else return false;
}
/*
*
* Group
*
*/
function getGroupReadable() {
if($this->chmod_group==7||$this->chmod_group==6||$this->chmod_group==5||$this->chmod_group==4) return true;
else return false;
}
function getGroupWritable() {
if($this->chmod_group==7||$this->chmod_group==6||$this->chmod_group==3||$this->chmod_group==2) return true;
else return false;
}
function getGroupExecutable() {
if($this->chmod_group==7||$this->chmod_group==5||$this->chmod_group==3||$this->chmod_group==1) return true;
else return false;
}
/*
*
* World
*
*/
function getWorldReadable() {
if($this->chmod_world==7||$this->chmod_world==6||$this->chmod_world==5||$this->chmod_world==4) return true;
else return false;
}
function getWorldWritable() {
if($this->chmod_world==7||$this->chmod_world==6||$this->chmod_world==3||$this->chmod_world==2) return true;
else return false;
}
function getWorldExecutable() {
if($this->chmod_world==7||$this->chmod_world==5||$this->chmod_world==3||$this->chmod_world==1) return true;
else return false;
}
}
?>
The above code could be optimized using byte shifting and byte masking.
