fga-php / fga
Framework-agnostic fine-grained authorization contracts and data objects for PHP.
v0.1.1
2026-12-01 17:42 UTC
Requires
- php: ~8.5.0 || ~8.6.0
- php-standard-library/comparison: ^6.4
- php-standard-library/type: ^6.4
Requires (Dev)
- carthage-software/mago: 1.61.0
- phpunit/phpunit: 13.4.8
- rector/rector: 2.9.2
Suggests
None
Provides
None
Conflicts
None
Replaces
None
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\Checkerfor permission checks, bulk checks, lists, explain, and expand.Fga\AccessFilterfor filtering a query by the objects a subject can access.Fga\ObjectReffor typed objects, subjects, usersets, and wildcards.- Immutable request and response objects such as
Page,ListResult,ContextualTuple,Trace, andUsersetTree. Fga\FakeCheckerfor 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.