2016-09-27 06:20:02 +00:00
|
|
|
<?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;
|
|
|
|
|
2018-05-23 09:08:11 +00:00
|
|
|
static function get($value)
|
2016-09-27 06:20:02 +00:00
|
|
|
{
|
2018-05-23 09:08:11 +00:00
|
|
|
if (is_bool($value))
|
2016-09-27 06:20:02 +00:00
|
|
|
return self::BOOLEAN;
|
2018-05-23 09:08:11 +00:00
|
|
|
elseif (is_int($value))
|
2016-09-27 06:20:02 +00:00
|
|
|
return self::INTEGER;
|
2018-05-23 09:08:11 +00:00
|
|
|
elseif (is_float($value))
|
2016-09-27 06:20:02 +00:00
|
|
|
return self::DOUBLE;
|
2018-05-23 09:08:11 +00:00
|
|
|
elseif (is_string($value))
|
2016-09-27 06:20:02 +00:00
|
|
|
return self::STRING;
|
2018-05-23 09:08:11 +00:00
|
|
|
elseif (is_object($value))
|
2016-09-27 06:20:02 +00:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2018-05-23 09:08:11 +00:00
|
|
|
static function set(& $value, $type)
|
2016-09-27 06:20:02 +00:00
|
|
|
{
|
|
|
|
switch ($type)
|
|
|
|
{
|
|
|
|
case self::INTEGER:
|
2018-05-23 09:08:11 +00:00
|
|
|
settype($value, 'integer');
|
2016-09-27 06:20:02 +00:00
|
|
|
break;
|
|
|
|
case self::DOUBLE:
|
2018-05-23 09:08:11 +00:00
|
|
|
settype($value, 'float');
|
2016-09-27 06:20:02 +00:00
|
|
|
break;
|
|
|
|
case self::STRING:
|
2018-05-23 09:08:11 +00:00
|
|
|
settype($value, 'string');
|
2016-09-27 06:20:02 +00:00
|
|
|
break;
|
|
|
|
case self::BOOLEAN:
|
2018-05-23 09:08:11 +00:00
|
|
|
settype($value, 'boolean');
|
2016-09-27 06:20:02 +00:00
|
|
|
break;
|
|
|
|
case self::NUL:
|
|
|
|
$value = NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|