Legend of the Green Dragon

UniqueObject extends ObjectExists

Class that validates if objects exist in a given repository with a given list of matched fields only once.

Tags
license

MIT

see
http://www.doctrine-project.org/
author

Oskar Bley oskar@programming-php.net

Table of Contents

ERROR_NO_OBJECT_FOUND  = 'noObjectFound'
Error constants.
ERROR_OBJECT_NOT_UNIQUE  = 'objectNotUnique'
Error constants.
$fields  : array<string|int, mixed>
Fields to be checked.
$messageTemplates  : array<string|int, mixed>
$objectManager  : ObjectManager
$objectRepository  : ObjectRepository
ObjectRepository from which to search for entities.
$useContext  : bool
__construct()  : mixed
Constructor.
isValid()  : bool
Returns false if there is another object with the same field values but other identifiers.
cleanSearchValue()  : array<string|int, mixed>
getExpectedIdentifiers()  : array<string|int, mixed>
Gets the identifiers from the context.
getFoundIdentifiers()  : array<string|int, mixed>
Gets the identifiers from the matched object.
getIdentifiers()  : array<string|int, mixed>
validateFields()  : array<string|int, mixed>
Filters and validates the fields passed to the constructor.

Constants

ERROR_NO_OBJECT_FOUND

Error constants.

public mixed ERROR_NO_OBJECT_FOUND = 'noObjectFound'

ERROR_OBJECT_NOT_UNIQUE

Error constants.

public mixed ERROR_OBJECT_NOT_UNIQUE = 'objectNotUnique'

Properties

$fields

Fields to be checked.

protected array<string|int, mixed> $fields

$messageTemplates

protected array<string|int, mixed> $messageTemplates = [self::ERROR_OBJECT_NOT_UNIQUE => "There is already another object matching '%value%'"]

$objectRepository

ObjectRepository from which to search for entities.

protected ObjectRepository $objectRepository

Methods

__construct()

Constructor.

public __construct(array<string|int, mixed> $options) : mixed
Parameters
$options : array<string|int, mixed>

required keys are object_repository, which must be an instance of Doctrine\Common\Persistence\ObjectRepository, object_manager, which must be an instance of Doctrine\Common\Persistence\ObjectManager, and fields, with either a string or an array of strings representing the fields to be matched by the validator

Tags
throws
InvalidArgumentException
Return values
mixed

isValid()

Returns false if there is another object with the same field values but other identifiers.

public isValid(mixed $value[, array<string|int, mixed> $context = null ]) : bool
Parameters
$value : mixed
$context : array<string|int, mixed> = null
Return values
bool

cleanSearchValue()

protected cleanSearchValue(string|array<string|int, mixed> $value) : array<string|int, mixed>
Parameters
$value : string|array<string|int, mixed>

a field value or an array of field values if more fields have been configured to be matched

Tags
throws
RuntimeException
Return values
array<string|int, mixed>

getExpectedIdentifiers()

Gets the identifiers from the context.

protected getExpectedIdentifiers([array<string|int, mixed>|object $context = null ]) : array<string|int, mixed>
Parameters
$context : array<string|int, mixed>|object = null
Tags
throws
RuntimeException
Return values
array<string|int, mixed>

getFoundIdentifiers()

Gets the identifiers from the matched object.

protected getFoundIdentifiers(object $match) : array<string|int, mixed>
Parameters
$match : object
Tags
throws
RuntimeException
Return values
array<string|int, mixed>

getIdentifiers()

protected getIdentifiers() : array<string|int, mixed>
Return values
array<string|int, mixed>

the names of the identifiers

validateFields()

Filters and validates the fields passed to the constructor.

private validateFields() : array<string|int, mixed>
Tags
throws
InvalidArgumentException
Return values
array<string|int, mixed>

Search results