From b0789871074f954c5c3ee0197fd972bdc5061476 Mon Sep 17 00:00:00 2001 From: Vladimir Belozyorov Date: Thu, 21 Jul 2016 12:01:35 +0300 Subject: [PATCH 1/2] AccuratePropsNamingStrategies --- .../LongAccuratePropsNamingStrategy.php | 35 +++++++++++++++++ .../ShortAccuratePropsNamingStrategy.php | 39 +++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 lib/Naming/LongAccuratePropsNamingStrategy.php create mode 100644 lib/Naming/ShortAccuratePropsNamingStrategy.php diff --git a/lib/Naming/LongAccuratePropsNamingStrategy.php b/lib/Naming/LongAccuratePropsNamingStrategy.php new file mode 100644 index 0000000..533dbfe --- /dev/null +++ b/lib/Naming/LongAccuratePropsNamingStrategy.php @@ -0,0 +1,35 @@ +classify($type->getName()) . "Type"; + } + + public function getAnonymousTypeName(Type $type, $parentName) + { + return $this->classify($parentName) . "AnonymousType"; + } + + public function getItemName(Item $item) + { + return $this->classify($item->getName()); + } + + public function getPropertyName($item) + { + return $item->getName(); + } + + private function classify($name) + { + return Inflector::classify(str_replace(".", " ", $name)); + } +} \ No newline at end of file diff --git a/lib/Naming/ShortAccuratePropsNamingStrategy.php b/lib/Naming/ShortAccuratePropsNamingStrategy.php new file mode 100644 index 0000000..ddce961 --- /dev/null +++ b/lib/Naming/ShortAccuratePropsNamingStrategy.php @@ -0,0 +1,39 @@ +classify($type->getName()); + if ($name && substr($name, -4) !== 'Type') { + $name .= "Type"; + } + return $name; + } + + public function getAnonymousTypeName(Type $type, $parentName) + { + return $this->classify($parentName) . "AType"; + } + + public function getPropertyName($item) + { + return $item->getName(); + } + + public function getItemName(Item $item) + { + return $this->classify($item->getName()); + } + + private function classify($name) + { + return Inflector::classify(str_replace(".", " ", $name)); + } +} \ No newline at end of file From 223a8468f0dc3941e9ab4ee854cecd7329f18f11 Mon Sep 17 00:00:00 2001 From: Vladimir Belozyorov Date: Thu, 21 Jul 2016 12:05:48 +0300 Subject: [PATCH 2/2] AccuratePropsNamingStrategies added to command --- lib/Command/AbstractConvert.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/Command/AbstractConvert.php b/lib/Command/AbstractConvert.php index 4360ffa..5dc956c 100644 --- a/lib/Command/AbstractConvert.php +++ b/lib/Command/AbstractConvert.php @@ -3,9 +3,7 @@ use Exception; use Goetas\Xsd\XsdToPhp\AbstractConverter; -use Goetas\Xsd\XsdToPhp\Naming\LongNamingStrategy; -use Goetas\Xsd\XsdToPhp\Naming\NamingStrategy; -use Goetas\Xsd\XsdToPhp\Naming\ShortNamingStrategy; +use Goetas\Xsd\XsdToPhp\Naming; use GoetasWebservices\XML\XSDReader\SchemaReader; use Symfony\Component\Console; use Symfony\Component\Console\Input\InputArgument; @@ -32,7 +30,7 @@ protected function configure() /** */ - protected abstract function getConverterter(NamingStrategy $naming); + protected abstract function getConverterter(Naming\NamingStrategy $naming); /** * @@ -53,9 +51,13 @@ protected function execute(Console\Input\InputInterface $input, Console\Output\O } if ($input->getOption('naming-strategy') == 'short') { - $naming = new ShortNamingStrategy(); + $naming = new Naming\ShortNamingStrategy(); } elseif ($input->getOption('naming-strategy') == 'long') { - $naming = new LongNamingStrategy(); + $naming = new Naming\LongNamingStrategy(); + } elseif ($input->getOption('naming-strategy') == 'short-accurate-props') { + $naming = new Naming\ShortAccuratePropsNamingStrategy(); + } elseif ($input->getOption('naming-strategy') == 'long-accurate-props') { + $naming = new Naming\LongAccuratePropsNamingStrategy(); } else { throw new \InvalidArgumentException("Unsupported naming strategy"); }