1
|
|
|
<?php |
2
|
|
|
namespace net\authorize\util; |
3
|
|
|
|
4
|
|
|
class Mapper{ |
5
|
|
|
private $classes = array(); |
6
|
|
|
// private $dir = __DIR__ . "/../../yml/v1/"; |
|
|
|
|
7
|
|
|
|
8
|
|
|
// private function __construct() { |
|
|
|
|
9
|
|
|
// $files = scandir($this->dir); |
|
|
|
|
10
|
|
|
// foreach ($files as $file) { |
|
|
|
|
11
|
|
|
// // echo "filename:" . $file . "\n"; |
12
|
|
|
// // Elementing the .. |
13
|
|
|
// if($file != "." && $file != ".." ){ |
|
|
|
|
14
|
|
|
// $value = Yaml::parseFile($this->dir.$file); |
|
|
|
|
15
|
|
|
// //var_dump($value); |
16
|
|
|
// //array_push($classes, $value); |
17
|
|
|
// //var_dump($classes); |
18
|
|
|
// //echo $value['net\authorize\api\contract\v1\ANetApiRequestType']['properties']['merchantAuthentication']['type']."\n"; |
19
|
|
|
// $key = key($value); |
|
|
|
|
20
|
|
|
// $this->classes[$key] = $value[$key]; |
|
|
|
|
21
|
|
|
// //break; |
22
|
|
|
// } |
23
|
|
|
// } |
24
|
|
|
// } |
25
|
|
|
private function __construct() { |
26
|
|
|
$this->classes = json_decode(file_get_contents(__DIR__ ."/classes.json"), true); |
|
|
|
|
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public static function Instance() |
30
|
|
|
{ |
31
|
|
|
static $inst = null; |
32
|
|
|
if ($inst === null) { |
33
|
|
|
$inst = new Mapper(); |
34
|
|
|
} |
35
|
|
|
return $inst; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
// public function getClass(string $classname, string $property){ |
|
|
|
|
39
|
|
|
|
40
|
|
|
// if(isset($this->classes[$classname]['properties'][$property]['type'])){ |
|
|
|
|
41
|
|
|
// return $this->classes[$classname]['properties'][$property]['type']; |
|
|
|
|
42
|
|
|
// } |
43
|
|
|
// else if ($property == "refId" || $property == "sessionToken" ){ |
|
|
|
|
44
|
|
|
// return 'string'; |
45
|
|
|
// } |
46
|
|
|
// else if ($property == "messages" ){ |
|
|
|
|
47
|
|
|
// return 'net\authorize\api\contract\v1\MessagesType'; |
48
|
|
|
// } |
49
|
|
|
// else{ |
50
|
|
|
// echo "Error finding in YAML - ".$classname." ".$property."\n"; |
|
|
|
|
51
|
|
|
// return 'string'; |
52
|
|
|
// } |
53
|
|
|
// // return $this->classes[$classname]['properties'][$property]['type']; |
54
|
|
|
// } |
55
|
|
|
|
56
|
|
|
public function getClass($class, $property){ |
57
|
|
|
// make the first letter of property as lowercase as all properties are lowercase |
58
|
|
|
$property = lcfirst($property); |
59
|
|
|
|
60
|
|
|
//echo "getClass calling : class - " . $class . " property - " . $property . "\n"; |
61
|
|
|
$obj = new MapperObj; |
62
|
|
|
|
63
|
|
|
if(isset($this->classes[$class]['properties'][$property]['type'])){ |
64
|
|
|
$className = $this->classes[$class]['properties'][$property]['type']; |
65
|
|
|
if (stripos($className, "DateTime<'Y-m-d'>") !== false) { |
66
|
|
|
$className = 'Date'; |
67
|
|
|
} |
68
|
|
|
else if (stripos($className, "DateTime") !== false) { |
69
|
|
|
$className = 'DateTime'; |
70
|
|
|
} |
71
|
|
|
if(substr( $className, 0, 5 ) === "array") { |
72
|
|
|
$className = ltrim($className, 'array<'); |
73
|
|
|
$className = rtrim($className, '>'); |
74
|
|
|
$obj->isArray = true; |
75
|
|
|
|
76
|
|
|
if(isset($this->classes[$class]['properties'][$property]['xml_list']['entry_name'])){ |
77
|
|
|
// echo $file."\t\t\t\t\t\t\t\t\t"; |
|
|
|
|
78
|
|
|
// echo $propKey." :: ".$prop['serialized_name']." - ".$prop['xml_list']['entry_name']." - ".$prop['xml_list']['inline']; |
|
|
|
|
79
|
|
|
// echo "\n"; |
80
|
|
|
$obj->isInlineArray = $this->classes[$class]['properties'][$property]['xml_list']['inline']; |
81
|
|
|
$obj->arrayEntryname = $this->classes[$class]['properties'][$property]['xml_list']['entry_name']; |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
$obj->className = $className; |
85
|
|
|
$obj->isCustomDefined = stripos($className, '\\') !== false; |
86
|
|
|
|
87
|
|
|
return $obj; |
88
|
|
|
} |
89
|
|
|
else if(get_parent_class($class)){ |
90
|
|
|
//echo "Checking parent class in YAML - ".get_parent_class($class)." -".$class." - ".$property."\n"; |
|
|
|
|
91
|
|
|
return $this->getClass(get_parent_class($class), $property); |
92
|
|
|
} |
93
|
|
|
// else if ($property == "refId" || $property == "sessionToken" ){ |
|
|
|
|
94
|
|
|
// return 'string'; |
95
|
|
|
// } |
96
|
|
|
// else if ($property == "messages" ){ |
97
|
|
|
// |
98
|
|
|
// $className = 'net\authorize\api\contract\v1\MessagesType'; |
99
|
|
|
// $obj->className = $className; |
100
|
|
|
// $obj->isCustomDefined = stripos($className, '\\') !== false; |
101
|
|
|
// |
102
|
|
|
// return $obj; |
103
|
|
|
// } |
104
|
|
|
else{ |
105
|
|
|
//echo "Error finding in YAML - ".$class." - ".$property."\n"; |
|
|
|
|
106
|
|
|
$obj = NULL; |
107
|
|
|
return $obj; |
108
|
|
|
} |
109
|
|
|
// return $this->classes[$classname]['properties'][$property]['type']; |
|
|
|
|
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
public function getXmlName($class){ |
113
|
|
|
if(isset($this->classes[$class]['xml_root_name'])){ |
114
|
|
|
return $this->classes[$class]['xml_root_name']; |
115
|
|
|
} |
116
|
|
|
} |
117
|
|
|
} |
118
|
|
|
//echo $classes['net\authorize\api\contract\v1\ANetApiRequestType']['properties']['merchantAuthentication']['type']."\n"; |
|
|
|
|
119
|
|
|
|
120
|
|
|
//$value = Yaml::parseFile('/*.yaml'); |
|
|
|
|
121
|
|
|
|
122
|
|
|
?> |
|
|
|
|
123
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.