Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/crypto-scythe/bitflagtrait

Trait for simple setting / getting bitflags
https://github.com/crypto-scythe/bitflagtrait

Last synced: 11 days ago
JSON representation

Trait for simple setting / getting bitflags

Awesome Lists containing this project

README

        

# BitflagTrait

Simple trait for setting and getting bitflags in your classes

## Installing

Just with composer:

composer require crypto_scythe/bitflagtrait

## Usage (similiar to examples/useracl.php)

isBitflagSet( $this->acl, self::FLAG_CREATE );

}

public function isReadAllowed() {

return $this->isBitflagSet( $this->acl, self::FLAG_READ );

}

public function isUpdateAllowed() {

return $this->isBitflagSet( $this->acl, self::FLAG_UPDATE );

}

public function isDeleteAllowed() {

return $this->isBitflagSet( $this->acl, self::FLAG_DELETE );

}

public function setCreateAllowed( $value ){

$this->setFlag( $this->acl, self::FLAG_CREATE, $value );

}

public function setReadAllowed($value) {

$this->setFlag( $this->acl, self::FLAG_READ, $value );

}

public function setUpdateAllowed($value) {

$this->setFlag( $this->acl, self::FLAG_UPDATE, $value );

}

public function setDeleteAllowed($value){

$this->setFlag( $this->acl, self::FLAG_DELETE, $value );

}

public function __toString() {

$rights = array_filter( [
$this->isCreateAllowed() ? 'CREATE' : false,
$this->isReadAllowed() ? ' READ' : false,
$this->isUpdateAllowed() ? 'UPDATE' : false,
$this->isDeleteAllowed() ? 'DELETE' : false
] );

return print_r( $rights, true );

}

}

$userACL = new UserACL();
$userACL->setCreateAllowed( true );
$userACL->setReadAllowed( false );
$userACL->setUpdateAllowed( true );
$userACL->setDeleteAllowed( false );

echo $userACL;