BinaryEnumFlagsTraits\InteractsWithEnumFlagsFlag enum and Mask value objectMask object from getMask().getMaskValue(): int method for enum-backed flags to persist/interoperate with integer masks.float values as masks/flags.v3.0.0 integer-only API.UPGRADE-v3.md with migration instructions.Traits\InteractsWithNumericFlags.Traits\BinaryFlags is now deprecated and kept for backward compatibility.float to BinaryFlags mask/flag methods is deprecated in v2.1.0.v3.0.0.Bits::BIT_64 will be removed in v3.0.0.Bits::BIT_64 is being removed because PHP numbers for bitwise flags are signed. The 64th bit is the sign bit, so it cannot be used reliably as a normal flag.
Using integer-compatible bits avoids these issues.
Cast external/legacy mask and flag values to int before calling BinaryFlags methods.
$flags->setMask((int) $mask);
$flags->addFlag((int) $flag);
// Before: numeric PermissionFlags
class PermissionFlags extends BinaryFlags
{
public const CAN_VIEW = Bits::BIT_1;
public const CAN_BOOK = Bits::BIT_2;
}
$flags = new PermissionFlags($storedMask);
$flags->addFlag(PermissionFlags::CAN_VIEW | PermissionFlags::CAN_BOOK);
$storedMask = $flags->getMask();
// After: enum-backed PermissionFlags
enum Permission: int
{
case CanView = Bits::BIT_1;
case CanBook = Bits::BIT_2;
}
class PermissionFlags extends BinaryEnumFlags
{
protected static function getFlagEnumClass(): string
{
return Permission::class;
}
}
$flags = new PermissionFlags(Mask::fromInt($storedMask, Permission::class));
$flags->addFlag(Permission::CanView);
$flags->addFlag(Permission::CanBook);
$storedMask = $flags->getMaskValue();
Full Changelog: https://github.com/reinder83/binary-flags/compare/v2.0...v2.0.1
Drop support for older PHP versions, better support for PHP 8+ and typehinting
$currentPos variable from trait to abstract classThis release makes it possible iterate over the set flags, do a count() to return the number of set flags and add support to json_encode the BinaryFlags object
Add static method getAllFlags Add static method getAllFlagsMask
Updated unittests to have 100% code completion.
Updated readme and Bits notation
Added a useful Bits class, which holds BIT constants, so you can assign your flags more easily
This release adds a modify callback, to allow you to update your models automatically.
How can I help you explore Laravel packages today?