Download the PHP package reinder83/binary-flags without Composer

On this page you can find all versions of the php package reinder83/binary-flags. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package binary-flags

test

BinaryFlags

With this class you can easily add flags to your projects.

The number of flags you can use is limited to the architecture of your system, e.g.: 32 flags on a 32-bit system or 64 flags on 64-bit system. To store 64-bits flags in a database, you will need to store it as UNSIGNED BIGINT in MySQL or an equivalent in your datastore.

This package also comes with a trait which you can use to implement binary flags directly in your own class.

Installing

To install this package simply run the following command in the root of your project.

Methods

The following methods can be used:

setMask(int $mask)

Overwrite the current mask. This can be passed as first argument in the constructor.

getMask(): int

Retrieve the current mask.

setOnModifyCallback(callable $onModify)

Set a callback function which is called when the mask changes. This can be passed as second argument in the constructor.

getFlagNames([int $mask, [bool $asArray=false]])

Give the name(s) for the given $mask or the current mask when omitted. When $asArray is true the method will return an array with the names, otherwise a comma separated string will be returned (default).

addFlag(int $flag)

Adds one or multiple flags to the current mask.

removeFlag(int $flag)

Removes one or multiple flags from the current mask.

checkFlag(int $flag, [bool $checkAll=true]): bool

Check if given flag(s) are set in the current mask. By default, it will check all bits in the given flag. When you want to match any of the given flags set $checkAll to false.

checkAnyFlag(int $mask): bool

Since: v1.0.1 \ For you convenient I've added an alias to checkFlag with $checkAll set to false.

count(): int

Since: v1.2.0 \ Returns the number of flags that have been set.

jsonSerialize(): mixed

Since: v1.2.0 \ Return a value that can be encoded by json_encode() in the form of ["mask" => 7]. You should not have to call this method directly, instead you can pass the BinaryFlags object to json_encode which will convert it to '{"mask": 7}'.

Static Methods

The following static methods can be used:

getAllFlags(): array

Since: v1.1.0 \ Return all the flags with their names as an array, using their flag mask as key. This method can also be overloaded to return custom names for the flags, which will be used by the getFlagNames method.

getAllFlagsMask(): int

Since: v1.1.0 \ Return mask of all the flags together

Iteration

Since: v1.2.0 \ You can treat a BinaryFlags object as an iterable, where each iteration will return the next bit value that has been set including its description (or the name of the constant representing the bit value).

Example usage

Below some example usage code

Create classes
Simple usage
Usage with multiple flags
Flag names example

By default, the flag names are based on the constant names

Custom flag names example

If you want custom flag names that are not equal to the constant names, you can override these with getAllFlags()

Example usage with Eloquent models

Support

For bugs or feature requests feel free to contact me or submit an issue or pull request. Or you can support me by buying me a coffee:

Buy me a coffee


All versions of binary-flags with dependencies

PHP Build Version
Package Version
Requires php Version ^8.0
ext-json Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package reinder83/binary-flags contains the following files

Loading the files please wait ....