Initial Version
This commit is contained in:
46
shared/lib/Resource/Selector/EntitySelector.php
Normal file
46
shared/lib/Resource/Selector/EntitySelector.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace KTXF\Resource\Selector;
|
||||
|
||||
/**
|
||||
* Entity-level selector (leaf node)
|
||||
*/
|
||||
class EntitySelector extends SelectorAbstract {
|
||||
|
||||
protected array $keyTypes = ['string', 'integer'];
|
||||
protected array $valueTypes = ['boolean', 'array', 'string', 'integer'];
|
||||
protected string $selectorName = 'EntitySelector';
|
||||
|
||||
public function append($value): void {
|
||||
if (!is_string($value) && !is_int($value)) {
|
||||
throw new \InvalidArgumentException('EntitySelector values must be string or int');
|
||||
}
|
||||
parent::append($value);
|
||||
}
|
||||
|
||||
public function offsetSet($key, $value): void {
|
||||
if ($key !== null && !is_int($key)) {
|
||||
throw new \InvalidArgumentException('EntitySelector does not support associative keys');
|
||||
}
|
||||
if (!is_string($value) && !is_int($value)) {
|
||||
throw new \InvalidArgumentException('EntitySelector values must be string or int');
|
||||
}
|
||||
parent::offsetSet($key, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all entity identifiers
|
||||
* @return array<string|int>
|
||||
*/
|
||||
public function identifiers(): array {
|
||||
return $this->getArrayCopy();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user