Oihana PHP Arango

CasbinSyncTrait

Shared wiring for controllers that need to invoke {@see CasbinPolicySync} during their lifecycle — typically to clean up policies in the `rbac` collection before a vertex is deleted (cf. PoliciesController + PermissionsController).

Provides:

  • the CASBIN_SYNC init key consumers reference via self::CASBIN_SYNC (per Marc's convention, never CasbinSyncTrait::CASBIN_SYNC) ;
  • the $casbinSync property typed as the optional service ;
  • initializeCasbinSync() a one-line helper that resolves the service from the constructor $init array.

Usage:

use CasbinSyncTrait ;

public function __construct( Container $container , array $init = [] )
{
    parent::__construct( $container , $init ) ;
    $this->initializeCasbinSync( $init , $container ) ;
}
Tags
author

Marc Alcaraz

Table of Contents

Constants

CASBIN_SYNC  : string = 'casbinSync'
Initialization key for the Casbin policy sync service. Consumers must pass either the {@see CasbinPolicySync} instance directly or its DI container identifier (string) under this key in the `$init` array.

Properties

$casbinSync  : CasbinPolicySync|null
The optional Casbin policy sync service.

Methods

initializeCasbinSync()  : static
Resolves the Casbin policy sync service from the `$init` array and stores it on `$this->casbinSync`. Safe to call when the key is absent or the dependency is unavailable — the property simply stays `null` and consumers must guard with `if( $this->casbinSync )`.

Constants

CASBIN_SYNC

Initialization key for the Casbin policy sync service. Consumers must pass either the {@see CasbinPolicySync} instance directly or its DI container identifier (string) under this key in the `$init` array.

public string CASBIN_SYNC = 'casbinSync'

Reference from the consumer class as self::CASBIN_SYNC — never as CasbinSyncTrait::CASBIN_SYNC (PHP 8.2+ forbids the latter).

Properties

Methods

initializeCasbinSync()

Resolves the Casbin policy sync service from the `$init` array and stores it on `$this->casbinSync`. Safe to call when the key is absent or the dependency is unavailable — the property simply stays `null` and consumers must guard with `if( $this->casbinSync )`.

protected initializeCasbinSync(array<string|int, mixed> $init, Container $container) : static

Call from the consumer constructor right after parent::__construct.

Parameters
$init : array<string|int, mixed>

The constructor init array.

$container : Container

The DI container.

Tags
throws
ContainerExceptionInterface
DependencyException
NotFoundException
NotFoundExceptionInterface
Return values
static
On this page

Search results