1 | <?php |
||
18 | class Types |
||
19 | { |
||
20 | const TYPE_ARRAY = 'array'; |
||
21 | const TYPE_BOOLEAN = 'boolean'; |
||
22 | const TYPE_INTEGER = 'integer'; |
||
23 | const TYPE_NUMBER = 'number'; |
||
24 | const TYPE_NULL = 'null'; |
||
25 | const TYPE_OBJECT = 'object'; |
||
26 | const TYPE_STRING = 'string'; |
||
27 | |||
28 | /** |
||
29 | * @var array |
||
30 | */ |
||
31 | public static $phpToJson = [ |
||
32 | 'array' => self::TYPE_ARRAY, |
||
33 | 'boolean' => self::TYPE_BOOLEAN, |
||
34 | 'double' => self::TYPE_NUMBER, |
||
35 | 'integer' => self::TYPE_INTEGER, |
||
36 | 'NULL' => self::TYPE_NULL, |
||
37 | 'object' => self::TYPE_OBJECT, |
||
38 | 'string' => self::TYPE_STRING, |
||
39 | ]; |
||
40 | |||
41 | /** |
||
42 | * @var array |
||
43 | */ |
||
44 | public static $jsonToPhp = [ |
||
45 | self::TYPE_ARRAY => 'array', |
||
46 | self::TYPE_BOOLEAN => 'boolean', |
||
47 | self::TYPE_INTEGER => 'integer', |
||
48 | self::TYPE_NUMBER => 'double', |
||
49 | self::TYPE_NULL => 'NULL', |
||
50 | self::TYPE_OBJECT => 'object', |
||
51 | self::TYPE_STRING => 'string', |
||
52 | ]; |
||
53 | |||
54 | /** |
||
55 | * @var array |
||
56 | */ |
||
57 | public static $phpJsonCompatibility = [ |
||
58 | 'arrayarray' => true, |
||
59 | 'booleanboolean' => true, |
||
60 | 'doublenumber' => true, |
||
61 | 'integerinteger' => true, |
||
62 | 'integernumber' => true, |
||
63 | 'NULLnull' => true, |
||
64 | 'objectobject' => true, |
||
65 | 'stringstring' => true, |
||
66 | ]; |
||
67 | |||
68 | /** |
||
69 | * Returns the type of an instance according to JSON Schema Core 3.5. |
||
70 | * |
||
71 | * @param mixed $instance |
||
72 | * |
||
73 | * @return string |
||
74 | * |
||
75 | * @throws UnsupportedTypeException |
||
76 | */ |
||
77 | 356 | public static function getPrimitiveTypeOf($instance) |
|
87 | |||
88 | /** |
||
89 | * Returns whether a type is part of the list of primitive types |
||
90 | * defined by the specification. |
||
91 | * |
||
92 | * @param string $jsonType |
||
93 | * |
||
94 | * @return bool |
||
95 | */ |
||
96 | 204 | public static function isPrimitive($jsonType) |
|
100 | } |
||
101 |