public function getPath(PHPClass $php) { foreach ($this->namespaces as $namespace => $dir) { if (strpos(trim($php->getNamespace()) . "\\", $namespace) === 0) { $d = strtr(substr($php->getNamespace(), strlen($namespace)), "\\", "/"); $dir = rtrim($dir, "/") . "/" . $d; if (!is_dir($dir) && !mkdir($dir, 0777, true)) { throw new PathGeneratorException("Can't create the '{$dir}' directory"); } return rtrim($dir, "/") . "/" . $php->getName() . ".php"; } } throw new PathGeneratorException("Can't find a defined location where save '{$php}' object"); }
private function handleClassExtension(PHPClass $class, Type $type) { if ($alias = $this->getTypeAlias($type)) { $c = PHPClass::createFromFQCN($alias); $val = new PHPProperty('__value'); $val->setType($c); $c->addProperty($val); $class->setExtends($c); } else { $extension = $this->visitType($type, true); $class->setExtends($extension); } }
protected function isNativeType(PHPClass $class) { return !$class->getNamespace() && in_array($class->getName(), ['string', 'int', 'float', 'integer', 'boolean', 'array', 'mixed', 'callable']); }
public function generate(Generator\ClassGenerator $class, PHPClass $type) { $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 = $this->isOneType($extends)) { $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 true; } }