Skip to content

Commit

Permalink
Merge pull request #395 from giveforks/php74-support
Browse files Browse the repository at this point in the history
Updating generator to fix PHP74 related bug
  • Loading branch information
gnongsie authored Feb 10, 2021
2 parents bf28f6b + b6f5dd6 commit c584eed
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 7 deletions.
8 changes: 7 additions & 1 deletion scripts/appendJsonSerializeCode.pl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@
my $filepath = "lib/net/authorize/api/contract/v1/";
my $filename = "$filepath"."$_";
my $text = `cat $filename`;
my $sub = `cat scripts/appendJsonSerializeCode.txt`;
my $sub = "";

if ($text =~ /(?^pm:\nclass \w+ extends )/) {
$sub = `cat scripts/appendJsonSerializeSubClassCode.txt`;
} else {
$sub = `cat scripts/appendJsonSerializeCode.txt`;
}

$text =~ s|(.+)}|$1$sub|xms;

Expand Down
7 changes: 1 addition & 6 deletions scripts/appendJsonSerializeCode.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,7 @@
}
}
}
if (get_parent_class() == ""){
return $values;
}
else{
return array_merge(parent::jsonSerialize(), $values);
}
return $values;
}

}
31 changes: 31 additions & 0 deletions scripts/appendJsonSerializeSubClassCode.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Json Serialize Code
public function jsonSerialize(){
$values = array_filter((array)get_object_vars($this),
function ($val){
return !is_null($val);
});
$mapper = \net\authorize\util\Mapper::Instance();
foreach($values as $key => $value){
$classDetails = $mapper->getClass(get_class() , $key);
if (isset($value)){
if ($classDetails->className === 'Date'){
$dateTime = $value->format('Y-m-d');
$values[$key] = $dateTime;
}
else if ($classDetails->className === 'DateTime'){
$dateTime = $value->format('Y-m-d\TH:i:s\Z');
$values[$key] = $dateTime;
}
if (is_array($value)){
if (!$classDetails->isInlineArray){
$subKey = $classDetails->arrayEntryname;
$subArray = [$subKey => $value];
$values[$key] = $subArray;
}
}
}
}
return array_merge(parent::jsonSerialize(), $values);
}

}

0 comments on commit c584eed

Please sign in to comment.