Goetas\Xsd\XsdToPhp\Php\ClassGenerator::generate PHP Method

generate() public method

public generate ( ClassGenerator $class, PHPClass $type )
$class Zend\Code\Generator\ClassGenerator
$type Goetas\Xsd\XsdToPhp\Php\Structure\PHPClass
    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;
        }
    }

Usage Example

Example #1
0
 protected function convert(AbstractConverter $converter, array $schemas, array $targets, OutputInterface $output)
 {
     $generator = new ClassGenerator();
     $generator->setTargetPhpVersion($converter->getTargetPhpVersion());
     $generator->setBaseClass($converter->getBaseClass());
     $pathGenerator = new Psr4PathGenerator($targets);
     $progress = $this->getHelperSet()->get('progress');
     $items = $converter->convert($schemas);
     $progress->start($output, count($items));
     foreach ($items as $item) {
         $progress->advance(1, true);
         $output->write(" Creating <info>" . $output->getFormatter()->escape($item->getFullName()) . "</info>... ");
         $path = $pathGenerator->getPath($item);
         $fileGen = new FileGenerator();
         $fileGen->setFilename($path);
         $classGen = new \Zend\Code\Generator\ClassGenerator();
         if ($generator->generate($classGen, $item)) {
             $fileGen->setClass($classGen);
             $fileGen->write();
             $output->writeln("done.");
         } else {
             $output->write("skip.");
         }
     }
     $progress->finish();
 }
All Usage Examples Of Goetas\Xsd\XsdToPhp\Php\ClassGenerator::generate