nur-sery/src/schema/_assoc/AssocSchema.php

56 lines
1.6 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\_assoc;
2023-11-24 16:50:05 +04:00
2024-04-05 08:31:49 +04:00
use nur\sery\cl;
2024-01-01 01:01:27 +04:00
use nur\sery\ref\schema\ref_schema;
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
2024-01-01 01:01:27 +04:00
/**
* Class AssocSchema
*/
2023-11-24 16:50:05 +04:00
class AssocSchema extends Schema {
/** @var array meta-schema d'un schéma de nature tableau associatif */
2024-01-01 01:01:27 +04:00
const METASCHEMA = ref_schema::ASSOC_METASCHEMA;
2023-11-24 16:50:05 +04:00
/**
* 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);
}
2023-11-28 08:20:33 +04:00
static function normalize($definition, $definitionKey=null): array {
2023-11-24 16:50:05 +04:00
}
2023-11-28 08:20:33 +04:00
function __construct($definition=null, $definitionKey=null, bool $normalize=true) {
2023-11-24 16:50:05 +04:00
if ($definition === null) $definition = static::SCHEMA;
2023-11-28 08:20:33 +04:00
if ($normalize) $definition = self::normalize($definition, $definitionKey);
2023-11-24 16:50:05 +04:00
$this->definition = $definition;
}
2023-11-24 22:36:33 +04:00
2023-11-25 10:04:24 +04:00
function isAssoc(?AssocSchema &$assoc=null): bool {
$assoc = $this;
2023-11-24 22:36:33 +04:00
return true;
}
2023-11-27 22:39:35 +04:00
2024-01-01 01:01:27 +04:00
function newValue(?Value &$destv=null, &$dest=null, $destKey=null): AssocValue {
if ($destv instanceof AssocValue) return $destv->reset($dest, $destKey);
else return ($destv = new AssocValue($this, $dest, $destKey));
2023-11-27 22:39:35 +04:00
}
2023-11-24 16:50:05 +04:00
}