Search by

fga-php / fga

Perer876

Framework-agnostic fine-grained authorization contracts and data objects for PHP.

Package info

github.com/fga-php/fga

pkg:composer/fga-php/fga

Statistics

Installs: 57

Dependents: 1

Suggesters: 0

Stars: 2

Open Issues: 0

v0.1.1 2026-12-01 17:42 UTC

This package is auto-updated.

Last update: 2026-12-01 21:32:52 UTC


README

Framework-agnostic contracts and value objects for fine-grained authorization in PHP.

This package defines the vocabulary shared by FGA drivers and integrations:

  • Fga\Checker for permission checks, bulk checks, lists, explain, and expand.
  • Fga\AccessFilter for filtering a query by the objects a subject can access.
  • Fga\ObjectRef for typed objects, subjects, usersets, and wildcards.
  • Immutable request and response objects such as Page, ListResult, ContextualTuple, Trace, and UsersetTree.
  • Fga\FakeChecker for tests that must not touch a real authorization backend.

The package uses PSL Type for wire-format validation and PSL Comparison for ObjectRef ordering. Drivers such as fga-php/melange implement the contracts.

Installation

composer require fga-php/fga

Usage

use Fga;

/** @var Fga\Checker $checker */
$checker = $container->get(Fga\Checker::class);

$alice = Fga\ObjectRef::of('user', 'alice');
$document = Fga\ObjectRef::of('document', '123');

if ($checker->check($alice, 'can_read', $document)) {
    // ...
}

Usersets and wildcards use the same encoding as OpenFGA:

Fga\ObjectRef::userset('team', 'eng', 'member'); // team:eng#member
Fga\ObjectRef::wildcard('user');                 // user:*

Testing

use Fga;

$fake = (new Fga\FakeChecker())
    ->allow(Fga\ObjectRef::of('user', 'alice'), 'can_read', Fga\ObjectRef::of('document', '123'));

$fake->check(Fga\ObjectRef::of('user', 'alice'), 'can_read', Fga\ObjectRef::of('document', '123')); // true
$fake->assertChecked(Fga\ObjectRef::of('user', 'alice'), 'can_read', Fga\ObjectRef::of('document', '123'));

License

MIT. See LICENSE.