2023-11-09 10:03:35 +04:00
|
|
|
<?php
|
|
|
|
namespace nur\sery\schema;
|
|
|
|
|
2023-11-24 16:50:05 +04:00
|
|
|
abstract class Schema {
|
2023-11-09 10:03:35 +04:00
|
|
|
/**
|
2023-11-24 16:50:05 +04:00
|
|
|
* créer si besoin une nouvelle instance à partir d'une définition de schéma
|
2023-11-09 10:03:35 +04:00
|
|
|
*/
|
2023-11-24 16:50:05 +04:00
|
|
|
static function new(&$md, $definition): self {
|
|
|
|
if ($md === null) {
|
|
|
|
if (AssocSchema::isa_definition($definition)) {
|
|
|
|
$md = new AssocSchema($definition);
|
|
|
|
} elseif (ListSchema::isa_definition($definition)) {
|
|
|
|
$md = new ListSchema($definition);
|
|
|
|
} elseif (ScalarSchema::isa_definition($definition)) {
|
|
|
|
$md = new ScalarSchema($definition);
|
|
|
|
} else {
|
|
|
|
throw SchemaException::invalid_schema();
|
|
|
|
}
|
|
|
|
}
|
2023-11-09 10:03:35 +04:00
|
|
|
return $md;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2023-11-24 16:50:05 +04:00
|
|
|
* @var array définition du schéma, à redéfinir le cas échéant dans une classe
|
|
|
|
* dérivée
|
2023-11-09 10:03:35 +04:00
|
|
|
*/
|
2023-11-24 16:50:05 +04:00
|
|
|
const SCHEMA = null;
|
2023-11-09 10:03:35 +04:00
|
|
|
|
2023-11-24 16:50:05 +04:00
|
|
|
/** @var array */
|
|
|
|
protected $definition;
|
2023-11-09 10:03:35 +04:00
|
|
|
}
|