nur-sery/src/schema/_list/ListSchema.php

53 lines
1.5 KiB
PHP
Raw Normal View History

2023-11-24 16:50:05 +04:00
<?php
2023-11-28 00:20:42 +04:00
namespace nur\sery\schema\_list;
2023-11-27 22:39:35 +04:00
use nur\sery\schema\Schema;
use nur\sery\schema\Value;
2023-11-24 16:50:05 +04:00
class ListSchema extends Schema {
/** @var array meta-schema d'un schéma de nature liste */
const METASCHEMA = [];
/**
* indiquer si $definition est une définition de schéma de nature liste que
* {@link normalize()} pourrait normaliser
*/
static function isa_definition($definition): bool {
if (!is_array($definition)) return false;
# nature explicitement spécifiée
if (array_key_exists("", $definition)) {
$nature = $definition[""];
if ($nature === "list") return true;
if (is_array($nature)
&& array_key_exists(0, $nature)
&& $nature[0] === "list") {
return true;
}
return false;
}
# un unique élément tableau à l'index 0
$count = count($definition);
$haveIndex0 = array_key_exists(0, $definition);
return $count == 1 && $haveIndex0 && is_array($definition[0]);
}
static function normalize($definition): array {
}
function __construct($definition=null, bool $normalize=true) {
if ($definition === null) $definition = static::SCHEMA;
if ($normalize) $definition = self::normalize($definition);
$this->definition = $definition;
}
2023-11-24 22:36:33 +04:00
2023-11-25 10:04:24 +04:00
function isList(?ListSchema &$list=null): bool {
$list = $this;
2023-11-24 22:36:33 +04:00
return true;
}
2023-11-27 22:39:35 +04:00
2023-11-28 00:20:42 +04:00
function newValue(?Value &$value=null, &$dest=null, $key=null): Value {
2023-11-27 22:39:35 +04:00
if (!($value instanceof ListValue)) $value = new ListValue($this);
2023-11-28 00:20:42 +04:00
return $value->reset($dest, $key);
2023-11-27 22:39:35 +04:00
}
2023-11-24 16:50:05 +04:00
}