Skip to content
This repository has been archived by the owner on Jan 7, 2023. It is now read-only.

Commit

Permalink
some improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
goetas committed Feb 28, 2014
1 parent 6863e5d commit 12ed679
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 10 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,19 @@ php bin/xsd2php.php convert \
You have always to specify `--ns-map='mycompany\\myproject:http://www.company.com/projectOne' ` because `http://www.company.com/projectTwo` should use some types contained into `http://www.company.com/projectOne`


When some properties are arrays you can hint it:


Example:
```sh
php bin/xsd2php.php convert \
--ns-map='mycompany\\myproject:http://www.company.com/projectOne' \
--array-map='ArrayOfReservations:http://www.company.com/projectTwo' \
--array-map='ArrayOf*:http://www.company.com/projectTwo' \

'http://www.example.com/data.xsd' '/var/www/classes' 'http://www.company.com/projectTwo'
```


[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/goetas/xsd2php/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

13 changes: 11 additions & 2 deletions bin/xsd2php.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
#!/bin/php
<?php

include __DIR__ . '/../../../autoload.php';
foreach (array(
__DIR__ . '/../autoload.php',
__DIR__ . '/../../autoload.php',
__DIR__ . '/../vendor/autoload.php',
__DIR__ . '/../../vendor/autoload.php',
) as $path) {
if(is_file($path)){
include $path;
break;
}
}

use Goetas\Xsd\XsdToPhp\Console\ConsoleRunner;

Expand Down
38 changes: 30 additions & 8 deletions lib/Goetas/Xsd/XsdToPhp/Generator/ClassGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,9 @@ protected function generateServerClass(\DOMElement $node, DOMXPath $xp, $save, $
$content = '<?php'.PHP_EOL;
$content .='namespace '.$ns.';'.PHP_EOL;
$content .= '/**'.PHP_EOL;

$content .= ' * XSD NS: '.$node->getAttribute("ns")."#".$node->getAttribute("name").PHP_EOL;

$content.= ' * \\'.$this->getFullClassName($node).PHP_EOL;

if ($doc = $xp->evaluate("string(doc)", $node)) {
Expand Down Expand Up @@ -496,7 +499,19 @@ protected function getFullClassName(DOMElement $node)

return $this->getFullClassNamePhp($ns,$name);
}
protected function hasPrimitive($ns, $name)
{
if (isset ( $this->namespaces [$ns] )) {
return rtrim ( $this->namespaces [$ns], "\\" ) . "\\" . $this->fixClassName ( $name );
} elseif (isset ( $this->primitive [$ns] [$name])) {
return $this->primitive [$ns] [$name];

} elseif (isset ( $this->alias [$ns] [$name])) {
return $this->getFullClassNamePhp($this->alias [$ns] [$name]["ns"], $this->alias [$ns] [$name] ["name"]);
} else {
throw new \Exception ( "Non trovo nessun associazione al namespace '$ns' per il tipo '$name'" );
}
}
protected function getFullClassNamePhp($ns, $name)
{
if (isset ( $this->namespaces [$ns] )) {
Expand Down Expand Up @@ -638,21 +653,28 @@ protected function geneatePropertyMethods(DOMElement $node, DOMXPath $xp)
$content2 = '';

$atype = $this->isArrayTypeProp($node);

$varName = '$'.self::calmelCase($node->getAttribute("name"), true);
if ($atype) {

if ($atype===1) {
$arrayNode = $this->getArrayTypeNode1($node, $xp);
try {
$arrayNode = $this->getArrayTypeNode1($node, $xp);
} catch (\Exception $e) {
throw new \Exception("May be array type?", 0, $e);
}
} else {
$arrayNode = $this->getArrayTypeNode($node, $xp);
}

$cls = $this->getFullClassName($arrayNode);



$content .= '/**'.PHP_EOL;
if ($this->isPhpNative($cls)) {
$content .= ' * @param '.$cls;
$content .= ' * @param '.$varName.' '.$cls;
} else {
$content .= ' * @param \\'.$cls;
$content .= ' * @param '.$varName.' \\'.$cls;
}

$content .= PHP_EOL;
Expand All @@ -676,9 +698,9 @@ protected function geneatePropertyMethods(DOMElement $node, DOMXPath $xp)
$cls = $this->getFullClassName($node);
$content .= '/**'.PHP_EOL;
if ($this->isPhpNative($cls)) {
$content .= ' * @param '.$this->getFullClassName($node);
$content .= ' * @param '.$varName.' '.$this->getFullClassName($node);
} else {
$content .= ' * @param \\'.$this->getFullClassName($node);
$content .= ' * @param '.$varName.' \\'.$this->getFullClassName($node);
}

$content .= PHP_EOL;
Expand All @@ -690,7 +712,7 @@ protected function geneatePropertyMethods(DOMElement $node, DOMXPath $xp)
if (!$this->isPhpNative($cls)) {
$content.= '\\'.$cls.' ';
}
$content.= '$'.self::calmelCase($node->getAttribute("name"), true);
$content.= $varName;

if (!$node->getAttribute("required")!=='true') {
$content.=" = null ";
Expand Down Expand Up @@ -724,7 +746,7 @@ protected function geneateProperty(DOMElement $node, DOMXPath $xp)
}

$cls = $this->getFullClassName($node);

$content .= ' * XSD NS: '.$node->getAttribute("type-ns")."#".$node->getAttribute("type-name").PHP_EOL;
if ($this->isPhpNative($cls)) {
$content .= ' * @var '.$cls;
} elseif ($this->isArrayTypeProp($node)) {
Expand Down

0 comments on commit 12ed679

Please sign in to comment.