Skip to content

Commit

Permalink
some big refactoring for the soap client
Browse files Browse the repository at this point in the history
  • Loading branch information
goetas committed Sep 16, 2016
1 parent 7afbbc4 commit 43dfa1b
Show file tree
Hide file tree
Showing 17 changed files with 261 additions and 199 deletions.
12 changes: 1 addition & 11 deletions src/AbstractConverter.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
<?php
namespace GoetasWebservices\Xsd\XsdToPhp;

use GoetasWebservices\Xsd\XsdToPhp\Naming\NamingStrategy;
use GoetasWebservices\XML\WSDLReader\DefinitionsReader;
use GoetasWebservices\XML\XSDReader\Schema\Element\ElementSingle;
use GoetasWebservices\XML\XSDReader\Schema\Schema;
use GoetasWebservices\XML\XSDReader\Schema\Type\ComplexType;
use GoetasWebservices\XML\XSDReader\Schema\Type\SimpleType;
use GoetasWebservices\XML\XSDReader\Schema\Type\Type;
use GoetasWebservices\XML\XSDReader\SchemaReader;
use GoetasWebservices\Xsd\XsdToPhp\Naming\NamingStrategy;
use Psr\Log\LoggerAwareTrait;
use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;
Expand All @@ -27,14 +25,6 @@ abstract class AbstractConverter
'http://www.w3.org/XML/1998/namespace' => ''
);

protected $baseTypes = [
'string',
'float',
'boolean',
'date',
'integer',
'mixed'
];
/**
* @var \GoetasWebservices\Xsd\XsdToPhp\Naming\NamingStrategy
*/
Expand Down
4 changes: 2 additions & 2 deletions src/Command/Convert.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ protected function execute(InputInterface $input, OutputInterface $output)
}

foreach (['php', 'jms'] as $type) {
$converter = $this->container->get('goetas.xsd2php.converter.'.$type);
$converter = $this->container->get('goetas.xsd2php.converter.' . $type);
$items = $converter->convert($schemas);

$writer = $this->container->get('goetas.xsd2php.writer.'.$type);
$writer = $this->container->get('goetas.xsd2php.writer.' . $type);
$writer->write($items);
}
return count($items) ? 0 : 255;
Expand Down
77 changes: 37 additions & 40 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,47 +12,44 @@ public function getConfigTreeBuilder()
$rootNode = $treeBuilder->root('xsd2php');

$rootNode

->children()
->scalarNode('naming_strategy')
->defaultValue('short')
->cannotBeEmpty()
->end()
->scalarNode('path_generator')
->defaultValue('psr4')
->cannotBeEmpty()
->end()

->arrayNode('namespaces')->fixXmlConfig('namespace')
->cannotBeEmpty()->isRequired()
->requiresAtLeastOneElement()
->prototype('scalar')
->end()
->end()
->arrayNode('known_locations')->fixXmlConfig('known_location')
->prototype('scalar')
->end()
->end()
->arrayNode('destinations_php')->fixXmlConfig('destination')
->cannotBeEmpty()->isRequired()
->requiresAtLeastOneElement()
->prototype('scalar')
->end()
->end()
->arrayNode('destinations_jms')->fixXmlConfig('destination')
->cannotBeEmpty()->isRequired()
->requiresAtLeastOneElement()
->prototype('scalar')
->end()
->end()
->arrayNode('aliases')->fixXmlConfig('alias')
->prototype('array')
->prototype('scalar')
->end()
->end()
->end()
->end()
;
->scalarNode('naming_strategy')
->defaultValue('short')
->cannotBeEmpty()
->end()
->scalarNode('path_generator')
->defaultValue('psr4')
->cannotBeEmpty()
->end()
->arrayNode('namespaces')->fixXmlConfig('namespace')
->cannotBeEmpty()->isRequired()
->requiresAtLeastOneElement()
->prototype('scalar')
->end()
->end()
->arrayNode('known_locations')->fixXmlConfig('known_location')
->prototype('scalar')
->end()
->end()
->arrayNode('destinations_php')->fixXmlConfig('destination')
->cannotBeEmpty()->isRequired()
->requiresAtLeastOneElement()
->prototype('scalar')
->end()
->end()
->arrayNode('destinations_jms')->fixXmlConfig('destination')
->cannotBeEmpty()->isRequired()
->requiresAtLeastOneElement()
->prototype('scalar')
->end()
->end()
->arrayNode('aliases')->fixXmlConfig('alias')
->prototype('array')
->prototype('scalar')
->end()
->end()
->end()
->end();
return $treeBuilder;
}
}
2 changes: 1 addition & 1 deletion src/DependencyInjection/Xsd2PhpExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function load(array $configs, ContainerBuilder $container)


