-
Notifications
You must be signed in to change notification settings - Fork 93
/
Copy pathType.php
112 lines (103 loc) · 2.64 KB
/
Type.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<?php
namespace com\fenqile\fsof\consumer;
use com\fenqile\fsof\consumer\ConsumerException;
use Icecave\Collections\Collection;
class Type
{
/*
const SHORT = 1;
const INT = 2;
const INTEGER = 2;
const LONG = 3;
const FLOAT = 4;
const DOUBLE = 5;
const STRING = 6;
const BOOL = 7;
const BOOLEAN = 7;
const MAP = 8;
*/
const ARRAYLIST = 9;
const DEFAULT_TYPE = 10;
const adapter = [
/*
Type::SHORT => 'S',
Type::INT => 'I',
Type::LONG => 'J',
Type::FLOAT => 'F',
Type::DOUBLE => 'D',
Type::BOOLEAN => 'Z',
Type::STRING => 'Ljava/lang/String;',
Type::MAP => 'Ljava/util/Map;',
*/
Type::ARRAYLIST => 'Ljava/util/ArrayList;',
Type::DEFAULT_TYPE => 'Ljava/lang/Object;'
];
private function __construct()
{
}
/**
*
* @param integer $value
* @return UniversalObject
*/
public static function object($class, $properties)
{
$typeObj = new self();
$typeObj->className = $class;
$std = new \stdClass;
foreach ($properties as $key => $value) {
$std->$key = $value;
}
$typeObj->object = $std;
return $typeObj;
}
/**
*
* @param mixed $arg
* @return string
* @throws ConsumerException
*/
public static function argToType($arg)
{
$type = gettype($arg);
switch ($type) {
case 'integer':
case 'boolean':
case 'double':
case 'string':
case 'NULL':
return self::adapter[Type::DEFAULT_TYPE];
case 'array':
if (Collection::isSequential($arg)) {
return self::adapter[Type::ARRAYLIST];
} else {
return self::adapter[Type::DEFAULT_TYPE];
}
case 'object':
if ($arg instanceof Type) {
$className = $arg->className;
} else {
$className = get_class($arg);
}
return 'L' . str_replace(['.', '\\'], '/', $className) . ';';
default:
throw new ConsumerException("Handler for type {$type} not implemented");
}
}
/**
*
* @param int $arg
* @return int
*/
/*
private static function numToType($value)
{
if (-32768 <= $value && $value <= 32767) {
return Type::SHORT;
} elseif (-2147483648 <= $value && $value <= 2147483647) {
return Type::INT;
}
return Type::LONG;
}
*/
}