php-vn-lib/lib/type.php

69 lines
1.2 KiB
PHP

<?php
namespace Vn\Lib;
class Time extends \DateTime {}
class Date extends \DateTime {}
class Type
{
const NUL = 1;
const BOOLEAN = 2;
const INTEGER = 3;
const DOUBLE = 4;
const STRING = 5;
const OBJECT = 6;
const TIME = 7;
const DATE = 8;
const DATE_TIME = 9;
static function get($value)
{
if (is_bool($value))
return self::BOOLEAN;
elseif (is_int($value))
return self::INTEGER;
elseif (is_float($value))
return self::DOUBLE;
elseif (is_string($value))
return self::STRING;
elseif (is_object($value))
{
if ($value instanceof Time)
return self::TIME;
elseif ($value instanceof Date)
return self::DATE;
elseif ($value instanceof \DateTime)
return self::DATE_TIME;
else
return self::OBJECT;
}
return self::NUL;
}
static function set(& $value, $type)
{
switch ($type)
{
case self::INTEGER:
settype($value, 'integer');
break;
case self::DOUBLE:
settype($value, 'float');
break;
case self::STRING:
settype($value, 'string');
break;
case self::BOOLEAN:
settype($value, 'boolean');
break;
case self::NUL:
$value = NULL;
break;
}
}
}