$schemaReader = $container->getDefinition('goetas.xsd2php.schema_reader');
foreach ($config['known_locations'] as $namespace => $location){
foreach ($config['known_locations'] as $namespace => $location) {
$schemaReader->addMethodCall('addKnownSchemaLocation', [$namespace, $location]);
}

Expand Down
4 changes: 2 additions & 2 deletions src/Jms/YamlConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

use Doctrine\Common\Inflector\Inflector;
use Exception;
use GoetasWebservices\Xsd\XsdToPhp\AbstractConverter;
use GoetasWebservices\Xsd\XsdToPhp\Naming\NamingStrategy;
use GoetasWebservices\XML\XSDReader\Schema\Attribute\AttributeContainer;
use GoetasWebservices\XML\XSDReader\Schema\Attribute\AttributeItem;
use GoetasWebservices\XML\XSDReader\Schema\Element\Element;
Expand All @@ -19,6 +17,8 @@
use GoetasWebservices\XML\XSDReader\Schema\Type\ComplexType;
use GoetasWebservices\XML\XSDReader\Schema\Type\SimpleType;
use GoetasWebservices\XML\XSDReader\Schema\Type\Type;
use GoetasWebservices\Xsd\XsdToPhp\AbstractConverter;
use GoetasWebservices\Xsd\XsdToPhp\Naming\NamingStrategy;

class YamlConverter extends AbstractConverter
{
Expand Down
21 changes: 19 additions & 2 deletions src/Naming/LongNamingStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,19 @@

class LongNamingStrategy implements NamingStrategy
{
protected $reservedWords = [
'int',
'float',
'bool',
'string',
'true',
'false',
'null',
'resource',
'object',
'mixed',
'numeric',
];

public function getTypeName(Type $type)
{
Expand All @@ -20,7 +33,11 @@ public function getAnonymousTypeName(Type $type, $parentName)

public function getItemName(Item $item)
{
return $this->classify($item->getName());
$name = $this->classify($item->getName());
if (in_array(strtolower($name), $this->reservedWords)) {
$name .= 'Xsd';
}
return $name;
}

public function getPropertyName($item)
Expand All @@ -32,4 +49,4 @@ private function classify($name)
{
return Inflector::classify(str_replace(".", " ", $name));
}
}
}
21 changes: 19 additions & 2 deletions src/Naming/ShortNamingStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,19 @@

class ShortNamingStrategy implements NamingStrategy
{
protected $reservedWords = [
'int',
'float',
'bool',
'string',
'true',
'false',
'null',
'resource',
'object',
'mixed',
'numeric',
];

public function getTypeName(Type $type)
{
Expand All @@ -29,11 +42,15 @@ public function getPropertyName($item)

public function getItemName(Item $item)
{
return $this->classify($item->getName());
$name = $this->classify($item->getName());
if (in_array(strtolower($name), $this->reservedWords)) {
$name .= 'Xsd';
}
return $name;
}

private function classify($name)
{
return Inflector::classify(str_replace(".", " ", $name));
}
}
}
5 changes: 1 addition & 4 deletions src/PathGenerator/Psr4PathGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ public function setTargets($namespaces)

foreach ($this->namespaces as $namespace => $dir) {
if (!is_dir($dir)) {
throw new PathGeneratorException("The folder '$dir' does not exist.");
}
if (!is_writable($dir)) {
throw new PathGeneratorException("The folder '$dir' is not writable.");
mkdir($dir, 0777, true);
}
}
}
Expand Down
Loading

0 comments on commit 43dfa1b

Please sign in to comment.