41 lines
1.2 KiB
PHP
41 lines
1.2 KiB
PHP
|
<?php
|
||
|
namespace nur\sery\schema;
|
||
|
|
||
|
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;
|
||
|
}
|
||
|
}
|