Search by

adachsoft / principal-group

Arkadiusz Adach

Optional user groups for adachsoft/principal-contracts: group model with roles, repository contract, principal expander, membership provider and group service.

Package info

gitlab.com/a.adach/principal-group

Issues

pkg:composer/adachsoft/principal-group

Statistics

Installs: 1

Dependents: 0

Suggesters: 0

Stars: 0

v0.1.0 2026-11-22 23:36 UTC

This package is auto-updated.

Last update: 2026-11-22 22:36:51 UTC


README

adachsoft/principal-group adds optional groups to applications using adachsoft/principal-contracts. Groups act as principals and can contain leaf principals or nested groups.

Features

  • Immutable group and membership models with ADMIN and MEMBER roles.
  • Nested membership lookup and group-to-principal expansion.
  • Access-controlled group management with a last-administrator safeguard.
  • Repository contract with optimistic version checks, plus an in-memory implementation.
  • Injectable clock, identifier generator, and group-change listener.

Installation

composer require adachsoft/principal-group

Requirements

The package requires PHP 8.3 or later and uses adachsoft/reference-contracts, adachsoft/principal-contracts, and PSR-20 clocks.

Usage

use AdachSoft\PrincipalGroup\InMemory\InMemoryGroupRepository;
use AdachSoft\PrincipalGroup\Service\GroupServiceFactory;
use AdachSoft\ReferenceContracts\PrincipalReference;

$repository = new InMemoryGroupRepository();
$groups = GroupServiceFactory::create($repository);

$owner = new PrincipalReference('account', 'alice');
$group = $groups->createGroup($owner, 'Household');

$membershipResolver = GroupServiceFactory::createMembershipResolver($repository);
$principalResolver = GroupServiceFactory::createPrincipalResolver($repository, ['account']);

$memberships = $membershipResolver->membershipsOf($owner);
$accounts = $principalResolver->resolve($group->reference());

Use the in-memory repository for examples and ephemeral storage. For persistent storage, implement GroupRepositoryInterface and pass your adapter to GroupServiceFactory::create(). The same membership resolver can be integrated with other AdachSoft services that support composite membership resolution.

See the usage example for a complete runnable example. Applications can also extend AdachSoft\PrincipalGroup\Testing\AbstractGroupRepositoryContractTest to verify their repository adapter; PHPUnit is required to run those contract tests.