Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/crypto-scythe/bitflagtrait
- Owner: crypto-scythe
- License: mit
- Created: 2016-05-12T21:31:47.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2016-05-12T21:35:33.000Z (over 8 years ago)
- Last Synced: 2024-12-12T14:12:01.055Z (16 days ago)
- Language: PHP
- Size: 1.95 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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;