<?php
namespace nur\sery\wip\schema\types;

use nur\sery\cl;

class Registry {
  const TYPES = [
    "string" => tstring::class,
    "bool" => tbool::class, "boolean" => tbool::class,
    "int" => tint::class, "integer" => tint::class,
    "float" => tfloat::class, "flt" => tfloat::class,
    "double" => tfloat::class, "dbl" => tfloat::class,
    "array" => tarray::class,
    "callable" => tcallable::class,
    # types spéciaux
    "key" => tkey::class,
    "pkey" => tpkey::class,
    "content" => tcontent::class,
  ];

  function __construct() {
    $this->types = [];
  }

  /** @var IType[] */
  protected $types;

  function get(string $name): IType {
    $type = cl::get($this->types, $name);
    if ($type === null) {
      $class = self::TYPES[$name];
      $type = $this->types[$name] = new $class();
    }
    return $type;
  }
}
