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_SYNCinit key consumers reference viaself::CASBIN_SYNC(per Marc's convention, neverCasbinSyncTrait::CASBIN_SYNC) ; - the
$casbinSyncproperty typed as the optional service ; - initializeCasbinSync() a one-line helper that resolves the
service from the constructor
$initarray.
Usage:
use CasbinSyncTrait ;
public function __construct( Container $container , array $init = [] )
{
parent::__construct( $container , $init ) ;
$this->initializeCasbinSync( $init , $container ) ;
}
Tags
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
$casbinSync
The optional Casbin policy sync service.
protected
CasbinPolicySync|null
$casbinSync
= null
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.