/** * * @param string $finder * @param Schema $schema * @param DOMElement $node * @param string $typeName * @throws TypeException * @return ElementItem|Group|AttributeItem|AttribiuteGroup|Type */ private function findSomething($finder, Schema $schema, DOMElement $node, $typeName) { list($name, $namespace) = self::splitParts($node, $typeName); $namespace = $namespace ?: $schema->getTargetNamespace(); try { return $schema->{$finder}($name, $namespace); } catch (TypeNotFoundException $e) { throw new TypeException(sprintf("Can't find %s named {%s}#%s, at line %d in %s ", strtolower(substr($finder, 4)), $namespace, $name, $node->getLineNo(), $node->ownerDocument->documentURI), 0, $e); } }
public function addSchema(Schema $schema, $namespace = null) { if ($namespace !== null && $schema->getTargetNamespace() !== $namespace) { throw new SchemaException(sprintf("The target namespace ('%s') for schema, does not match the declared namespace '%s'", $schema->getTargetNamespace(), $namespace)); } if ($namespace !== null) { $this->schemas[$namespace] = $schema; } else { $this->schemas[] = $schema; } }
/** * * @param PHPClass $class * @param Schema $schema * @param Element $element * @param boolean $arrayize * @return \Goetas\Xsd\XsdToPhp\Structure\PHPProperty */ private function visitElement(&$class, Schema $schema, ElementItem $element, $arrayize = true) { $property = array(); $property["expose"] = true; $property["access_type"] = "public_method"; $property["serialized_name"] = $element->getName(); if ($schema->getTargetNamespace()) { $property["xml_element"]["namespace"] = $schema->getTargetNamespace(); } $property["accessor"]["getter"] = "get" . Inflector::classify($element->getName()); $property["accessor"]["setter"] = "set" . Inflector::classify($element->getName()); $t = $element->getType(); if ($arrayize) { if ($itemOfArray = $this->isArrayNestedElement($t)) { if (!$t->getName()) { $classType = $this->visitTypeAnonymous($t, $element->getName(), $class); } else { $classType = $this->visitType($t); } $visited = $this->visitElement($classType, $schema, $itemOfArray, false); $property["type"] = "array<" . $visited["type"] . ">"; $property["xml_list"]["inline"] = false; $property["xml_list"]["entry_name"] = $itemOfArray->getName(); if ($schema->getTargetNamespace()) { $property["xml_list"]["namespace"] = $schema->getTargetNamespace(); } return $property; } elseif ($itemOfArray = $this->isArrayType($t)) { if (!$t->getName()) { $visitedType = $this->visitTypeAnonymous($itemOfArray, $element->getName(), $class); if ($prop = $this->typeHasValue($itemOfArray, $class, 'xx')) { $property["type"] = "array<" . $prop . ">"; } else { $property["type"] = "array<" . key($visitedType) . ">"; } } else { $this->visitType($itemOfArray); $property["type"] = "array<" . $this->findPHPName($itemOfArray) . ">"; } $property["xml_list"]["inline"] = false; $property["xml_list"]["entry_name"] = $itemOfArray->getName(); if ($schema->getTargetNamespace()) { $property["xml_list"]["namespace"] = $schema->getTargetNamespace(); } return $property; } elseif ($this->isArrayElement($element)) { $property["xml_list"]["inline"] = true; $property["xml_list"]["entry_name"] = $element->getName(); if ($schema->getTargetNamespace()) { $property["xml_list"]["namespace"] = $schema->getTargetNamespace(); } $property["type"] = "array<" . $this->findPHPClass($class, $element) . ">"; return $property; } } $property["type"] = $this->findPHPClass($class, $element); return $property; }