début de travail sur les types simples et time

This commit is contained in:
Jephté Clain 2025-10-21 12:26:20 +04:00
parent aee4a8d7c7
commit c1adebdbd3
7 changed files with 172 additions and 0 deletions

21
src/php/time/Time.php Normal file
View File

@ -0,0 +1,21 @@
<?php
namespace nulib\php\time;
/**
* Class Time: une heure allant de 0h à 24h inclus.
*
* la seule utilisation autorisée de "24h" est comme borne supérieure pour une
* plage horaire.
*/
class Time {
static function with($time): self {
if ($time instanceof static) return $time;
else return new static($time);
}
static function withn($time): ?self {
if ($time === null) return null;
elseif ($time instanceof static) return $time;
else return new static($time);
}
}

24
src/php/types/vdate.php Normal file
View File

@ -0,0 +1,24 @@
<?php
namespace nulib\php\types;
use nulib\php\time\Date;
class vdate {
static function ensure(&$date): void {
$date = Date::with($date);
}
static function ensuren(&$date): void {
$date = Date::withn($date);
}
static function with($value): Date {
self::ensure($value);
return $value;
}
static function withn($value): ?Date {
self::ensuren($value);
return $value;
}
}

View File

@ -0,0 +1,24 @@
<?php
namespace nulib\php\types;
use nulib\php\time\DateTime;
class vdatetime {
static function ensure(&$datetime): void {
$datetime = DateTime::with($datetime);
}
static function ensuren(&$datetime): void {
$datetime = DateTime::withn($datetime);
}
static function with($value): DateTime {
self::ensure($value);
return $value;
}
static function withn($value): ?DateTime {
self::ensuren($value);
return $value;
}
}

18
src/php/types/vmixed.php Normal file
View File

@ -0,0 +1,18 @@
<?php
namespace nulib\php\types;
class vmixed {
static function ensure(&$mixed): void {
}
static function ensuren(&$mixed): void {
}
static function with($value) {
return $value;
}
static function withn($value) {
return $value;
}
}

18
src/php/types/vraw.php Normal file
View File

@ -0,0 +1,18 @@
<?php
namespace nulib\php\types;
class vraw {
static function ensure(&$raw): void {
}
static function ensuren(&$raw): void {
}
static function with($value) {
return $value;
}
static function withn($value) {
return $value;
}
}

43
src/php/types/vschema.php Normal file
View File

@ -0,0 +1,43 @@
<?php
namespace nulib\php\types;
/**
* Class vschema: gestionsimplifiée de schémas associatifs
*
* seuls les types simples sont reconnus
*/
class vschema {
/** @var array types valides */
const TYPES = [
"rawstring" => vrawstring::class,
"string" => vstring::class,
"text" => vtext::class,
"bool" => vbool::class,
"int" => vint::class,
"float" => vfloat::class,
"array" => varray::class,
"func" => vfunc::class,
"raw" => vraw::class,
"mixed" => vmixed::class,
"key" => vkey::class,
"pkey" => vpkey::class,
"content" => vcontent::class,
"datetime" => vdatetime::class,
"date" => vdate::class,
"time" => vtime::class,
];
/** indiquer si $value est conforme au schéma */
static function check($value, array $schema): bool {
}
/**
* s'assurer que $value est conforme au schéma
* - les clés ne sont pas créées si elles n'existent pas
*
*/
static function ensure(&$value, array $schema): void {
}
}

24
src/php/types/vtime.php Normal file
View File

@ -0,0 +1,24 @@
<?php
namespace nulib\php\types;
use nulib\php\time\Time;
class vtime {
static function ensure(&$time): void {
$time = Time::with($time);
}
static function ensuren(&$time): void {
$time = Time::withn($time);
}
static function with($value): Time {
self::ensure($value);
return $value;
}
static function withn($value): ?Time {
self::ensuren($value);
return $value;
}
}