<?php
namespace nulib\schema\types;

abstract class _tformatable extends _tsimple {
  const FORMAT = null;

  static function get_params_from_definition(?array $definition): ?array {
    $params = null;
    $format = $definition["format"] ?? null;
    if ($format !== null) $params["format"] = $format;
    return $params;
  }

  function format($value, $format=null): string {
    $format ??= $this->params["format"] ?? static::FORMAT;
    if ($format !== null) return sprintf($format, $value);
    else return strval($value);
  }
}
