PermissionRegistrar
class PermissionRegistrar
Constants
| MODEL_ROLES_CACHE_KEY_PREFIX |
|
| MODEL_PERMISSIONS_CACHE_KEY_PREFIX |
|
| MODEL_CACHE_TOKEN_KEY |
|
| PERMISSION_CATALOG_CONTEXT_KEY |
|
| WILDCARD_PERMISSION_INDEX_CONTEXT_KEY |
|
| MODEL_VIA_ROLE_PERMISSIONS_CONTEXT_KEY |
|
Properties
| static protected string|null | $partitionColumn | ||
| static protected null|Closure(): null|int|string | $partitionResolver | ||
| static protected bool | $initialized | ||
| protected string | $permissionClass | ||
| protected string | $roleClass | ||
| protected string|null | $teamClass | ||
| string | $pivotRole | ||
| string | $pivotPermission | ||
| int | $cacheExpirationTime | ||
| bool | $teams | ||
| protected PermissionsTeamResolver | $teamResolver | ||
| string | $teamsKey | ||
| string | $cacheKey | ||
| protected string | $modelRolesCacheKeyPrefix | ||
| protected string | $modelPermissionsCacheKeyPrefix | ||
| protected string | $modelCacheTokenKey | ||
| protected string|null | $cacheStoreName | ||
| protected PermissionRelationContext}>> | $loadedRelationProvenance |
Methods
Create a new permission registrar.
Configure the permission row partition resolver.
Determine whether permission row partitioning is configured.
Get the configured permission partition column.
Resolve the current permission partition.
Ensure a model belongs to the captured permission partition.
Initialize cache and config-backed registrar state.
Validate the configured model classes.
Validate a configured role model class.
Validate a configured permission model class.
Get the configured cache repository.
Get the memoized cache repository for the current coroutine.
Get the current permissions team id.
Flush the permission cache.
Flush the permission cache for an explicit partition.
Forget a model's direct role and permission assignment caches.
Forget a model's assignment caches for an explicit partition and team.
Forget assignment caches for an explicit morph identity, partition, and team.
Forget a model's role assignment cache for an explicit partition and team.
Forget a model's permission assignment cache for an explicit partition and team.
Remember a model's permissions granted through roles.
Remember a model's role assignment ids.
Remember a model's permission assignment ids.
Build an assignment cache key for an explicit identity and context.
Build the runtime cache key segment for coroutine-local model state.
Build a coroutine-local cache key for an explicit identity and context.
Get the current model assignment cache token.
Bump the model assignment cache token.
Bump the model assignment cache token for an explicit partition.
Create a new model assignment cache namespace token.
Forget the cached wildcard permission index.
Forget one item from a coroutine-local permission cache.
Forget coroutine-local permission cache items for a partition.
Clear already-loaded permissions collection.
Clear all permission runtime state in the current coroutine.
Clear permission runtime state for an explicit partition.
Mark the context that produced a loaded permission relation.
Determine whether a loaded permission relation matches current context.
Forget loaded permission relation provenance for a model.
Get the permissions based on the passed params.
Get the roles based on the passed params.
Get indexed models for supported exact lookup shapes.
Filter a model collection by attributes.
Determine if an attribute matches a requested value.
Get the permission model class.
Get the current global permission cache key.
Add the permission partition to a cache key.
Resolve an optional explicit partition argument.
Build the runtime key prefix for a partition.
Set the permission model class.
Get the role model class.
Set the role model class.
Get the team model class.
Set the team model class.
Get the cache repository.
Get the cache store.
Get permissions with their roles.
Get roles for cache.
Determine if any cached role-permission edge is denied.
Determine if a value is a UUID or ULID.
Flush all static state.
Details
at line 99
__construct(CacheManager $cacheManager, Repository $config, Container $app)
Create a new permission registrar.
at line 119
static void
resolvePartitionUsing(string $column, Closure $resolver)
Configure the permission row partition resolver.
Register before resolving the Permission registrar or Gate.
Boot-only. The column and callback persist in static properties for the worker lifetime and affect every subsequent permission operation.
at line 139
static bool
partitioningEnabled()
Determine whether permission row partitioning is configured.
at line 147
static string|null
partitionColumn()
Get the configured permission partition column.
at line 155
PermissionPartition|null
resolvePartition()
Resolve the current permission partition.
at line 181
PermissionPartition
partitionFromRecord(Model $model)
Resolve a permission partition from a persisted record.
at line 211
void
ensureModelMatchesPartition(Model $model, PermissionPartition $partition)
Ensure a model belongs to the captured permission partition.
at line 229
void
initializeCache()
Initialize cache and config-backed registrar state.
Boot or tests only. The values are stored on the singleton registrar and affect every later permission lookup in this worker.
at line 269
protected void
validateModelClasses()
Validate the configured model classes.
at line 280
protected void
validateRoleClass(string $roleClass)
Validate a configured role model class.
at line 300
protected void
validatePermissionClass(string $permissionClass)
Validate a configured permission model class.
at line 318
protected Repository
configuredCacheRepository()
Get the configured cache repository.
at line 326
protected Repository
cacheRepository()
Get the memoized cache repository for the current coroutine.
at line 334
void
setPermissionsTeamId(int|string|Model|null $id)
Set the current permissions team id.
at line 342
int|string|null
getPermissionsTeamId()
Get the current permissions team id.
at line 350
bool
registerPermissions(Gate $gate)
Register the permission check method on the gate.
at line 372
bool
forgetCachedPermissions()
Flush the permission cache.
at line 380
bool
forgetCachedPermissionsFor(PermissionPartition|null $partition)
Flush the permission cache for an explicit partition.
at line 393
void
forgetModelAssignmentCache(Model $model)
Forget a model's direct role and permission assignment caches.
at line 405
void
forgetModelAssignmentCacheFor(Model $model, PermissionPartition|null $partition, int|string|null $team)
Forget a model's assignment caches for an explicit partition and team.
at line 421
void
forgetModelAssignmentCacheForIdentity(string $morphType, int|string $modelKey, PermissionPartition|null $partition, int|string|null $team)
Forget assignment caches for an explicit morph identity, partition, and team.
at line 458
void
forgetModelRoleCache(Model $model)
Forget a model's cached role assignments.
at line 470
void
forgetModelRoleCacheFor(Model $model, PermissionPartition|null $partition, int|string|null $team)
Forget a model's role assignment cache for an explicit partition and team.
at line 497
void
forgetModelPermissionCache(Model $model)
Forget a model's cached permission assignments.
at line 509
void
forgetModelPermissionCacheFor(Model $model, PermissionPartition|null $partition, int|string|null $team)
Forget a model's permission assignment cache for an explicit partition and team.
at line 537
Collection
rememberModelViaRolePermissions(Model $model, Closure $callback)
Remember a model's permissions granted through roles.
at line 555
void
forgetModelViaRolePermissions(Model $model)
Forget a model's permissions granted through roles.
at line 569
array
rememberModelRoleAssignments(Model $model, Closure $callback)
Remember a model's role assignment ids.
at line 584
array
rememberModelPermissionAssignments(Model $model, Closure $callback)
Remember a model's permission assignment ids.
at line 596
protected string
modelCacheKey(string $prefix, Model $model)
Build the cache key for model assignment caches.
at line 610
protected string
modelCacheKeyForIdentity(string $prefix, string $morphType, int|string $modelKey, PermissionPartition|null $partition, int|string|null $team)
Build an assignment cache key for an explicit identity and context.
at line 629
protected string
modelRuntimeCacheKey(Model $model)
Build the runtime cache key segment for coroutine-local model state.
at line 642
protected string
modelRuntimeCacheKeyForIdentity(string $morphType, int|string $modelKey, PermissionPartition|null $partition, int|string|null $team)
Build a coroutine-local cache key for an explicit identity and context.
at line 660
string
modelAssignmentCacheToken(PermissionPartition|null $partition = null)
Get the current model assignment cache token.
at line 673
string
bumpModelAssignmentCacheToken()
Bump the model assignment cache token.
at line 681
string
bumpModelAssignmentCacheTokenFor(PermissionPartition|null $partition)
Bump the model assignment cache token for an explicit partition.
at line 697
protected string
newModelAssignmentCacheToken()
Create a new model assignment cache namespace token.
at line 705
void
forgetWildcardPermissionIndex(Model|null $record = null)
Forget the cached wildcard permission index.
at line 733
array
getWildcardPermissionIndex(Model $record)
Get the wildcard permission index for a model.
at line 756
protected string
wildcardPermissionIndexKey(Model $record)
Build the coroutine-local wildcard permission index key.
at line 764
protected void
forgetRuntimeCacheItem(string $contextKey, string $itemKey)
Forget one item from a coroutine-local permission cache.
at line 774
protected void
forgetRuntimeCacheItemsForPartition(string $contextKey, PermissionPartition|null $partition)
Forget coroutine-local permission cache items for a partition.
at line 793
void
clearPermissionsCollection()
Clear already-loaded permissions collection.
at line 801
protected void
clearAllPermissionRuntimeState()
Clear all permission runtime state in the current coroutine.
at line 811
protected void
clearPermissionRuntimeStateFor(PermissionPartition|null $partition)
Clear permission runtime state for an explicit partition.
at line 836
void
markLoadedRelation(Model $model, string $relation, Collection $collection, PermissionRelationContext $context)
Mark the context that produced a loaded permission relation.
at line 857
bool
loadedRelationIsCurrent(Model $model, string $relation)
Determine whether a loaded permission relation matches current context.
at line 898
void
forgetLoadedRelationProvenance(Model $model, string|null $relation = null)
Forget loaded permission relation provenance for a model.
at line 980
Collection
getPermissions(array $params = [], bool $onlyOne = false, string|null $permissionClass = null)
Get the permissions based on the passed params.
at line 1006
Collection
getRoles(array $params = [], bool $onlyOne = false, string|null $roleClass = null)
Get the roles based on the passed params.
at line 1032
protected Collection|null
indexedModels(array $params, bool $onlyOne, string $modelType)
Get indexed models for supported exact lookup shapes.
at line 1135
protected Collection
filterModels(Collection $models, array $params, bool $onlyOne)
Filter a model collection by attributes.
at line 1156
static protected bool
attributeMatches(mixed $actual, mixed $expected)
Determine if an attribute matches a requested value.
at line 1176
string
getPermissionClass()
Get the permission model class.
at line 1184
string
getCacheKey()
Get the current global permission cache key.
at line 1192
protected string
partitionedCacheKey(string $key, PermissionPartition|null $partition = null)
Add the permission partition to a cache key.
at line 1206
protected PermissionPartition|null
resolvedPartitionArgument(PermissionPartition|null $partition)
Resolve an optional explicit partition argument.
at line 1216
protected string
partitionRuntimePrefix(PermissionPartition|null $partition)
Build the runtime key prefix for a partition.
at line 1229
PermissionRegistrar
setPermissionClass(string $permissionClass)
Set the permission model class.
Boot or tests only. The model class is stored on the singleton registrar and affects every later permission lookup in this worker.
at line 1244
string
getRoleClass()
Get the role model class.
at line 1257
PermissionRegistrar
setRoleClass(string $roleClass)
Set the role model class.
Boot or tests only. The model class is stored on the singleton registrar and affects every later role lookup in this worker.
at line 1272
string|null
getTeamClass()
Get the team model class.
at line 1285
PermissionRegistrar
setTeamClass(string|null $teamClass)
Set the team model class.
Boot or tests only. The model class is stored on the singleton registrar and affects every later team permission lookup in this worker.
at line 1296
Repository
getCacheRepository()
Get the cache repository.
at line 1304
Store
getCacheStore()
Get the cache store.
at line 1312
protected Collection
getPermissionsWithRoles(string|null $permissionClass = null)
Get permissions with their roles.
at line 1322
protected Collection
getRolesForCache()
Get roles for cache.
at line 1382
bool
hasDeniedRolePermissions()
Determine if any cached role-permission edge is denied.
at line 1390
protected bool
pivotIsDenied(Model $model)
Determine if a hydrated pivot marks the permission as denied.
at line 1404
protected Collection
relationCollection(Model $model, string $relation)
Get a hydrated relation collection.
at line 1534
static bool
isUid(mixed $value)
Determine if a value is a UUID or ULID.
at line 1554
static void
flushState()
Flush all static state.