Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Binary Flags Laravel Package

reinder83/binary-flags

View on GitHub
Deep Wiki
Context7
v3.0.0

Release Notes - v3.0.0

Changed

  • Numeric BinaryFlags APIs now accept int values only.
  • Passing float values to numeric mask/flag methods now raises TypeError for strict_types=1 callers.
  • Non-strict callers should still cast or validate external values before calling the API because PHP scalar coercion can convert float to int at the call boundary.
  • The numeric iterator and JSON serialization contracts are now documented as int-based.

Removed

  • Bits::BIT_64.
  • The v2.x float-normalization/deprecation path in Traits\InteractsWithNumericFlags.

BIT_64 Notice

Bits::BIT_64 was 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.

v2.1.0

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();
v2.0.1

What's Changed

New Contributors

Full Changelog: https://github.com/reinder83/binary-flags/compare/v2.0...v2.0.1

v2.0

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

v1.2.2
  • Moved $currentPos variable from trait to abstract class
  • Update readme
v1.2.1
  • 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
v1.2.0

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

v1.1.0

Add static method getAllFlags Add static method getAllFlagsMask

v1.0.1
  • Added checkAnyFlag method
  • Minor readme updates
v1.0

Updated unittests to have 100% code completion.

v0.5

Updated readme and Bits notation

v0.4
  • Added Trait support
  • Travis and CodeCoverage fixes
v0.3

Added a useful Bits class, which holds BIT constants, so you can assign your flags more easily

v0.2

This release adds a modify callback, to allow you to update your models automatically.

v0.1
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
calmfox/watch-sylius
damienfern/grpc-symfony-bundle
atoolo/index-bundle
atoolo/genai-bundle
coprotoai/laravel-ticket
davidjln/llm-carbon-bundle
cryonighter/valid-request-bundle
coolms/taxonomy-bundle
coolms/field-bundle
articulate-orm/symfony
aaix/laravel-tall-architect
ephoto/akeneo-connector
emmanuelballery/eb-plantumlbundle
emielburgman/symfony-visitor-beacon
emielburgman/symfony-visit-storage
emielburgman/symfony-security-headers
emielburgman/symfony-log-viewer
emarref/xdebug-bundle
emarref/pubnub-bundle
elriseio/finance-money-bundle