Skip to content

Commit 998a28c

Browse files
committed
Add masterCodeAppender using perl
1 parent e52cc3f commit 998a28c

6 files changed

Lines changed: 233 additions & 0 deletions

File tree

scripts/appendJsonSeralizeCode.pl

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/perl
2+
use strict;
3+
use warnings;
4+
5+
#my $text = `cat ARBGetSubscriptionRequest.php`;
6+
#my $sub = `cat appendSetCode.txt`;
7+
#$text =~ s|(.+)}|$1$sub|xms;
8+
#print 'Result : '.$text."\n";
9+
10+
11+
while (<>) {
12+
chomp;
13+
my $filepath = "../lib/net/authorize/api/contract/v1/"
14+
my $filename = "$filepath"."$_";
15+
my $text = `cat $filename`;
16+
my $sub = `cat appendJsonSeralizeCode.txt`;
17+
18+
$text =~ s|(.+)}|$1$sub|xms;
19+
20+
open(my $fh, '>', "$filename");
21+
print $fh $text;
22+
close $fh;
23+
# print 'Result : '.$text."\n";
24+
}
25+
#unless(mkdir 'backup') {
26+
# die "Unable to create directory backup\n";
27+
# }
28+
#open(my $fh, '>', 'backup/ARBGetSubscriptionRequest copy2.php');
29+
#print $fh "My first report generated by perl\n";
30+
#close $fh;

scripts/appendJsonSeralizeCode.txt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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+
foreach($values as $key => $value){
8+
if (isset($value) & &is_array($value)){
9+
$subKey = str_replace("Type", "", lcfirst((new ReflectionClass($value[0]))->getShortName()));
10+
$subArray = [$subKey => $value];
11+
$values[$key] = $subArray;
12+
}
13+
}
14+
if (get_parent_class() == ""){
15+
return $values;
16+
}
17+
else{
18+
return array_merge(parent::jsonSerialize() , $values);
19+
}
20+
}
21+
22+
}

scripts/appendSetCode.pl

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/perl
2+
use strict;
3+
use warnings;
4+
5+
#my $text = `cat ARBGetSubscriptionRequest.php`;
6+
#my $sub = `cat appendSetCode.txt`;
7+
#$text =~ s|(.+)}|$1$sub|xms;
8+
#print 'Result : '.$text."\n";
9+
10+
11+
while (<>) {
12+
chomp;
13+
my $filepath = "../lib/net/authorize/api/contract/v1/"
14+
my $filename = "$filepath"."$_";
15+
my $text = `cat $filename`;
16+
my $sub = `cat appendSetCode.txt`;
17+
18+
$text =~ s|(.+)}|$1$sub|xms;
19+
20+
open(my $fh, '>', "$filename");
21+
print $fh $text;
22+
close $fh;
23+
# print 'Result : '.$text."\n";
24+
}
25+
#unless(mkdir 'backup') {
26+
# die "Unable to create directory backup\n";
27+
# }
28+
#open(my $fh, '>', 'backup/ARBGetSubscriptionRequest copy2.php');
29+
#print $fh "My first report generated by perl\n";
30+
#close $fh;

scripts/appendSetCode.txt

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Json Set Code
2+
public function set($data)
3+
{
4+
foreach($data AS $key => $value) {
5+
$isarray = false;
6+
$classname = (new netauthorizeapicontractv1Mapper)->getClass(get_class() , $key);
7+
if (substr($classname, 0, 5) === "array") {
8+
$classname = ltrim($classname, 'array<');
9+
$classname = rtrim($classname, '>');
10+
$isarray = true;
11+
}
12+
if ($isarray) {
13+
if ($classname != "string") {
14+
foreach($value AS $keyChild => $valueChild) {
15+
$type = new $classname;
16+
$type->set($valueChild);
17+
$this->{'addTo' . $key}($type);
18+
}
19+
}
20+
else {
21+
foreach($value AS $keyChild => $valueChild) {
22+
$this->{'addTo' . $key}($valueChild);
23+
}
24+
}
25+
}
26+
else {
27+
if ($classname != "string") {
28+
$type = new $classname;
29+
$type->set($value);
30+
$this->{'set' . $key}($type);
31+
}
32+
else {
33+
$this->{'set' . $key}($value);
34+
}
35+
}
36+
}
37+
}
38+
39+
}

