2017 © Pedro Peláez
 

library type-detector

TypeDetector is php library to detect variable types by the name and value

image

yarco/type-detector

TypeDetector is php library to detect variable types by the name and value

  • Sunday, November 13, 2016
  • by yarcowang
  • Repository
  • 1 Watchers
  • 0 Stars
  • 4 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

Type Detector

Latest Version Software License Build Status Total Downloads, (*1)

TypeDetector is php library to detect variable types by the key name and the value. The thinkings inherit from superunit and php-schema ( both are my experimental projects )., (*2)

Usage

Use composer to install this library., (*3)

composer require yarco/type-detector, (*4)

Use the class's static method array TypeDetector::detect(array $array) to get key-value pair of the types., (*5)

Example:, (*6)

use Yarco\TypeDetector;

$result = TypeDetector::detect(['name' => 'yarco', 'age' => 36]);
print_r($result);

/*
it should return

Array
(
    [name] => string
    [age] => smallint
)

*/

Types

Below fields are referenced from w3schools.com., (*7)

Number

MySQL Data Types SQL Server Data Types HTML Input Types Doctrine Types Type Detector Supported
TINYINT(size) tinyint
SMALLINT(size) smallint smallint smallint
MEDIUMINT(size)
INT(size) int range, number integer int
BIGINT(size) bigint bigint bigint
FLOAT(size,d) real
DOUBLE(size,d) float(n) float float
DECIMAL(size,d) decimal(p,s) decimal decimal
numeric(p,s)
smallmoney
money
bit boolean

Text

MySQL Data Types SQL Server Data Types HTML Input Types Doctrine Types Type Detector Supported
CHAR(size) char(n), nchar(n)
VARCHAR(size) varchar(n), nvarchar(n) text string string
TINYTEXT
TEXT text, ntext textarea text text
BLOB binary, varbinary binary
MEDIUMTEXT
MEDIUMBLOB
LONGTEXT
LONGBLOB image blob
ENUM(x,y,z,etc.) select
SET
password password
color color
email email
search
tel
url url

Datetime

MySQL Data Types SQL Server Data Types HTML Input Types Doctrine Types Type Detector Supported
DATE date date date date
DATETIME datetime, datetime2, smalldatetime datetime, datetime-local datetime datetime
TIMESTAMP timestamp
TIME time time time time
YEAR month,week
datetimeoffset datetimetz

Other

MySQL Data Types SQL Server Data Types HTML Input Types Doctrine Types Type Detector Supported
uniqueidentifier guid
JSON checkbox

Valid Type Definitions

Type Detector Supported Types Definition Priority (large first)
smallint type is integer and value less than 100 120
bigint type is integer and value large than 10000 120
int type is integer 115
decimal type is float and number of the fraction is either 2 or 3 112
float type is float 110
password type is string and value is *** 100
color type is string and value match ^#[0-9a-fA-F]{6}$ 90
email type is string and value is email 80
url type is string and value is url 70
date type is string and value match ^\d{2}/\d{2}/\d{4}$ or ^\d{4}-\d{2}-\d{2}$ 60
time type is string and value match ^\d{2}:\d{2}:\d{2}$ or ^\d{2}:\d{2}$ 60
datetime type is tring and value match ^\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}(?::\d{2})?$ or can be convert to datetime 55
string type is string and length less than 27 20
text type is tring 0

The Versions

13/11 2016

dev-master

9999999-dev

TypeDetector is php library to detect variable types by the name and value

  Sources   Download

MIT

The Requires

  • php ^7.0

 

The Development Requires

13/11 2016

v0.0.2

0.0.2.0

TypeDetector is php library to detect variable types by the name and value

  Sources   Download

MIT

The Requires

  • php ^7.0

 

The Development Requires

12/11 2016

v0.0.1

0.0.1.0

TypeDetector is php library to detect variable types by the name and value

  Sources   Download

MIT

The Requires

  • php ^7.0

 

The Development Requires