2023-11-24 16:50:05 +04:00
|
|
|
<?php
|
|
|
|
namespace nur\sery\schema;
|
|
|
|
|
|
|
|
use nulib\cl;
|
|
|
|
|
|
|
|
class AssocSchema extends Schema {
|
|
|
|
/** @var array meta-schema d'un schéma de nature tableau associatif */
|
|
|
|
const METASCHEMA = [];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* indiquer si $definition est une définition de schéma de nature tableau
|
|
|
|
* associatif 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 === "assoc") return true;
|
|
|
|
if (is_array($nature)
|
|
|
|
&& array_key_exists(0, $nature)
|
|
|
|
&& $nature[0] === "assoc") {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
# un tableau associatif
|
|
|
|
return !cl::have_num_keys($definition);
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
function isAssoc(): bool {
|
|
|
|
return true;
|
|
|
|
}
|
2023-11-24 16:50:05 +04:00
|
|
|
}
|