nur-ture/src/schema/types.php

57 lines
2.4 KiB
PHP

<?php
namespace nur\sery\wip\schema;
use nulib\ValueException;
use nur\sery\wip\schema\types\IType;
use nur\sery\wip\schema\types\Registry;
use nur\sery\wip\schema\types\tarray;
use nur\sery\wip\schema\types\tbool;
use nur\sery\wip\schema\types\tfunc;
use nur\sery\wip\schema\types\tcontent;
use nur\sery\wip\schema\types\tfloat;
use nur\sery\wip\schema\types\tint;
use nur\sery\wip\schema\types\tkey;
use nur\sery\wip\schema\types\tmixed;
use nur\sery\wip\schema\types\tpkey;
use nur\sery\wip\schema\types\traw;
use nur\sery\wip\schema\types\trawstring;
use nur\sery\wip\schema\types\tstring;
use nur\sery\wip\schema\types\ttext;
/**
* Class types: classe outil pour gérer le registre de types
*/
class types {
/** @var Registry */
private static $registry;
static function registry(): Registry {
if (self::$registry === null) {
self::$registry = new Registry();
}
return self::$registry;
}
static function get(bool $nullable, $name, ?array $args=null, ?array $definition=null): IType {
if ($name instanceof IType) return $name;
if ($name !== null && !is_string($name)) {
throw ValueException::invalid_type($name, "string");
}
return self::registry()->get($nullable, $name, $args, $definition);
}
static function rawstring(bool $nullable=true): trawstring { return self::get($nullable, "rawstring"); }
static function string(bool $nullable=true): tstring { return self::get($nullable, "string"); }
static function text(bool $nullable=true): ttext { return self::get($nullable, "text"); }
static function bool(bool $nullable=true): tbool { return self::get($nullable, "bool"); }
static function int(bool $nullable=true): tint { return self::get($nullable, "int"); }
static function float(bool $nullable=true): tfloat { return self::get($nullable, "float"); }
static function array(bool $nullable=true): tarray { return self::get($nullable, "array"); }
static function callable(bool $nullable=true): tfunc { return self::get($nullable, "callable"); }
static function raw(bool $nullable=true): traw { return self::get($nullable, "raw"); }
static function mixed(bool $nullable=true): tmixed { return self::get($nullable, "mixed"); }
static function key(bool $nullable=true): tkey { return self::get($nullable, "key"); }
static function pkey(bool $nullable=true): tpkey { return self::get($nullable, "pkey"); }
static function content(bool $nullable=true): tcontent { return self::get($nullable, "content"); }
}