karkowg/laravel-bit-flag

This package is abandoned and no longer maintained. No replacement package was suggested.

Laravel support for karkowg/bit-flag

v1.0.0 2022-04-26 21:24 UTC

This package is auto-updated.

Last update: 2024-05-03 19:40:53 UTC


README

BitFlag code snippet

Laravel BitFlag

Latest Version on Packagist GitHub Tests Action Status License Total Downloads

This package provides Laravel support for karkowg/bit-flag.

Requires PHP 7.4 and Laravel 8.x

⚡️ Installation

composer require karkowg/laravel-bit-flag

Usage

<?php

namespace App\BitFlags;

use Karkow\BitFlag\Laravel\BitFlag;

class CartStatus extends BitFlag
{
    private const CHECKED_OUT = 1 << 0;
    private const PAYED = 1 << 1;
    private const SHIPPED = 1 << 2;

    // ... other setters/getters

    public function markAsPayed(): self
    {
        return $this->set(self::PAYED);
    }

    public function hasBeenPayed(): bool
    {
        return $this->has(self::PAYED);
    }
}


// App\Services\CartService

$cartStatus = CartStatus::make();

if ($paymentSuccessful) {
    $cartStatus->markAsPayed();
}

$cartStatus->hasBeenPayed(); //? true

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Credits

License

The MIT License (MIT). Please see License File for more information.