scripts/backup.pl

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/perl
2+
use strict;
3+
use warnings;
4+
use File::Path;
5+
6+
#my $text = `cat ARBGetSubscriptionRequest.php`;
7+
#my $sub = `cat appendSetCode.txt`;
8+
#$text =~ s|(.+)}|$1$sub|xms;
9+
#print 'Result : '.$text."\n";
10+
11+
#mkdir 'backup';
12+
while (<>) {
13+
chomp;
14+
my $filepath = "../lib/net/authorize/api/contract/";
15+
my $filename = $filepath."v1/".$_;
16+
my $text = `cat $filename`;
17+
# print $filename;
18+
my $backupdir = "$filepath"."backup/$_";
19+
$backupdir =~ s/(.*)\/.*$/$1/;
20+
mkpath($backupdir) unless -d $backupdir;
21+
open(my $fh, '>', "$filepath"."backup/$_");
22+
print $fh $text;
23+
close $fh;
24+
# print 'Result : '.$text."\n";
25+
}
26+
#unless(mkdir 'backup') {
27+
# die "Unable to create directory backup\n";
28+
# }
29+
#open(my $fh, '>', 'backup/ARBGetSubscriptionRequest copy2.php');
30+
#print $fh "My first report generated by perl\n";
31+
#close $fh;

scripts/masterAppender.sh

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#!/bin/bash
2+
#sed -i "/ARBGetSubscriptionRequest/,/^}/s%^}%\t//JsonSerialize code appended\n
3+
#}\n
4+
#test\n
5+
#entry%" "ARBGetSubscriptionRequest.php"
6+
7+
#sed -E "/ARBGetSubscriptionRequest/,/^}/s%^}%s\t//777 code appended[\n] s /\
8+
#/}%" "ARBGetSubscriptionRequest.php"
9+
10+
11+
#perl -p -w -e "/ARBGetSubscriptionRequest/,/^}/s%^}%s\t//777 code appended[\n] s /\
12+
#/}%" "ARBGetSubscriptionRequest.php"
13+
#
14+
#file='ARBGetSubscriptionRequest.php'
15+
#echo $file;
16+
#perl -p -w -e "s|(.+)}|$1KKM|xms;" $file
17+
#
18+
#perl - $ <<'__HERE__'
19+
#my $text = `cat ARBGetSubscriptionRequest.php`;
20+
#$text =~ s|(.+)}|$1$sub|xms;
21+
#my $sub = `cat appendSetCode.txt`;
22+
#print 'Result : '.$sub."\n";
23+
#__HERE__
24+
#$line =~ s/\}(\s*)$/:$1/;
25+
#perl test.pl requestList.txt
26+
#
27+
##!/bin/bash
28+
29+
echo "Starting appending seralization code `date`"
30+
31+
#ls *.php | grep -i -e "request\.php"> requestList.txt
32+
#ls *.php | grep -i -e "response\.php" > responseList.txt
33+
# ls *.php | grep -i -e "type\.php" | grep -i -v "ANetApi" > typeList.txt
34+
#ls *.php | grep -i -e "type\.php" > typeList.txt
35+
#find . -print | grep -i -e "type\.php" > typeList.txt
36+
#find -print | grep -i -e "type\.php" | cut -c 3- > typeList.txt
37+
38+
# List filenames with request, response and type and remove the file path upto v1 i.e. 38 characters
39+
find ../lib/net/authorize/api/contract/v1 -print | grep -i -e "request\.php" | cut -c 38- > requestList.txt
40+
find ../lib/net/authorize/api/contract/v1 -print | grep -i -e "response\.php" | cut -c 38- > responseList.txt
41+
find ../lib/net/authorize/api/contract/v1 -print | grep -i -e "type\.php" | cut -c 38- > typeList.txt
42+
43+
#mkdir -p ../lib/net/authorize/api/contract/v1/backup
44+
45+
#appendJsonSeralizeCode=`cat appendJsonSeralizeCode.txt`
46+
#appendSetCode=`cat appendSetCode.txt`
47+
48+
echo "Taking backup of Types"
49+
perl backup.pl typeList.txt
50+
echo "Appending JsonSerialize code to Types"
51+
perl appendJsonSeralizeCode.pl typeList.txt
52+
echo "Appending Set code to Types"
53+
perl appendSetCode.pl typeList.txt
54+
55+
56+
echo "Taking backup of Requests"
57+
perl backup.pl requestList.txt
58+
echo "Appending JsonSerialize code to Requests"
59+
perl appendJsonSeralizeCode.pl requestList.txt
60+
#echo "Appending Set code to Requests"
61+
#perl appendSetCode.pl requestList.txt
62+
63+
echo "Taking backup of Responses"
64+
perl backup.pl responseList.txt
65+
#echo "Appending JsonSerialize code to Responses"
66+
#perl appendJsonSeralizeCode.pl responseList.txt
67+
echo "Appending Set code to Responses"
68+
perl appendSetCode.pl responseList.txt
69+
70+
echo "Done Phase 1"
71+
72+
#list="typeList.txt"
73+
#while read -r filename
74+
#do
75+
# filename=$(echo "$filename" | sed -e "s/^\.\///g")
76+
# echo "Appending implements JsonSerializable to - $filename"
77+
# sed -i '/^class/ s/$/ implements \\JsonSerializable/' "$filename"
78+
#
79+
#done < "$list"
80+
81+

0 commit comments

Comments
 (0)