private function typeHasValue(Type $type, PHPClass $parentClass, $name) { do { if (!$type instanceof SimpleType) { return false; } if ($alias = $this->getTypeAlias($type)) { return PHPClass::createFromFQCN($alias); } if ($type->getName()) { $parentClass = $this->visitType($type); } else { $parentClass = $this->visitTypeAnonymous($type, $name, $parentClass); } if ($prop = $parentClass->getPropertyInHierarchy('__value')) { return $prop->getType(); } } while (method_exists($type, 'getRestriction') && ($rest = $type->getRestriction()) && ($type = $rest->getBase()) || method_exists($type, 'getUnions') && ($unions = $type->getUnions()) && ($type = reset($unions))); return false; }
public function generate(PHPClass $type) { $class = new \Zend\Code\Generator\ClassGenerator(); $docblock = new DocBlockGenerator("Class representing " . $type->getName()); if ($type->getDoc()) { $docblock->setLongDescription($type->getDoc()); } $class->setNamespaceName($type->getNamespace() ?: NULL); $class->setName($type->getName()); $class->setDocblock($docblock); if ($extends = $type->getExtends()) { if ($p = $extends->isSimpleType()) { $this->handleProperty($class, $p); $this->handleValueMethod($class, $p, $extends); } else { $class->setExtendedClass($extends->getName()); if ($extends->getNamespace() != $type->getNamespace()) { if ($extends->getName() == $type->getName()) { $class->addUse($type->getExtends()->getFullName(), $extends->getName() . "Base"); $class->setExtendedClass($extends->getName() . "Base"); } else { $class->addUse($extends->getFullName()); } } } } if ($this->handleBody($class, $type)) { return $class; } }