Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix And type #175

Closed
Closed
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
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"authors": [
{
"name": "Asmir Mustafic",
"email" : "[email protected]"
"email": "[email protected]"
}
],
"keywords": [
Expand All @@ -18,7 +18,7 @@
],
"license": "MIT",
"require": {
"php": ">=7.2|^8.0",
"php": "^8.0",
"symfony/console": "^2.7|^3.0|^4.0|^5.0|^6.0|^7.0",
"symfony/dependency-injection": "^2.2|^3.0|^4.0|^5.0|^6.0|^7.0",
"symfony/yaml": "^2.2|^3.0|^4.0|^5.0|^6.0|^7.0",
Expand Down
15 changes: 12 additions & 3 deletions src/Jms/YamlConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Exception;
use GoetasWebservices\XML\XSDReader\Schema\Attribute\AttributeContainer;
use GoetasWebservices\XML\XSDReader\Schema\Attribute\AttributeItem;
use GoetasWebservices\XML\XSDReader\Schema\Element\Any\Any;
use GoetasWebservices\XML\XSDReader\Schema\Element\Element;
use GoetasWebservices\XML\XSDReader\Schema\Element\ElementContainer;
use GoetasWebservices\XML\XSDReader\Schema\Element\ElementDef;
Expand Down Expand Up @@ -444,7 +445,8 @@ public function getPropertyInHierarchy($class, $prop)

if (
(isset($props['properties']) && count($props['properties']) > 0 && !isset($props['properties'][$prop])) ||
(isset($props['properties']) && count($props['properties']) > 1)) {
(isset($props['properties']) && count($props['properties']) > 1)
) {
return false;
}

Expand All @@ -466,7 +468,9 @@ public function getPropertyInHierarchy($class, $prop)
*/
protected function getElementNamespace(Schema $schema, ElementItem $element)
{
if ($element->getSchema()->getTargetNamespace() &&
if (
(!$element instanceof Any) &&
$element->getSchema()->getTargetNamespace() &&
($schema->getElementsQualification() || ($element instanceof Element && $element->isQualified()) || !$element->isLocal())
) {
return $element->getSchema()->getTargetNamespace();
Expand All @@ -482,7 +486,7 @@ protected function getElementNamespace(Schema $schema, ElementItem $element)
*
* @return array
*/
protected function &visitElement(&$class, Schema $schema, ElementItem $element, $arrayize = true)
protected function &visitElement(&$class, Schema $schema, ElementItem|Any $element, $arrayize = true)
{
$property = [];
$property['expose'] = true;
Expand All @@ -500,6 +504,11 @@ protected function &visitElement(&$class, Schema $schema, ElementItem $element,
$inflector = InflectorFactory::create()->build();
$property['accessor']['getter'] = 'get' . $inflector->classify($this->getNamingStrategy()->getPropertyName($element));
$property['accessor']['setter'] = 'set' . $inflector->classify($this->getNamingStrategy()->getPropertyName($element));

if ($element instanceof Any) {
return $property;
}

$t = $element->getType();

if ($arrayize) {
Expand Down
12 changes: 7 additions & 5 deletions src/Php/PhpConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Exception;
use GoetasWebservices\XML\XSDReader\Schema\Attribute\AttributeItem;
use GoetasWebservices\XML\XSDReader\Schema\Attribute\Group as AttributeGroup;
use GoetasWebservices\XML\XSDReader\Schema\Element\Any\Any;
use GoetasWebservices\XML\XSDReader\Schema\Element\Element;
use GoetasWebservices\XML\XSDReader\Schema\Element\ElementDef;
use GoetasWebservices\XML\XSDReader\Schema\Element\ElementItem;
Expand Down Expand Up @@ -298,7 +299,6 @@ public function visitType(Type $type, $force = false)
}

if (($this->isArrayType($type) || $this->isArrayNestedElement($type)) && !$force) {

$this->classes[spl_object_hash($type)]['skip'] = true;
$this->skipByType[spl_object_hash($class)] = true;

Expand Down Expand Up @@ -451,21 +451,24 @@ private function visitAttribute(PHPClass $class, Schema $schema, AttributeItem $
*
* @return \GoetasWebservices\Xsd\XsdToPhp\Php\Structure\PHPProperty
*/
private function visitElement(PHPClass $class, Schema $schema, ElementSingle $element, $arrayize = true)
private function visitElement(PHPClass $class, Schema $schema, ElementSingle|Any $element, $arrayize = true)
{
$property = new PHPProperty();
$property->setName($this->getNamingStrategy()->getPropertyName($element));
$property->setDoc($element->getDoc());

if ($element instanceof Any) {
return $property;
}

if ($element->isNil() || $element->getMin() === 0) {
$property->setNullable(true);
}

$t = $element->getType();

if ($arrayize) {

if ($itemOfArray = $this->isArrayType($t)) {

if (!$itemOfArray->getName()) {
if ($element instanceof ElementRef) {
$refClass = $this->visitElementDef($element->getReferencedElement());
Expand All @@ -485,7 +488,6 @@ private function visitElement(PHPClass $class, Schema $schema, ElementSingle $el

return $property;
} elseif ($itemOfArray = $this->isArrayNestedElement($t)) {

if (!$t->getName()) {
if ($element instanceof ElementRef) {
$refClass = $this->visitElementDef($element->getReferencedElement());
Expand Down