<?php
namespace nur\b\coll;

use nur\data\types\md_utils;
use nur\data\types\Metadata;

/**
 * Trait TArrayMdDynamic: à utiliser avec {@link TAutoconstsDynamic}
 */
trait TArrayMdDynamic {
  protected static function _ensure_md(?Metadata &$md, ?array $schema, ?string $cache_key=null): ?Metadata {
    if ($schema === null) return null;
    return md_utils::ensure_md($md, $schema);
  }

  protected static function _ensure_md_func(?Metadata &$md, ?callable $get_md, ?string $cache_key=null): ?Metadata {
    if ($get_md === null) return null;
    return md_utils::ensure_md_func($md, $get_md);
  }

  /** @var Metadata */
  private static $md;

  protected function md(): ?Metadata {
    return self::_ensure_md(self::$md, self::_AUTOGEN_SCHEMA());
  }
}