diff --git a/README.md b/README.md index 34afc45..9ed3927 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,55 @@ And just run installation command $ composer.phar install ``` +Usage +--- + +See usage in [sample](./example/example.php) file. + +``` +Aliance/InfiniteBitmask $ php -f example/example.php +Check user for all flags: +Premium: no +Wizard already shown: no +Paid ever: no +Referral: no +Banned: no +Already notified: no +––––––––––––––––––––––––––––––––––– +Check user for all flags: +Premium: no +Wizard already shown: no +Paid ever: yes +Referral: no +Banned: yes +Already notified: yes +––––––––––––––––––––––––––––––––––– +array(3) { + [0]=> + int(8) + [1]=> + int(1) + [2]=> + int(1) +} +Check user for all flags: +Premium: no +Wizard already shown: no +Paid ever: yes +Referral: no +Banned: yes +Already notified: no +––––––––––––––––––––––––––––––––––– +array(3) { + [0]=> + int(8) + [1]=> + int(1) + [2]=> + int(0) +} +``` + Tests --- diff --git a/example/example.php b/example/example.php new file mode 100644 index 0000000..b4e55ed --- /dev/null +++ b/example/example.php @@ -0,0 +1,67 @@ + [], // default empty bitmasks +]; + +require_once realpath(dirname('.')) . '/vendor/autoload.php'; + +// create a Bitmask object, passing user bitmask from storage +$Bitmask = new \Aliance\InfiniteBitmask\InfiniteBitmask($user['bitmasks']); + +checkFlags($Bitmask); + +// set user some flags +$Bitmask->setBit(HAS_PAID_EVER); +$Bitmask->setBit(IS_BANNED); +$Bitmask->setBit(HAS_ALREADY_NOTIFIED); + +checkFlags($Bitmask); + +var_dump($Bitmask->getMaskSlices()); + +// unset daily flag +$Bitmask->unsetBit(HAS_ALREADY_NOTIFIED); + +checkFlags($Bitmask); + +var_dump($Bitmask->getMaskSlices()); + +function checkFlags(\Aliance\InfiniteBitmask\InfiniteBitmask $Bitmask) +{ + echo 'Check user for all flags:', PHP_EOL; + echo 'Premium: ', $Bitmask->issetBit(IS_PREMIUM) ? 'yes' : 'no', PHP_EOL; + echo 'Wizard already shown: ', $Bitmask->issetBit(HAS_WIZARD_ALREADY_SHOWN) ? 'yes' : 'no', PHP_EOL; + echo 'Paid ever: ', $Bitmask->issetBit(HAS_PAID_EVER) ? 'yes' : 'no', PHP_EOL; + echo 'Referral: ', $Bitmask->issetBit(IS_REFERRAL) ? 'yes' : 'no', PHP_EOL; + echo 'Banned: ', $Bitmask->issetBit(IS_BANNED) ? 'yes' : 'no', PHP_EOL; + echo 'Already notified: ', $Bitmask->issetBit(HAS_ALREADY_NOTIFIED) ? 'yes' : 'no', PHP_EOL; + echo str_repeat('–', 35), PHP_EOL; +}