CheckOwnerArgumentsTrait uses \oihana\models\traits\DocumentsTrait
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 ]);
Tags
Table of Contents
Properties
- $owner : array<string, mixed>|null
Methods
- checkOwnerArguments() : void
- Check all 'owner' arguments against their Documents model.
- 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
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
initializeOwner()
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, the owner definition is read from the ControllerParam::OWNER key.
Return values
static —Returns the current instance for method chaining.