Oihana PHP

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
author

Marc Alcaraz (ekameleon)

since
1.0.0

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

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
throws
ContainerExceptionInterface

If the container encounters an error while retrieving an entry.

DependencyException

If the dependency cannot be resolved by the container.

Error404

If one of the checked arguments does not match an existing document record.

Error500

If an argument is associated with a null or invalid Documents model reference.

NotFoundException

If the requested entry is not found in the container.

NotFoundExceptionInterface

If no entry was found in the container for the given identifier.

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.

On this page

Search results