PHPackages                             maidmaid/flag - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. maidmaid/flag

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

maidmaid/flag
=============

Bitfield flags manager/debugger

v0.2.1(9y ago)2182MITPHPPHP &gt;=5.6.0

Since Apr 29Pushed 9y ago1 watchersCompare

[ Source](https://github.com/maidmaid/flag)[ Packagist](https://packagist.org/packages/maidmaid/flag)[ Docs](https://github.com/maidmaid/flag)[ RSS](/packages/maidmaid-flag/feed)WikiDiscussions master Synced yesterday

READMEChangelog (3)Dependencies (3)Versions (4)Used By (0)

Flag ⛳
======

[](#flag-golf)

Binarized flags are not intuitive to understand, using concepts like [bitwise operators](http://php.net/manual/en/language.operators.bitwise.php), [bitmask](https://en.wikipedia.org/wiki/Mask_(computing)) or [bit field](https://en.wikipedia.org/wiki/Bit_field). Moreover, theses flags are not easy to debug; find flags that hide behind integer bitfield is very annoying. This library propose a fluent API to handle bitfield and improve developer experience with tools for debugging them.

[![Build Status](https://camo.githubusercontent.com/13a5db00f0036f4f161b45211f8d7d07cd87e203bcad7df347e98479f587cb0a/68747470733a2f2f7472617669732d63692e6f72672f6d6169646d6169642f666c61672e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/maidmaid/flag)[![Latest Stable Version](https://camo.githubusercontent.com/4672bb21830529271274d05ca55022e98bc9a74d7fb128e1934563e8ef7f676d/68747470733a2f2f706f7365722e707567782e6f72672f6d6169646d6169642f666c61672f762f737461626c65)](https://packagist.org/packages/maidmaid/flag)[![License](https://camo.githubusercontent.com/771ed7c641adc0c57e778174f1c3767d57644147082cece4c3e01507b5c8aeab/68747470733a2f2f706f7365722e707567782e6f72672f6d6169646d6169642f666c61672f6c6963656e7365)](https://packagist.org/packages/maidmaid/flag)

Installation
------------

[](#installation)

Use [Composer](http://getcomposer.org/) to install Flag in your project:

```
composer require "maidmaid/flag"
```

Overview
--------

[](#overview)

For example, here is how to play with [`Yaml` flags](https://github.com/symfony/symfony/blob/8872833c5d6a46ea27a4483e650617361660d946/src/Symfony/Component/Yaml/Yaml.php#L23-L34):

```
use Maidmaid\Flag\Flag;
use Symfony\Component\Yaml\Yaml;

$flag = Flag::create(Yaml::class)
    ->add(Yaml::DUMP_OBJECT)      // logs '[debug] bitfield changed Yaml [bin: 1] [dec: 1] [flags: DUMP_OBJECT]'
    ->add(Yaml::PARSE_DATETIME)   // logs '[debug] bitfield changed Yaml [bin: 100001] [dec: 33] [flags: DUMP_OBJECT | PARSE_DATETIME]'
    ->remove(Yaml::DUMP_OBJECT)   // logs '[debug] bitfield changed Yaml [bin: 100000] [dec: 32] [flags: PARSE_DATETIME]'
;

$flag->has(Yaml::DUMP_OBJECT);    // returns false
$flag->has(Yaml::PARSE_DATETIME); // returns true
$flag->get();                     // returns 288
$flag->set(100);                  // logs '[debug] bitfield changed Yaml [bin: 1100100] [dec: 100] [flags: PARSE_OBJECT | PARSE_DATETIME | DUMP_OBJECT_AS_MAP]'

foreach ($flag as $k => $v) {
    echo "$k => $v ";            // writes '4 => PARSE_OBJECT 32 => PARSE_DATETIME 64 => DUMP_OBJECT_AS_MAP '
}
```

Prefixed Flags
--------------

[](#prefixed-flags)

As in [`Caster::EXCLUDE_*` case](https://github.com/symfony/symfony/blob/8872833c5d6a46ea27a4483e650617361660d946/src/Symfony/Component/VarDumper/Caster/Caster.php#L25-L34), it's possible to handle prefixed flags.

```
use Maidmaid\Flag\Flag;
use Symfony\Component\VarDumper\Caster\Caster;

$flag = Flag::create(Caster::class, 'EXCLUDE_')
    ->add(Caster::EXCLUDE_EMPTY)         // logs '[debug] bitfield changed Caster::EXCLUDE_* [bin: 10000000] [dec: 128] [EXCLUDE_*: EMPTY]'
    ->add(Caster::EXCLUDE_PRIVATE)       // logs '[debug] bitfield changed Caster::EXCLUDE_* [bin: 10100000] [dec: 160] [EXCLUDE_*: PRIVATE | EMPTY]'
    ->add(Caster::EXCLUDE_NOT_IMPORTANT) // logs '[debug] bitfield changed Caster::EXCLUDE_* [bin: 110100000] [dec: 416] [EXCLUDE_*: PRIVATE | EMPTY | NOT_IMPORTANT]'
;
```

Hierarchical Flags
------------------

[](#hierarchical-flags)

As in [`Output::VERBOSITY_*` case](https://github.com/symfony/symfony/blob/8872833c5d6a46ea27a4483e650617361660d946/src/Symfony/Component/Console/Output/OutputInterface.php#L23-L27), flags are hierachical, like this:

```
VERBOSITY_VERY_VERBOSE
└── VERBOSITY_VERBOSE
    └── VERBOSITY_NORMAL

```

This means that if `VERBOSITY_VERY_VERBOSE` is flagged, `VERBOSITY_VERBOSE` and `VERBOSITY_NORMAL` will be also implicitly flagged.

```
use Symfony\Component\Console\Output\Output;
use Maidmaid\Flag\Flag;

$flag = Flag::create(Output::class, 'VERBOSITY_', $hierachical = true)
    ->add(Output::VERBOSITY_VERBOSE) // logs '[debug] bitfield changed Output::VERBOSITY_* [bin: 1000000] [dec: 64] [VERBOSITY_*: QUIET | NORMAL | VERBOSE]'
    ->add(Output::VERBOSITY_DEBUG)   // logs '[debug] bitfield changed Output::VERBOSITY_* [bin: 101000000] [dec: 320] [VERBOSITY_*: QUIET | NORMAL | VERBOSE | VERY_VERBOSE | DEBUG]'
;
```

Global Flags
------------

[](#global-flags)

It's possible to handle flags in global space, like with [`E_*` errors flags](http://php.net/manual/en/errorfunc.constants.php).

```
use Maidmaid\Flag\Flag;

$flag = Flag::create(null, 'E_')
    ->add(E_ALL)             // logs '[debug] bitfield changed E_* [bin: 111111111111111] [dec: 32767] [E_*: ERROR | RECOVERABLE_ERROR | WARNING | PARSE | NOTICE | STRICT | DEPRECATED | CORE_ERROR | CORE_WARNING | COMPILE_ERROR | COMPILE_WARNING | USER_ERROR | USER_WARNING | USER_NOTICE | USER_DEPRECATED | ALL]'
    ->set(0)                 // logs '[debug] bitfield changed E_* [bin: 0] [dec: 0] [E_*: ]'
    ->add(E_USER_ERROR)      // logs '[debug] bitfield changed E_* [bin: 100000000] [dec: 256] [E_*: USER_ERROR]'
    ->add(E_USER_DEPRECATED) // logs '[debug] bitfield changed E_* [bin: 100000100000000] [dec: 16640] [E_*: USER_ERROR | USER_DEPRECATED]'
;
```

No-int Flags
------------

[](#no-int-flags)

As in [`Request::METHOD_*` case](https://github.com/symfony/symfony/blob/8872833c5d6a46ea27a4483e650617361660d946/src/Symfony/Component/HttpFoundation/Request.php#L49-L58), values flags are not integer but string. For example, `METHOD_GET` has `GET` string as value. This string values are internally binarized.

```
use Symfony\Component\HttpFoundation\Request;
use Maidmaid\Flag\Flag;

$flag = Flag::create(Request::class, 'METHOD_')
    ->add(Request::METHOD_GET)  // logs '[debug] bitfield changed Request::METHOD_* [bin: 10] [dec: 2] [METHOD_*: GET]'
    ->add(Request::METHOD_POST) // logs '[debug] bitfield changed Request::METHOD_* [bin: 110] [dec: 6] [METHOD_*: GET | POST]'
    ->add(Request::METHOD_PUT)  // logs '[debug] bitfield changed Request::METHOD_* [bin: 1110] [dec: 14] [METHOD_*: GET | POST | PUT]'
;
```

Standalone Flags
----------------

[](#standalone-flags)

It's also possible to handle no-constants flags.

```
use Maidmaid\Flag\Flag;

$flag = Flag::create()
    ->add('a') // logs '[debug] bitfield changed [bin: 1] [dec: 1] [flags: a]'
    ->add('b') // logs '[debug] bitfield changed [bin: 11] [dec: 3] [flags: a | b]'
;

$flag = (new Flag())
    ->add(8)  // logs '[debug] bitfield changed [bin: 1000] [dec: 8] [flags: 8]'
    ->add(32) // logs '[debug] bitfield changed [bin: 101000] [dec: 40] [flags: 8 | 32]'
;
```

Debug
-----

[](#debug)

If you add `symfony/console` suggested package, you can debug your flags with `debug:flag` command. Run `php bin/flag --help` for details.

 [![](doc/debug_command.png)](doc/debug_command.png)

License
-------

[](#license)

Flag is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

###  Health Score

25

—

LowBetter than 35% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

3

Last Release

3348d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/4578773?v=4)[Dany Maillard](/maintainers/maidmaid)[@maidmaid](https://github.com/maidmaid)

---

Top Contributors

[![maidmaid](https://avatars.githubusercontent.com/u/4578773?v=4)](https://github.com/maidmaid "maidmaid (12 commits)")

---

Tags

bitfieldbitmaskbitwiseflagsphpphp-libraryflagsbitmaskbitwisebitfield

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/maidmaid-flag/health.svg)

```
[![Health](https://phpackages.com/badges/maidmaid-flag/health.svg)](https://phpackages.com/packages/maidmaid-flag)
```

###  Alternatives

[ecotone/ecotone

Enterprise architecture layer for Laravel and Symfony — CQRS, Event Sourcing, Durable Workflows (Sagas, Orchestrators), Projections, and Outbox messaging via PHP attributes.

562565.8k42](/packages/ecotone-ecotone)[civicrm/civicrm-core

Open source constituent relationship management for non-profits, NGOs and advocacy organizations.

751284.3k37](/packages/civicrm-civicrm-core)[yaroslavche/bitmask

BitMask, EnumBitMask

3456.9k1](/packages/yaroslavche-bitmask)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
