/** * * @param PHPClass $class * @param Schema $schema * @param Element $element * @param boolean $arrayize * @return \Goetas\Xsd\XsdToPhp\Structure\PHPProperty */ private function visitElement(PHPClass $class, Schema $schema, ElementSingle $element, $arrayize = true) { $property = new PHPProperty(); $property->setName($this->getNamingStrategy()->getPropertyName($element)); $property->setDoc($element->getDoc()); $t = $element->getType(); $min = $element->getMin(); $max = $element->getMax(); $tags = array(new GenericTag('xmlname', $element->getName()), new GenericTag('xmlmin', $element->getMin() . ' '), new GenericTag('xmlmax', $max == -1 ? 'unbounded' : '' . $max . ' '), new GenericTag('xmlarray', $max == -1 || $max > $min && $min > 0 ? 'true' : 'false'), new GenericTag('xmlqualified', $element->isQualified() ? 'true' : 'false'), new GenericTag('xmlnil', $element->isNil() ? 'true' : 'false'), new GenericTag('xmlnamespace', $element->getSchema()->getTargetNamespace()), new GenericTag('xmltype', $element->getType()->getName()), new GenericTag('xmltypenamespace', $element->getType()->getSchema()->getTargetNamespace()), new GenericTag('xmlsimpletype', $t instanceof SimpleType ? 'true' : 'false')); $property->setTags($tags); if ($arrayize) { if ($itemOfArray = $this->isArrayType($t)) { if (!$itemOfArray->getName()) { $classType = $this->visitTypeAnonymous($itemOfArray, $element->getName(), $class); } else { $classType = $this->visitType($itemOfArray); } $arg = new PHPArg($this->getNamingStrategy()->getPropertyName($element)); $arg->setType($classType); $property->setType(new PHPClassOf($arg)); return $property; } elseif ($itemOfArray = $this->isArrayNestedElement($t)) { if (!$t->getName()) { $classType = $this->visitTypeAnonymous($t, $element->getName(), $class); } else { $classType = $this->visitType($t); } $elementProp = $this->visitElement($classType, $schema, $itemOfArray, false); $property->setType(new PHPClassOf($elementProp)); return $property; } elseif ($this->isArrayElement($element)) { $arg = new PHPArg($this->getNamingStrategy()->getPropertyName($element)); $arg->setType($this->findPHPClass($class, $element)); $arg->setDefault('array()'); $property->setType(new PHPClassOf($arg)); return $property; } } $property->setType($this->findPHPClass($class, $element, true)); return $property; }
protected function handleSetter(Generator\ClassGenerator $generator, PHPProperty $prop, PHPClass $class) { $name = "set" . Inflector::classify($prop->getName()); $type = $this->getPropertyType($prop); $namespace = explode("\\", $type); $namespaceClass = array_pop($namespace); $namespace = implode("\\", $namespace); if ($namespace == $class->getNamespace() || $namespace == "\\" . $class->getNamespace()) { $type = $namespaceClass; } if (substr($type, -2) == "[]") { $type = "array"; } $fullName = "method {$class->getName()} {$name}({$type} \${$prop->getName()})"; $docblock = $generator->getDocBlock(); $docblock->setWordWrap(false); $tag = new Generator\DocBlock\Tag(); $tag->setName($fullName); $docblock->setTag($tag); return; }
/** * * @param PHPClass $class * @param Schema $schema * @param Element $element * @param boolean $arrayize * @return \Goetas\Xsd\XsdToPhp\Structure\PHPProperty */ private function visitElement(PHPClass $class, Schema $schema, ElementSingle $element, $arrayize = true) { $property = new PHPProperty(); $property->setName($this->getNamingStrategy()->getPropertyName($element)); $property->setDoc($element->getDoc()); $t = $element->getType(); if ($arrayize) { if ($itemOfArray = $this->isArrayType($t)) { if (!$itemOfArray->getName()) { $classType = $this->visitTypeAnonymous($itemOfArray, $element->getName(), $class); } else { $classType = $this->visitType($itemOfArray); } $arg = new PHPArg($this->getNamingStrategy()->getPropertyName($element)); $arg->setType($classType); $property->setType(new PHPClassOf($arg)); return $property; } elseif ($itemOfArray = $this->isArrayNestedElement($t)) { if (!$t->getName()) { $classType = $this->visitTypeAnonymous($t, $element->getName(), $class); } else { $classType = $this->visitType($t); } $elementProp = $this->visitElement($classType, $schema, $itemOfArray, false); $property->setType(new PHPClassOf($elementProp)); return $property; } elseif ($this->isArrayElement($element)) { $arg = new PHPArg($this->getNamingStrategy()->getPropertyName($element)); $arg->setType($this->findPHPClass($class, $element)); $arg->setDefault('array()'); $property->setType(new PHPClassOf($arg)); return $property; } } $property->setType($this->findPHPClass($class, $element, true)); return $property; }
private function handleProperty(Generator\ClassGenerator $class, PHPProperty $prop) { $generatedProp = new PropertyGenerator($prop->getName()); $generatedProp->setVisibility(PropertyGenerator::VISIBILITY_PRIVATE); $class->addPropertyFromGenerator($generatedProp); if ($prop->getType() && (!$prop->getType()->getNamespace() && $prop->getType()->getName() == "array")) { // $generatedProp->setDefaultValue(array(), PropertyValueGenerator::TYPE_AUTO, PropertyValueGenerator::OUTPUT_SINGLE_LINE); } $docBlock = new DocBlockGenerator(); $generatedProp->setDocBlock($docBlock); if ($prop->getDoc()) { $docBlock->setLongDescription($prop->getDoc()); } $tag = new PropertyTag($prop->getName(), 'mixed'); $type = $prop->getType(); if ($type && $type instanceof PHPClassOf) { $tt = $type->getArg()->getType(); $tag->setTypes($this->getPhpType($tt) . "[]"); if ($p = $this->isOneType($tt)) { if ($t = $p->getType()) { $tag->setTypes($this->getPhpType($t) . "[]"); } } } elseif ($type) { if ($this->isNativeType($type)) { $tag->setTypes($this->getPhpType($type)); } elseif (($p = $this->isOneType($type)) && ($t = $p->getType())) { $tag->setTypes($this->getPhpType($t)); } else { $tag->setTypes($this->getPhpType($prop->getType())); } } $docBlock->setTag($tag); }