Skip to content

Releases: reinder83/binary-flags

Drop PHP 8.2, Deprecate floats, Add enums

27 Feb 10:15
ae6cb06

Choose a tag to compare

Release Notes - v2.1.0

Added

  • New enum-backed API:
    • BinaryEnumFlags
    • Traits\InteractsWithEnumFlags
    • Flag enum and Mask value object
  • Enum-backed flags now return a Mask object from getMask().
  • New getMaskValue(): int method for enum-backed flags to persist/interoperate with integer masks.
  • Deprecation warnings for passing float values as masks/flags.
  • README migration notice for the upcoming v3.0.0 integer-only API.
  • UPGRADE-v3.md with migration instructions.
  • New primary numeric trait: Traits\InteractsWithNumericFlags.
  • Traits\BinaryFlags is now deprecated and kept for backward compatibility.

Deprecated

  • Passing float to BinaryFlags mask/flag methods is deprecated in v2.1.0.
  • Float support will be removed in v3.0.0.
  • Bits::BIT_64 will be removed in v3.0.0.

BIT_64 Notice

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.

Migration Recommendation

Cast external/legacy mask and flag values to int before calling BinaryFlags methods.

$flags->setMask((int) $mask);
$flags->addFlag((int) $flag);

Enum Migration Example

// 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();

Drop PHP 8.0 and add better support for newer PHP versions

11 Dec 15:37
abd28bb

Choose a tag to compare

What's Changed

New Contributors

Full Changelog: v2.0...v2.0.1

Maintenance release PHP 8+

06 Jun 09:35
4699074

Choose a tag to compare

Drop support for older PHP versions, better support for PHP 8+ and typehinting

Minor fixes

01 Aug 12:28
a599929

Choose a tag to compare

  • Moved $currentPos variable from trait to abstract class
  • Update readme

Move interfaces from trait to abstract

01 Aug 07:52

Choose a tag to compare

  • Moved the countable, iteratable and jsonserializable methods to the abstract method, so it doesn't interfere with other classes that use the trait instead of extending from the abstract class.
  • Update Eloquent model example in readme

Add iterable, countable, and jsonSerializable

30 Jul 10:31

Choose a tag to compare

This 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 methods

22 Jul 13:17

Choose a tag to compare

Add static method getAllFlags
Add static method getAllFlagsMask

checkAnyFlag

12 Jun 19:49

Choose a tag to compare

  • Added checkAnyFlag method
  • Minor readme updates

Final release

12 Jun 14:23

Choose a tag to compare

Updated unittests to have 100% code completion.

Version 0.5

12 Jun 10:28

Choose a tag to compare

Updated readme and Bits notation