/**
  * @return \Goetas\XML\XSDReader\Schema\Schema
  */
 public function readNode(\DOMNode $node, $file = 'schema.xsd')
 {
     $this->loadedFiles[$file] = $rootSchema = new Schema();
     $rootSchema->addSchema($this->getGlobalSchema());
     $callbacks = $this->schemaNode($rootSchema, $node);
     foreach ($callbacks as $callback) {
         call_user_func($callback);
     }
     return $rootSchema;
 }
Exemple #2
0
 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;
     }
 }
Exemple #3
0
 /**
  *
  * @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;
 }