CheckOwnerArgumentsTrait uses trait:short
Utilities to validate "owner" arguments against Documents models.
This is mainly used to ensure that arguments passed to get(), list(), count() or exist() methods
actually correspond to existing document records.
$controller = new class
{
use \oihana\controllers\traits\CheckOwnerArgumentsTrait;
};
// Initialize owner definitions
$controller->initializeOwner
([
'owner' =>
[
'userId' => $userModel,
'accountId' => $accountModel,
]
]);
// Validate arguments (throws Error404 if a value is not found)
$controller->checkOwnerArguments
([
'userId' => 123,
'accountId' => 456,
]);
// It's safe to call with missing args: they will be ignored
$controller->checkOwnerArguments([ 'userId' => 123 ]);
Table of Contents
Properties
- $owner : array<string, mixed>|null
Methods
- assertExistInModel() : void
- Assert the existence of a specific property value in a Document model.
- checkOwnerArguments() : void
- Check all 'owner' arguments against their Documents model.
- getDocumentsModel() : DocumentsModel|null
- Returns a Documents Model instance directly or with the DI container.
- initializeOwner() : static
- Initialize the owner definition from an array.
Properties
$owner
public
array<string, mixed>|null
$owner
= null
Collection of owner's arguments to check
Methods
assertExistInModel()
Assert the existence of a specific property value in a Document model.
public
assertExistInModel(object|string|int|null $document, ExistModel $model[, string $name = Char::EMPTY ][, string|null $key = 'id' ]) : void
Parameters
- $document : object|string|int|null
-
The document to validate.
- $model : ExistModel
-
The OpenEdge model reference.
- $name : string = Char::EMPTY
-
The optional name of the resource to validate (use it in the error message).
- $key : string|null = 'id'
Tags
checkOwnerArguments()
Check all 'owner' arguments against their Documents model.
public
checkOwnerArguments([array<string|int, mixed> $args = [] ]) : void
Example:
$controller->owner =
[
'userId' => $userModel,
];
$controller->checkOwnerArguments([ 'userId' => 1 ]);
Parameters
- $args : array<string|int, mixed> = []
-
array<string, mixed> $args Arguments to validate
Tags
getDocumentsModel()
Returns a Documents Model instance directly or with the DI container.
public
getDocumentsModel(DocumentsModel|string|null $documents) : DocumentsModel|null
Parameters
- $documents : DocumentsModel|string|null
Tags
Return values
DocumentsModel|nullinitializeOwner()
Initialize the owner definition from an array.
public
initializeOwner([array<string, mixed> $init = [] ]) : static
Example:
$controller->initializeOwner([ 'owner' => [ 'userId' => $userModel ] ]);
Parameters
- $init : array<string, mixed> = []
-
Initialization array