Skip to content

3.3.0

Compare
Choose a tag to compare
@dereuromark dereuromark released this 04 Jan 22:56
· 36 commits to master since this release

Improvements

Added Enum support for Bitmasked behavior

use App\Model\Enum\CommentStatus;

$this->Comments->addBehavior('Tools.Bitmasked', [
    'bits' => CommentStatus::class, 
    'mappedField' => 'statuses'],
);

By using an Enum for bits it will automatically switch the incoming and outcoming bit values to Enum instances.

You can also manually set the bits using an array, but then you would have to also set enum to the Enum class:

$this->Comments->addBehavior('Tools.Bitmasked', [
    'bits' => CommentStatus::tryFrom(CommentStatus::None->value)::options(), 
    'enum' =>  CommentStatus::class, 
    'mappedField' => 'statuses'],
);

Live demo: https://sandbox.dereuromark.de/sandbox/tools-examples/bitmask-enums