Skip to content
This repository was archived by the owner on Jan 7, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions lib/Command/AbstractConvert.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -32,7 +30,7 @@ protected function configure()

/**
*/
protected abstract function getConverterter(NamingStrategy $naming);
protected abstract function getConverterter(Naming\NamingStrategy $naming);

/**
*
Expand All @@ -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");
}
Expand Down
35 changes: 35 additions & 0 deletions lib/Naming/LongAccuratePropsNamingStrategy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
namespace Goetas\Xsd\XsdToPhp\Naming;

use Doctrine\Common\Inflector\Inflector;
use GoetasWebservices\XML\XSDReader\Schema\Item;
use GoetasWebservices\XML\XSDReader\Schema\Type\Type;

class LongAccuratePropsNamingStrategy implements NamingStrategy
{

public function getTypeName(Type $type)
{
return $this->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));
}
}
39 changes: 39 additions & 0 deletions lib/Naming/ShortAccuratePropsNamingStrategy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php
namespace Goetas\Xsd\XsdToPhp\Naming;

use Doctrine\Common\Inflector\Inflector;
use GoetasWebservices\XML\XSDReader\Schema\Item;
use GoetasWebservices\XML\XSDReader\Schema\Type\Type;

class ShortAccuratePropsNamingStrategy implements NamingStrategy
{

public function getTypeName(Type $type)
{
$name = $this->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));
}
}