protected function addComplexType(ComplexType $type) { $complexType = $this->document->createElement(static::XSD_NS . ':complexType'); $complexType->setAttribute('name', $type->getXmlType()); $all = $this->document->createElement(static::XSD_NS . ':' . ($type instanceof ArrayOfType ? 'sequence' : 'all')); $complexType->appendChild($all); foreach ($type->all() as $child) { $childType = $this->definition->getTypeRepository()->getType($child->getType()); $element = $this->document->createElement(static::XSD_NS . ':element'); $element->setAttribute('name', $child->getName()); if ($childType instanceof ComplexType) { $name = $childType->getXmlType(); if ($childType instanceof ArrayOfType) { $name = $childType->getName(); } $element->setAttribute('type', static::TYPES_NS . ':' . $name); } else { $element->setAttribute('type', $childType); } if ($child->isNillable()) { $element->setAttribute('nillable', 'true'); } if ($type instanceof ArrayOfType) { $element->setAttribute('minOccurs', 0); $element->setAttribute('maxOccurs', 'unbounded'); } $all->appendChild($element); } $this->domSchema->appendChild($complexType); }
public function addComplexType(ComplexType $type) { $phpType = $type->getPhpType(); $this->types[$phpType] = $type; $this->addClassmap($type->getXmlType(), $phpType); }
protected function addComplexType(ComplexType $type) { $complexType = $this->document->createElement(static::XS_NS . ':complexType'); $complexType->setAttribute('name', $type->getXmlType()); $all = $this->document->createElement(static::XS_NS . ':' . ($type instanceof ArrayOfType ? 'sequence' : 'sequence')); $complexType->appendChild($all); foreach ($type->all() as $child) { $childType = $this->definition->getTypeRepository()->getType($child->getType()); $element = $this->document->createElement(static::XS_NS . ':element'); $element->setAttribute('name', $child->getName()); $primitiveType = ''; if (is_string($childType)) { $ex = explode(':', $childType); $primitiveType = end($ex); } if ($childType instanceof ComplexType) { $name = $childType->getXmlType(); if ($childType instanceof ArrayOfType) { $name = $childType->getName(); } $element->setAttribute('type', static::TARGET_NS . ':' . $name); } elseif (is_string($childType) && in_array($primitiveType, $this->primitiveTypes) && $child->getRestriction()) { $element->appendChild($this->addSimpleTypes($primitiveType, $child)); } else { $element->setAttribute('type', static::XS_NS . ':' . $primitiveType); } $this->setAttributes($child, $element, $type); $all->appendChild($element); } $this->domSchema->appendChild($complexType); }
private function loadType($phpType) { if (false !== ($arrayOf = $this->typeRepository->getArrayOf($phpType))) { $this->loadType($arrayOf); } if (!$this->typeRepository->hasType($phpType)) { $complexTypeResolver = $this->resolve($phpType, 'annotation_complextype'); if (!$complexTypeResolver) { throw new \Exception(); } $loaded = $complexTypeResolver->load($phpType); $complexType = new ComplexType($phpType, isset($loaded['alias']) ? $loaded['alias'] : $phpType); foreach ($loaded['properties'] as $name => $property) { $complexType->add($name, $this->loadType($property->getValue()), $property->isNillable(), $property->getMinOccurs(), $property->getMaxOccurs()); } $this->typeRepository->addComplexType($complexType); } return $phpType; }
private function addComplexTypes(TypeRepository $typeRepository) { $foo = new ComplexType('BeSimple\\SoapBundle\\Tests\\fixtures\\ServiceBinding\\Foo', 'Foo'); $foo->add('foo', 'string'); $foo->add('bar', 'int'); $typeRepository->addComplexType($foo); $bar = new ComplexType('BeSimple\\SoapBundle\\Tests\\fixtures\\ServiceBinding\\Bar', 'Bar'); $bar->add('foo', 'string'); $bar->add('bar', 'int', true); $typeRepository->addComplexType($bar); $fooBar = new ComplexType('BeSimple\\SoapBundle\\Tests\\fixtures\\ServiceBinding\\FooBar', 'FooBar'); $fooBar->add('foo', 'BeSimple\\SoapBundle\\Tests\\fixtures\\ServiceBinding\\Foo'); $fooBar->add('bar', 'BeSimple\\SoapBundle\\Tests\\fixtures\\ServiceBinding\\Bar'); $typeRepository->addComplexType($fooBar); $simpleArrays = new ComplexType('BeSimple\\SoapBundle\\Tests\\fixtures\\ServiceBinding\\SimpleArrays', 'SimpleArrays'); $simpleArrays->add('array1', 'string[]', true); $simpleArrays->add('array2', 'string[]'); $simpleArrays->add('array3', 'string[]'); $typeRepository->addComplexType($simpleArrays); $fooRecursive = new ComplexType('BeSimple\\SoapBundle\\Tests\\fixtures\\ServiceBinding\\FooRecursive', 'FooRecursive'); $fooRecursive->add('bar', 'BeSimple\\SoapBundle\\Tests\\fixtures\\ServiceBinding\\BarRecursive'); $typeRepository->addComplexType($fooRecursive); $barRecursive = new ComplexType('BeSimple\\SoapBundle\\Tests\\fixtures\\ServiceBinding\\BarRecursive', 'BarRecursive'); $barRecursive->add('foo', 'BeSimple\\SoapBundle\\Tests\\fixtures\\ServiceBinding\\FooRecursive'); $typeRepository->addComplexType($barRecursive); return $typeRepository; }