Download the PHP package halaabdulmottleeb/bitmask-permissions without Composer

On this page you can find all versions of the php package halaabdulmottleeb/bitmask-permissions. 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 bitmask-permissions

Bitmask Permissions

A lightweight, high-performance authorization package for Laravel that stores permissions as integer bitmasks instead of relational pivot tables.

Every permission a subject holds on a resource is packed into a single integer column, so checks are a single indexed query with a bitwise AND — no joins, no pivot-row lookups. It supports both object-level (per-record) and global (resource-wide) grants out of the box.

Why bitmasks?

Traditional permission packages store each grant as one or more rows across several pivot tables. This package stores all of a subject's permissions on a given resource in one BIGINT:

Pivot-table approach Bitmask (this package)
Storage per grant multiple rows across pivot tables a single integer column
Permission check row lookups / joins one bitwise AND in a single indexed query
Object-level permissions not first-class native (resource_type + nullable resource_id)
Combining permissions insert / delete rows bitwise OR / AND

Trade-off: the number of distinct permissions per resource type is capped by the integer width (64 with BIGINT), and there are no built-in roles/caching helpers. It's optimized for fast, fine-grained, per-resource checks.

Requirements

Installation

The service provider is auto-discovered. Publish and run the migration:

Optionally publish the config file to change the table name:

Usage

1. Define your permissions as bit values

Each permission is a single bit — use powers of two. An enum is a clean way to do this:

2. Add the trait to any model that can hold permissions

Any Eloquent model works as the subject (User, Team, ApiClient, ...) because the relation is polymorphic.

3. Grant, check, and revoke

Combining permissions

Because permissions are bits, you can grant several at once with a bitwise OR:

hasPermissionTo() checks that all requested bits are present ((mask & permission) = permission).

Global (resource-wide) grants

The resource_id column is nullable. A grant with a null resource_id applies to every record of that resource type, and hasPermissionTo() matches either the specific record or the global grant.

API

The HasBitmaskPermissions trait adds:

Method Description
grantPermissionTo(int $permission, Model $resource) Adds the permission bit(s) for the subject on the resource.
hasPermissionTo(int $permission, Model $resource): bool Returns true if the subject has all requested bits (record-specific or global).
revokePermission(int $permission, Model $resource) Clears the permission bit(s) for the subject on the resource.
grantPermissions(): MorphMany The underlying polymorphic relation to PermissionGrant.

Configuration

config/bitmask-permissions.php:

Schema

A single table holds everything:

Testing

Tests run against an in-memory SQLite database via Orchestra Testbench.

License

MIT © Hala Abdulmottleb


All versions of bitmask-permissions with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
illuminate/database Version ^10.0|^11.0|^12.0|^13.0
illuminate/support Version ^10.0|^11.0|^12.0|^13.0
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 halaabdulmottleeb/bitmask-permissions contains the following files

Loading the files please wait ...