Skip to content

Commit

Permalink
Fix issue #139 by adding an option to use another xsd-types.yml file
Browse files Browse the repository at this point in the history
  • Loading branch information
Valérian GIRARD committed Jul 20, 2018
1 parent bf974d1 commit 92642d3
Show file tree
Hide file tree
Showing 12 changed files with 77 additions and 9 deletions.
2 changes: 2 additions & 0 deletions src/Command/GeneratePackageCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ protected function configure()
->addOption('enums-folder', null, InputOption::VALUE_OPTIONAL, 'Enumerations folder name (default: EnumType)')
->addOption('services-folder', null, InputOption::VALUE_OPTIONAL, 'Services class folder name (default: ServiceType)')
->addOption('src-dirname', null, InputOption::VALUE_OPTIONAL, 'Source directory subfolder oof destination directory (default: src)')
->addOption('xsd-types-path', null, InputOption::VALUE_OPTIONAL, 'Path to the xsd types configuration file to load')
->addOption(self::GENERATOR_OPTIONS_CONFIG_OPTION, null, InputOption::VALUE_OPTIONAL, 'Path to the generator\'s configuration file to load');
}
/**
Expand Down Expand Up @@ -145,6 +146,7 @@ protected function getPackageGenerationCommandLineOptions()
'suffix' => 'Suffix',
'urlorpath' => 'Origin',
'validation' => 'Validation',
'xsd-types-path' => 'XsdTypePath'
];
}
/**
Expand Down
19 changes: 19 additions & 0 deletions src/ConfigurationReader/GeneratorOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class GeneratorOptions extends AbstractYamlReader implements \JsonSerializable
const VALIDATION = 'validation';
const SCHEMAS_SAVE = 'schemas_save';
const SCHEMAS_FOLDER = 'schemas_folder';
const XSD_TYPES_PATH = 'xsd_types_path';
/**
* Generator's options
* @var array
Expand Down Expand Up @@ -724,6 +725,24 @@ public function setSchemasFolder($schemasFolder)
{
return $this->setOptionValue(self::SCHEMAS_FOLDER, $schemasFolder);
}
/**
* Get xsd type path option value
* @return string
*/
public function getXsdTypesPath()
{
return $this->getOptionValue(self::XSD_TYPES_PATH);
}
/**
* Set xsd type path option value
* @throws \InvalidArgumentException
* @param string $xsdTypePath
* @return GeneratorOptions
*/
public function setXsdTypePath($xsdTypePath)
{
return $this->setOptionValue(self::XSD_TYPES_PATH, $xsdTypePath);
}
/**
* @return string[]
*/
Expand Down
12 changes: 6 additions & 6 deletions src/File/AbstractModelFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -476,8 +476,8 @@ public function getStructAttributeTypeAsPhpType(StructAttributeModel $attribute
{
$attribute = $this->getStructAttribute($attribute);
$attributeType = $this->getStructAttributeType($attribute, true);
if (XsdTypes::instance()->isXsd($attributeType)) {
$attributeType = self::getPhpType($attributeType);
if (XsdTypes::instance($this->getGenerator()->getOptionXsdTypesPath())->isXsd($attributeType)) {
$attributeType = self::getPhpType($attributeType, $this->getGenerator()->getOptionXsdTypesPath());
}
return $attributeType;
}
Expand All @@ -488,9 +488,9 @@ public function getStructAttributeTypeAsPhpType(StructAttributeModel $attribute
* @param mixed $fallback
* @return mixed
*/
public static function getValidType($type, $fallback = null)
public static function getValidType($type, $xsdTypesPath = null, $fallback = null)
{
return XsdTypes::instance()->isXsd(str_replace('[]', '', $type)) ? $fallback : $type;
return XsdTypes::instance($xsdTypesPath)->isXsd(str_replace('[]', '', $type)) ? $fallback : $type;
}
/**
* See http://php.net/manual/fr/language.oop5.typehinting.php for these cases
Expand All @@ -499,8 +499,8 @@ public static function getValidType($type, $fallback = null)
* @param mixed $fallback
* @return mixed
*/
public static function getPhpType($type, $fallback = self::TYPE_STRING)
public static function getPhpType($type, $xsdTypesPath = null, $fallback = self::TYPE_STRING)
{
return XsdTypes::instance()->isXsd(str_replace('[]', '', $type)) ? XsdTypes::instance()->phpType($type) : $fallback;
return XsdTypes::instance($xsdTypesPath)->isXsd(str_replace('[]', '', $type)) ? XsdTypes::instance($xsdTypesPath)->phpType($type) : $fallback;
}
}
2 changes: 1 addition & 1 deletion src/File/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ protected function getTypeFromName($name)
$type = $model->getPackagedName(true);
}
}
return self::getValidType($type);
return self::getValidType($type, $this->getGenerator()->getOptionXsdTypesPath());
}
/**
* @param string $soapHeaderName
Expand Down
2 changes: 1 addition & 1 deletion src/File/Struct.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ protected function getStructMethodParameter(StructAttributeModel $attribute, $lo
*/
protected function getStructMethodParameterType(StructAttributeModel $attribute, $returnArrayType = true)
{
return self::getValidType($this->getStructAttributeTypeHint($attribute, $returnArrayType), null);
return self::getValidType($this->getStructAttributeTypeHint($attribute, $returnArrayType), $this->getGenerator()->getOptionXsdTypesPath(), null);
}
/**
* @param MethodContainer $methods
Expand Down
18 changes: 18 additions & 0 deletions src/Generator/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -824,6 +824,24 @@ public function setOptionSchemasFolder($optionSchemasFolder)
$this->options->setSchemasFolder($optionSchemasFolder);
return $this;
}
/**
* Gets the optionXsdTypesPath value
* @return string
*/
public function getOptionXsdTypesPath()
{
return $this->options->getXsdTypesPath();
}
/**
* Sets the optionXsdTypesPath value
* @param string $xsdTypesPath
* @return Generator
*/
public function setOptionXsdTypesPath($xsdTypesPath)
{
$this->options->setXsdTypesPath($xsdTypesPath);
return $this;
}
/**
* Gets the WSDL
* @return Wsdl|null
Expand Down
3 changes: 3 additions & 0 deletions src/resources/config/generator_options.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,6 @@ schemas_save:
schemas_folder:
default: 'wsdl'
values: ''
xsd_types_path:
default: ''
values: ''
2 changes: 2 additions & 0 deletions tests/ConfigurationReader/GeneratorOptionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,7 @@ public function testToArray()
'services_folder' => 'ServiceType',
'schemas_save' => false,
'schemas_folder' => 'wsdl',
'xsd_types_path' => '',
], self::optionsInstance()->toArray());
}
/**
Expand Down Expand Up @@ -723,6 +724,7 @@ public function testJsonSerialize()
'services_folder' => 'ServiceType',
'schemas_save' => false,
'schemas_folder' => 'wsdl',
'xsd_types_path' => '',
], self::optionsInstance()->jsonSerialize());
}
}
17 changes: 17 additions & 0 deletions tests/Generator/GeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,23 @@ public function testSetSchemasFolder()
$instance->setOptionSchemasFolder('wsdl');

$this->assertSame('wsdl', $instance->getOptionSchemasFolder());
}
/**
*
*/
public function testSetOptionXsdTypesPath()
{
$instance = self::localInstance();
$instance->setOptionXsdTypesPath('/some/path/file.yml');

$this->assertSame('/some/path/file.yml', $instance->getOptionXsdTypesPath());
}
/**
*
*/
public function testGetOptionXsdTypesPath()
{
$this->assertEmpty(self::localInstance()->getOptionXsdTypesPath());
}
/**
*
Expand Down
3 changes: 2 additions & 1 deletion tests/resources/generated/json_serialized.json
Original file line number Diff line number Diff line change
Expand Up @@ -3311,6 +3311,7 @@
"enums_folder": "EnumType",
"services_folder": "ServiceType",
"schemas_save": false,
"schemas_folder": "wsdl"
"schemas_folder": "wsdl",
"xsd_types_path": ""
}
}
3 changes: 3 additions & 0 deletions tests/resources/generator_options.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,7 @@ schemas_save:
values: [ true, false ]
schemas_folder:
default: 'wsdl'
values: ''
xsd_types_path:
default: ''
values: ''
3 changes: 3 additions & 0 deletions wsdltophp.yml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,6 @@ schemas_save:
schemas_folder:
default: 'wsdl'
values: ''
xsd_types_path:
default: ''
values: ''

0 comments on commit 92642d3

Please sign in to comment.