Skip to content

Commit c584eed

Browse files
authored
Merge pull request #395 from giveforks/php74-support
Updating generator to fix PHP74 related bug
2 parents bf28f6b + b6f5dd6 commit c584eed

File tree

3 files changed

+39
-7
lines changed

3 files changed

+39
-7
lines changed

scripts/appendJsonSerializeCode.pl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,13 @@
1313
my $filepath = "lib/net/authorize/api/contract/v1/";
1414
my $filename = "$filepath"."$_";
1515
my $text = `cat $filename`;
16-
my $sub = `cat scripts/appendJsonSerializeCode.txt`;
16+
my $sub = "";
17+
18+
if ($text =~ /(?^pm:\nclass \w+ extends )/) {
19+
$sub = `cat scripts/appendJsonSerializeSubClassCode.txt`;
20+
} else {
21+
$sub = `cat scripts/appendJsonSerializeCode.txt`;
22+
}
1723

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

scripts/appendJsonSerializeCode.txt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,7 @@
2525
}
2626
}
2727
}
28-
if (get_parent_class() == ""){
29-
return $values;
30-
}
31-
else{
32-
return array_merge(parent::jsonSerialize(), $values);
33-
}
28+
return $values;
3429
}
3530

3631
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Json Serialize Code
2+
public function jsonSerialize(){
3+
$values = array_filter((array)get_object_vars($this),
4+
function ($val){
5+
return !is_null($val);
6+
});
7+
$mapper = \net\authorize\util\Mapper::Instance();
8+
foreach($values as $key => $value){
9+
$classDetails = $mapper->getClass(get_class() , $key);
10+
if (isset($value)){
11+
if ($classDetails->className === 'Date'){
12+
$dateTime = $value->format('Y-m-d');
13+
$values[$key] = $dateTime;
14+
}
15+
else if ($classDetails->className === 'DateTime'){
16+
$dateTime = $value->format('Y-m-d\TH:i:s\Z');
17+
$values[$key] = $dateTime;
18+
}
19+
if (is_array($value)){
20+
if (!$classDetails->isInlineArray){
21+
$subKey = $classDetails->arrayEntryname;
22+
$subArray = [$subKey => $value];
23+
$values[$key] = $subArray;
24+
}
25+
}
26+
}
27+
}
28+
return array_merge(parent::jsonSerialize(), $values);
29+
}
30+
31+
}

0 commit comments

Comments
 (0)