Download the PHP package vaened/php-sentinel without Composer

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

PHP Sentinel

Tests

Framework-agnostic authorization core for PHP 8.4+.

Installation

Requires PHP 8.4 or higher. Its only dependency is vaened/support.

The example assumes concrete model and persistence implementations are already wired in your application bootstrap.

Integration surface

Sentinel provides the Registry services, including the concrete PermissionEntryProvider and RoleEntryProvider. The package consumer implements the domain and repository contracts.

Foundations

These contracts define the minimum model Sentinel needs to evaluate authorization.

Repositories

Repositories persist both the catalog and the relationships between subjects, roles, and permissions.

Each repository exposes the combination of lookup, grants, exists, allOf, create, update, and remove that belongs to its own contract.

Entry providers

The entry providers are concrete core services. They compose repositories and return the entries consumed by the Authorizer.

Caching the authorization checks

Calls to can, cannot, is, and isnt are the hot path of any authorization system. Sentinel provides an optional cache layer that avoids recomputing a subject's effective authorization projection on every check.

What gets cached

Sentinel caches the effective authorization projection of a subject: the assigned roles and the state of each applicable permission, whether direct or inherited through a role. That projection is built once per subject and then reused on every subsequent can / is check.

For cached permissions, Sentinel preserves three states:

What the cache does NOT do:

Decisions you have to make

Before wiring the layer, there are three operational decisions you need to make:

  1. Provide a PSR-16 driver. The cache layer is built on top of any Psr\SimpleCache\CacheInterface implementation — Redis, Memcached, APCu, file, whatever you already use. Without a driver, there is no cache. If your framework already gives you a PSR-16 driver (Laravel, Symfony, etc.), use it.
  2. Choose a unique prefix per application. Keys are stored as prefix:... in the driver. If two applications share the same PSR-16 driver (common in multi-tenant setups), they need different prefixes. Suggested convention: app_name:sentinel.
  3. Understand what the default ttl does. Sentinel applies a default ttl of 12 hours (CacheSettings::DEFAULT_TTL_IN_SECONDS). A projection lives for exactly that long from the moment it is first captured — it is not renewed on every read: it is only renewed when it is rebuilt. In practice:

    • If the projection is queried within 12 hours of being captured, it is served from cache.
    • If more than 12 hours pass, the next query rebuilds the projection (a single database hit) and starts a new 12-hour window.
    • An inactive subject leaves its projection orphaned; the driver releases it after the TTL. This keeps cache memory from growing without bound if the driver does not have its own eviction policy.

    Pass ttl: null if you want projections to never expire by time and prefer to manage cleanup through an external mechanism.

How to wire it up

First, choose how to construct the factory. Then use that factory to wrap your five base repositories.

Using the bundled PSR-16 store

If you already have a driver compatible with Psr\SimpleCache\CacheInterface, this is the direct path:

Using your own authorization cache store

If you need a different storage or invalidation strategy, you can implement AuthorizationCacheStore and hand it to the factory:

Building the cached repositories

Once you have the factory, wrap your five base repositories and get a CachedRepositories:

The returned repositories implement the same interfaces as the base ones. Your consumer code does not change: you pass $cached->subjectRoleRepository() where you used to pass $mySubjectRoleRepo.

Authorization cache store

AuthorizationCacheStore is the contract that encapsulates projection storage, global invalidation, per-subject invalidation, and construction of the effective cache key.

Stores receive a typed SubjectAuthorizationProjection. Use toArray() when crossing a serialization boundary and SubjectAuthorizationProjection::fromArray() when restoring a payload into a projection.

Sentinel includes a default implementation based on PSR-16: Psr16AuthorizationCacheStore.

You can create your own implementation if you need:

The main limitation of the default PSR-16 implementation is that, when you call invalidate(), previous projections stop being read immediately, but remain orphaned and continue occupying space in the driver until their TTL expires.

Invalidating manually

The factory does not expose the internal invalidation services. If you need to invalidate manually (for example, in an artisan command, after a large migration, or when a specific subject changed roles), instantiate Psr16AuthorizationCacheStore separately with the same driver and the same settings:

Important: database mutations performed outside Sentinel operators (direct SQL queries, other processes, improvised seeds) do not invalidate the cache automatically. If that happens, call invalidate() or forget() manually.

Inspecting the cache

If you inspect your PSR-16 driver with an external tool (Redis Commander, APCu GUI, etc.), you will see keys in this format:

{N} is the active namespace version. Every time you call invalidate(), all projections move to v{N+1} and the previous ones become orphaned (they are no longer read, and the driver eventually clears them).

Implementation references

Authorizer

Authorizer is the read gate. It combines a PermissionEntryProvider and a RoleEntryProvider and answers boolean questions about a Subject. It is constructed once with both providers and is then ready to answer can, cannot, is, and isnt at any time.

can()

Returns true when the subject has at least one of the requested permissions, or all of them when you pass Junction::And.

cannot()

Inverse of can(). Same signature.

is()

Returns true when the subject has at least one of the requested roles, or all of them when you pass Junction::And.

isnt()

Inverse of is(). Same signature.

Junction

Enum with two cases:

Operators

The three operators mutate state through your repositories. All of them are variadic, so they can attach or detach multiple items in a single call.

Granter

Granter grants assignments.

It accepts Subject or Role as owner. If it receives a Role as owner and another Role as authorization, it throws InvalidAuthorization: roles cannot contain other roles.

Denier

Denier explicitly denies permissions to a subject. It applies the central rule: a direct denial overrides any inherited permission.

It only accepts Subject as an owner. Roles do not support denials.

Revoker

Revoker removes any previous assignment, whether it was a grant or a denial. It is idempotent: if the assignment does not exist, it makes no changes.

It accepts Subject or Role as owner.

Registry

RoleRegistry manage the registration operations for each entity: create, update, remove, plus read helpers for administration (lookup, find).

Errors

All exceptions thrown by Sentinel extend AuthorizationError, which itself extends RuntimeException. To catch any Sentinel error:

Specific exceptions:

Exception Thrown when
PermissionAlreadyExists PermissionRegistry::create receives a code that already exists.
RoleAlreadyExists RoleRegistry::create receives a code that already exists.
PermissionNotFound PermissionRegistry::update or an operator cannot find the id/code.
RoleNotFound RoleRegistry::update or an operator cannot find the id/code.
PermissionInUse PermissionRegistry::remove detects a linked subject or role.
RoleInUse RoleRegistry::remove detects a subject linked to that role.
InvalidAuthorization Granter receives roles as targets from an owner that is also a role.

Development

Additional documentation

You can find more details in the source code as well as in the tests located in tests/.

The tests cover different usage scenarios and can serve as additional reference for understanding the library’s behavior.


All versions of php-sentinel with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
psr/simple-cache Version ^3.0
vaened/support Version ^4.2
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 vaened/php-sentinel contains the following files

Loading the files please wait ...