forked from wsdl2phpgenerator/wsdl2phpgenerator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate.php
185 lines (163 loc) · 6.14 KB
/
generate.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
<?php
/**
* @package Wsdl2PhpGenerator
*/
/**
* Gettext should not be required - Thanks jeichhor
*/
if (!function_exists("_"))
{
function _($str)
{
return gettext($str);
}
}
if (!function_exists("gettext"))
{
function gettext($str)
{
return $str;
}
}
/**
* Include the needed files
*/
require_once dirname(__FILE__).'/lib/cli/Cli.php';
require_once dirname(__FILE__).'/lib/config/FileConfig.php';
require_once dirname(__FILE__).'/src/Generator.php';
// Try to read the config file if any
try
{
$config = new FileConfig(dirname(__FILE__).'/conf/settings.conf');
$locale = $config->get('language');
$domain = 'messages';
$lcDir = 'LC_MESSAGES';
$path = 'conf/translations';
$loc = substr($locale, 0, 5);
$file = $path.'/'.$loc.'/'.$lcDir.'/'.$domain.'.mo';
if (file_exists($file) == false)
{
throw new Exception('The selected language file ('.$file.') does not exist!');
}
bindtextdomain($domain, $path);
textdomain($domain);
setlocale(LC_ALL, $locale);
}
catch (Exception $e)
{
// This should be the no file exception, then use the default settings
}
// Start
$cli = new Cli('wsdl2php', '[OPTIONS] -i wsdlfile -o directory', '1.5.2');
$cli->addFlag('-e', _('If all classes should be guarded with if(!class_exists) statements'), true, false);
$cli->addFlag('-t', _('If no type constructor should be generated'), true, false);
$cli->addFlag('-s', _('If the output should be a single file'), true, false);
$cli->addFlag('-v', _('If the output to the console should be verbose'), true, false);
$cli->addFlag('-i', _('The input wsdl file'), false, true);
$cli->addFlag('-o', _('The output directory or file if -s is used (in that case, .php will be appened to file name)'), false, true);
$cli->addFlag('-n', _('Use namespace with the name'), false, false);
$cli->addFlag('-c', _("A comma separated list of classnames to generate.\nIf this is used only classes that exist in the list will be generated.\nIf the service is not in this list and the -s flag is used\nthe filename will be the name of the first class that is generated"), false, false);
$cli->addFlag('-p', _('The prefix to use for the generated classes'), false, false);
$cli->addFlag('-q', _('The suffix to use for the generated classes'), false, false);
$cli->addFlag('--singleElementArrays', _('Adds the option to use single element arrays to the client'), true, false);
$cli->addFlag('--xsiArrayType', _('Adds the option to use xsi arrays to the client'), true, false);
$cli->addFlag('--waitOneWayCalls', _('Adds the option to use wait one way calls to the client'), true, false);
$cli->addFlag('--cacheNone', _('Adds the option to not cache the wsdl to the client'), true, false);
$cli->addFlag('--cacheDisk', _('Adds the option to cache the wsdl on disk to the client'), true, false);
$cli->addFlag('--cacheMemory', _('Adds the option to cache the wsdl in memory to the client'), true, false);
$cli->addFlag('--cacheBoth', _('Adds the option to cache the wsdl in memory and on disk to the client'), true, false);
$cli->addFlag('--gzip', _('Adds the option to compress the wsdl with gzip to the client'), true, false);
$cli->addFlag('--sharedTypes', _('Adds the option to use share types'), true, false);
$cli->addFlag('-h', _('Show this help'), true, false);
$cli->addAlias('-e', '--classExists');
$cli->addAlias('-e', '--exists');
$cli->addAlias('-t', '--noTypeConstructor');
$cli->addAlias('-s', '--singleFile');
$cli->addAlias('-v', '--verbose');
$cli->addAlias('-i', '--input');
$cli->addAlias('-o', '--output');
$cli->addAlias('-n', '--namespace');
$cli->addAlias('-c', '--classes');
$cli->addAlias('-c', '--classNames');
$cli->addAlias('-c', '--classList');
$cli->addAlias('-p', '--prefix');
$cli->addAlias('-q', '--suffix');
$cli->addAlias('-h', '--help');
$cli->addAlias('-h', '--h');
$cli->validate($argv);
$singleFile = $cli->getValue('-s');
$classNames = trim($cli->getValue('-c'));
if ($singleFile && strlen($classNames) > 0)
{
// Print different messages based on if more than one class is requested for generation
if (strpos($classNames, ',') !== false)
{
print printf(_('You have selected to only generate some of the classes in the wsdl(%s) and to save them in one file. Continue? [Y/n]'), $classNames).PHP_EOL;
}
else
{
print _('You have selected to only generate one class and save it to a single file. If you have selected the service class and outputs this file to a directory where you previosly have generated the classes the file will be overwritten. Continue? [Y/n]').PHP_EOL;
}
//TODO: Refactor this to cli class?
// Force the user to supply a valid input
while(true)
{
$cmd = readline(null); // Reads from the standard input
if (in_array($cmd, array('', 'y', 'Y', 'yes')))
{
break; // Continue
}
else if (in_array($cmd, array('n', 'no', 'N')))
{
exit; // Terminate
}
print _('Please select yes or no.').PHP_EOL;
}
}
$classExists = $cli->getValue('-e');
$verbose = $cli->getValue('-v');
$noTypeConstructor = $cli->getValue('-t');
$inputFile = $cli->getValue('-i');
$outputDir = $cli->getValue('-o');
$namespaceName = $cli->getValue('-n');
$prefix = $cli->getValue('-p');
$suffix = $cli->getValue('-q');
$sharedTypes = $cli->getValue('--sharedTypes');
$optionsArray = array();
if ($cli->getValue('--singleElementArrays'))
{
$optionsArray[] = 'SOAP_SINGLE_ELEMENT_ARRAYS';
}
if ($cli->getValue('--xsiArrayType'))
{
$optionsArray[] = 'SOAP_USE_XSI_ARRAY_TYPE';
}
if ($cli->getValue('--waitOneWayCalls'))
{
$optionsArray[] = 'SOAP_WAIT_ONE_WAY_CALLS';
}
$wsdlCache = '';
if ($cli->getValue('--cacheNone'))
{
$wsdlCache = 'WSDL_CACHE_NONE';
}
else if ($cli->getValue('--cacheDisk'))
{
$wsdlCache = 'WSDL_CACHE_DISK';
}
else if ($cli->getValue('--cacheMemory'))
{
$wsdlCache = 'WSDL_CACHE_MEMORY';
}
else if ($cli->getValue('--cacheBoth'))
{
$wsdlCache = 'WSDL_CACHE_BOTH';
}
$gzip = '';
if ($cli->getValue('--gzip'))
{
$gzip = 'SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP';
}
$config = new Config($inputFile, $outputDir, $verbose, $singleFile, $classExists, $noTypeConstructor, $namespaceName, $optionsArray, $wsdlCache, $gzip, $classNames, $prefix, $suffix);
$generator = Generator::instance();
$generator->generate($config);