|
| 1 | +<?php |
| 2 | +namespace net\authorize\api\contract\v1; |
| 3 | +use Symfony\Component\Yaml\Yaml; |
| 4 | + |
| 5 | +class Mapper{ |
| 6 | + private $classes = array(); |
| 7 | + private $dir = "../../yml/v1/"; |
| 8 | + |
| 9 | + function __construct() { |
| 10 | + $files = scandir($this->dir); |
| 11 | + foreach ($files as $file) { |
| 12 | + //echo "filename:" . $file . "\n"; |
| 13 | + // Elementing the .. |
| 14 | + if($file != "." && $file != ".." ){ |
| 15 | + $value = Yaml::parseFile($this->dir.$file); |
| 16 | + //var_dump($value); |
| 17 | + //array_push($classes, $value); |
| 18 | + //var_dump($classes); |
| 19 | + //echo $value['net\authorize\api\contract\v1\ANetApiRequestType']['properties']['merchantAuthentication']['type']."\n"; |
| 20 | + $key = key($value); |
| 21 | + $this->classes[$key] = $value[$key]; |
| 22 | + //break; |
| 23 | + } |
| 24 | + } |
| 25 | + } |
| 26 | + |
| 27 | + // public function getClass(string $classname, string $property){ |
| 28 | + |
| 29 | + // if(isset($this->classes[$classname]['properties'][$property]['type'])){ |
| 30 | + // return $this->classes[$classname]['properties'][$property]['type']; |
| 31 | + // } |
| 32 | + // else if ($property == "refId" || $property == "sessionToken" ){ |
| 33 | + // return 'string'; |
| 34 | + // } |
| 35 | + // else if ($property == "messages" ){ |
| 36 | + // return 'net\authorize\api\contract\v1\MessagesType'; |
| 37 | + // } |
| 38 | + // else{ |
| 39 | + // echo "Error finding in YAML - ".$classname." ".$property."\n"; |
| 40 | + // return 'string'; |
| 41 | + // } |
| 42 | + // // return $this->classes[$classname]['properties'][$property]['type']; |
| 43 | + // } |
| 44 | + |
| 45 | + public function getClass(string $class, string $property){ |
| 46 | + |
| 47 | + $obj = new MapperObj; |
| 48 | + |
| 49 | + |
| 50 | + if(isset($this->classes[$classname]['properties'][$property]['type'])){ |
| 51 | + $className = $this->classes[$class]['properties'][$property]['type']; |
| 52 | + if(substr( $classname, 0, 5 ) === "array"){ |
| 53 | + $classname = ltrim($classname, 'array<'); |
| 54 | + $classname = rtrim($classname, '>'); |
| 55 | + $obj->isArray = true; |
| 56 | + |
| 57 | + if(isset($this->classes[$classname]['properties'][$property]['xml_list']['entry_name'])){ |
| 58 | + // echo $file."\t\t\t\t\t\t\t\t\t"; |
| 59 | + // echo $propKey." :: ".$prop['serialized_name']." - ".$prop['xml_list']['entry_name']." - ".$prop['xml_list']['inline']; |
| 60 | + // echo "\n"; |
| 61 | + $obj->isInlineArray = $this->classes[$classname]['properties'][$property]['xml_list']['inline']; |
| 62 | + $obj->arrayEntryname = $this->classes[$classname]['properties'][$property]['xml_list']['entry_name']; |
| 63 | + } |
| 64 | + } |
| 65 | + $obj->className = $className; |
| 66 | + $obj->isCustomDefined = stripos($className, '\\') !== false; |
| 67 | + |
| 68 | + return $obj; |
| 69 | + } |
| 70 | + else if(get_parent_class($classname)){ |
| 71 | + return getClass(get_parent_class($classname), $property) |
| 72 | + } |
| 73 | + // else if ($property == "refId" || $property == "sessionToken" ){ |
| 74 | + // return 'string'; |
| 75 | + // } |
| 76 | + // else if ($property == "messages" ){ |
| 77 | + // return 'net\authorize\api\contract\v1\MessagesType'; |
| 78 | + // } |
| 79 | + else{ |
| 80 | + echo "Error finding in YAML - ".$classname." ".$property."\n"; |
| 81 | + $obj->className = 'string'; |
| 82 | + return $obj; |
| 83 | + } |
| 84 | + // return $this->classes[$classname]['properties'][$property]['type']; |
| 85 | + } |
| 86 | +} |
| 87 | +//echo $classes['net\authorize\api\contract\v1\ANetApiRequestType']['properties']['merchantAuthentication']['type']."\n"; |
| 88 | + |
| 89 | +//$value = Yaml::parseFile('/*.yaml'); |
| 90 | + |
| 91 | +?> |
0 commit comments