Skip to content

Commit

Permalink
Updated code style to resemble PSR2 as closely as possible.
Browse files Browse the repository at this point in the history
Current exceptions:
- Files both declare classes and have side effects (includes)
- Classes are not in a namespace
- Lines contains more than 120 chars
  • Loading branch information
kasperg committed Mar 22, 2013
1 parent 20290be commit ce38767
Show file tree
Hide file tree
Showing 39 changed files with 4,383 additions and 4,656 deletions.
164 changes: 70 additions & 94 deletions generate.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -6,54 +6,50 @@
/** /**
* Gettext should not be required - Thanks jeichhor * Gettext should not be required - Thanks jeichhor
*/ */
if (!function_exists("_")) if (!function_exists("_")) {
{ public
function _($str) function _($str)
{ {
return gettext($str); return gettext($str);
} }
} }


if (!function_exists("gettext")) if (!function_exists("gettext")) {
{ public
function gettext($str) function gettext($str)
{ {
return $str; return $str;
} }
} }


/** /**
* Include the needed files * Include the needed files
*/ */
require_once dirname(__FILE__).'/lib/cli/Cli.php'; require_once dirname(__FILE__) . '/lib/cli/Cli.php';
require_once dirname(__FILE__).'/lib/config/FileConfig.php'; require_once dirname(__FILE__) . '/lib/config/FileConfig.php';


require_once dirname(__FILE__).'/src/Generator.php'; require_once dirname(__FILE__) . '/src/Generator.php';


// Try to read the config file if any // Try to read the config file if any
try try {
{ $config = new FileConfig(dirname(__FILE__) . '/conf/settings.conf');
$config = new FileConfig(dirname(__FILE__).'/conf/settings.conf'); $locale = $config->get('language');
$locale = $config->get('language');

$domain = 'messages';
$domain = 'messages'; $lcDir = 'LC_MESSAGES';
$lcDir = 'LC_MESSAGES'; $path = 'conf/translations';
$path = 'conf/translations'; $loc = substr($locale, 0, 5);
$loc = substr($locale, 0, 5); $file = $path . '/' . $loc . '/' . $lcDir . '/' . $domain . '.mo';
$file = $path.'/'.$loc.'/'.$lcDir.'/'.$domain.'.mo';

if (file_exists($file) == false) {
if (file_exists($file) == false) throw new Exception('The selected language file (' . $file . ') does not exist!');
{ }
throw new Exception('The selected language file ('.$file.') does not exist!');
} bindtextdomain($domain, $path);

textdomain($domain);
bindtextdomain($domain, $path); setlocale(LC_ALL, $locale);
textdomain($domain); } catch (Exception $e) {
setlocale(LC_ALL, $locale); // This should be the no file exception, then use the default settings
}
catch (Exception $e)
{
// This should be the no file exception, then use the default settings
} }


// Start // Start
Expand Down Expand Up @@ -103,36 +99,28 @@ function gettext($str)
$singleFile = $cli->getValue('-s'); $singleFile = $cli->getValue('-s');
$classNames = trim($cli->getValue('-c')); $classNames = trim($cli->getValue('-c'));


if ($singleFile && strlen($classNames) > 0) if ($singleFile && strlen($classNames) > 0) {
{ // Print different messages based on if more than one class is requested for generation
// Print different messages based on if more than one class is requested for generation if (strpos($classNames, ',') !== false) {
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 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; 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;
}
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; //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
} elseif (in_array($cmd, array('n', 'no', 'N'))) {
exit; // Terminate
}

print _('Please select yes or no.') . PHP_EOL;
}
} }


$classExists = $cli->getValue('-e'); $classExists = $cli->getValue('-e');
Expand All @@ -149,43 +137,31 @@ function gettext($str)
$noIncludes = $cli->getValue('--noIncludes'); $noIncludes = $cli->getValue('--noIncludes');


$optionsArray = array(); $optionsArray = array();
if ($cli->getValue('--singleElementArrays')) if ($cli->getValue('--singleElementArrays')) {
{ $optionsArray[] = 'SOAP_SINGLE_ELEMENT_ARRAYS';
$optionsArray[] = 'SOAP_SINGLE_ELEMENT_ARRAYS';
} }
if ($cli->getValue('--xsiArrayType')) if ($cli->getValue('--xsiArrayType')) {
{ $optionsArray[] = 'SOAP_USE_XSI_ARRAY_TYPE';
$optionsArray[] = 'SOAP_USE_XSI_ARRAY_TYPE';
} }
if ($cli->getValue('--waitOneWayCalls')) if ($cli->getValue('--waitOneWayCalls')) {
{ $optionsArray[] = 'SOAP_WAIT_ONE_WAY_CALLS';
$optionsArray[] = 'SOAP_WAIT_ONE_WAY_CALLS';
} }
$wsdlCache = ''; $wsdlCache = '';
if ($cli->getValue('--cacheNone')) if ($cli->getValue('--cacheNone')) {
{ $wsdlCache = 'WSDL_CACHE_NONE';
$wsdlCache = 'WSDL_CACHE_NONE'; } elseif ($cli->getValue('--cacheDisk')) {
} $wsdlCache = 'WSDL_CACHE_DISK';
else if ($cli->getValue('--cacheDisk')) } elseif ($cli->getValue('--cacheMemory')) {
{ $wsdlCache = 'WSDL_CACHE_MEMORY';
$wsdlCache = 'WSDL_CACHE_DISK'; } elseif ($cli->getValue('--cacheBoth')) {
} $wsdlCache = 'WSDL_CACHE_BOTH';
else if ($cli->getValue('--cacheMemory'))
{
$wsdlCache = 'WSDL_CACHE_MEMORY';
}
else if ($cli->getValue('--cacheBoth'))
{
$wsdlCache = 'WSDL_CACHE_BOTH';
} }
$gzip = ''; $gzip = '';
if ($cli->getValue('--gzip')) if ($cli->getValue('--gzip')) {
{ $gzip = 'SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP';
$gzip = 'SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP';
} }


$config = new Config($inputFile, $outputDir, $verbose, $singleFile, $classExists, $noTypeConstructor, $namespaceName, $optionsArray, $wsdlCache, $gzip, $classNames, $prefix, $suffix, $sharedTypes, $createAccessors, $constructorDefaultsToNull, $noIncludes); $config = new Config($inputFile, $outputDir, $verbose, $singleFile, $classExists, $noTypeConstructor, $namespaceName, $optionsArray, $wsdlCache, $gzip, $classNames, $prefix, $suffix, $sharedTypes, $createAccessors, $constructorDefaultsToNull, $noIncludes);


$generator = Generator::instance(); $generator = Generator::instance();
$generator->generate($config); $generator->generate($config);

Loading

0 comments on commit ce38767

Please sign in to comment.