2023-11-27 22:39:35 +04:00
|
|
|
<?php
|
2024-05-23 08:15:28 +04:00
|
|
|
namespace nur\sery\wip\schema;
|
2023-11-27 22:39:35 +04:00
|
|
|
|
2023-11-28 00:20:42 +04:00
|
|
|
use ArrayAccess;
|
|
|
|
use IteratorAggregate;
|
2024-05-23 08:15:28 +04:00
|
|
|
use nur\sery\wip\schema\_assoc\AssocValue;
|
|
|
|
use nur\sery\wip\schema\_list\ListValue;
|
|
|
|
use nur\sery\wip\schema\_scalar\ScalarValue;
|
|
|
|
use nur\sery\wip\schema\types\IType;
|
2023-11-27 22:39:35 +04:00
|
|
|
|
2023-11-28 00:20:42 +04:00
|
|
|
abstract class Value implements ArrayAccess, IteratorAggregate {
|
2023-11-28 08:20:33 +04:00
|
|
|
function isAssoc(?AssocValue &$assoc=null): bool { return false; }
|
|
|
|
function isList(?ListValue &$list=null): bool { return false; }
|
|
|
|
function isScalar(?ScalarValue &$scalar=null): bool { return false; }
|
|
|
|
|
2023-11-28 00:20:42 +04:00
|
|
|
/** spécifier la valeur destination gérée par cet objet */
|
2023-12-28 19:33:13 +04:00
|
|
|
abstract function reset(&$dest, $destKey=null, ?bool $verifix=null): self;
|
2023-11-27 22:39:35 +04:00
|
|
|
|
2023-11-28 00:20:42 +04:00
|
|
|
/**
|
|
|
|
* Obtenir la liste des clés valides pour les valeurs accessibles via cet
|
|
|
|
* objet
|
|
|
|
*/
|
|
|
|
abstract function getKeys(): array;
|
2023-11-27 22:39:35 +04:00
|
|
|
|
2023-11-28 00:20:42 +04:00
|
|
|
/** obtenir un objet pour gérer la valeur spécifiée */
|
|
|
|
abstract function getValue($key=null): Value;
|
|
|
|
|
|
|
|
function getIterator() {
|
|
|
|
foreach ($this->getKeys() as $key) {
|
|
|
|
yield $key => $this->getValue($key);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-28 19:33:13 +04:00
|
|
|
/**
|
|
|
|
* obtenir le résultat de l'appel d'une des fonctions {@link set()} ou
|
|
|
|
* {@link unset()}
|
|
|
|
*/
|
|
|
|
abstract function getResult(): Result;
|
2023-11-27 22:39:35 +04:00
|
|
|
|
|
|
|
/** retourner true si la valeur existe */
|
2023-12-03 22:44:29 +04:00
|
|
|
abstract function isPresent(): bool;
|
|
|
|
|
2023-12-28 19:33:13 +04:00
|
|
|
/** retourner le type associé à la valeur */
|
|
|
|
abstract function getType(): IType;
|
|
|
|
|
2023-12-03 22:44:29 +04:00
|
|
|
/** retourner true si la valeur est disponible */
|
|
|
|
abstract function isAvailable(): bool;
|
2023-11-27 22:39:35 +04:00
|
|
|
|
|
|
|
/** retourner true si la valeur est valide */
|
2023-12-03 22:44:29 +04:00
|
|
|
abstract function isValid(): bool;
|
2023-11-27 22:39:35 +04:00
|
|
|
|
2023-12-28 19:33:13 +04:00
|
|
|
/** retourner true si la valeur est dans sa forme normalisée */
|
|
|
|
abstract function isNormalized(): bool;
|
|
|
|
|
2023-11-28 00:20:42 +04:00
|
|
|
/** obtenir la valeur */
|
|
|
|
abstract function get($default=null);
|
|
|
|
|
2023-12-28 19:33:13 +04:00
|
|
|
/** remplacer la valeur */
|
|
|
|
abstract function set($value): self;
|
|
|
|
|
|
|
|
/** supprimer la valeur */
|
2023-12-28 19:44:57 +04:00
|
|
|
abstract function unset(): self;
|
2023-11-28 00:20:42 +04:00
|
|
|
|
|
|
|
/** formatter la valeur pour affichage */
|
|
|
|
abstract function format($format=null): string;
|
2023-12-28 19:33:13 +04:00
|
|
|
|
|
|
|
#############################################################################
|
|
|
|
# key & properties
|
|
|
|
|
|
|
|
function offsetExists($offset): bool {
|
|
|
|
return in_array($offset, $this->getKeys());
|
|
|
|
}
|
|
|
|
|
|
|
|
function offsetGet($offset) {
|
|
|
|
return $this->getValue($offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
function offsetSet($offset, $value): void {
|
|
|
|
$this->getValue($offset)->set($value);
|
|
|
|
}
|
|
|
|
|
|
|
|
function offsetUnset($offset): void {
|
|
|
|
$this->getValue($offset)->unset();
|
|
|
|
}
|
2023-11-27 22:39:35 +04:00
|
|
|
}
|