Beispiel #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();
 }
 /**
  *
  * @param mixed $xml
  * @return \Zend\Code\Generator\ClassGenerator[]
  */
 protected function getPhpClasses($xml, array $types = array())
 {
     $creator = new PhpConverter(new ShortNamingStrategy());
     $creator->addNamespace('', 'Example');
     foreach ($types as $typeData) {
         list($ns, $name, $type) = $typeData;
         $creator->addAliasMapType($ns, $name, $type);
     }
     $generator = new ClassGenerator();
     $reader = new SchemaReader();
     if (!is_array($xml)) {
         $xml = ['schema.xsd' => $xml];
     }
     $schemas = [];
     foreach ($xml as $name => $str) {
         $schemas[] = $reader->readString($str, $name);
     }
     $items = $creator->convert($schemas);
     $classes = array();
     foreach ($items as $k => $item) {
         $codegen = new \Zend\Code\Generator\ClassGenerator();
         if ($generator->generate($codegen, $item)) {
             $classes[$k] = $codegen;
         }
     }
     return $classes;
 }
 /**
  *
  * @param mixed $xml
  * @return \Zend\Code\Generator\ClassGenerator[]
  */
 protected function getClasses($xml)
 {
     $phpcreator = new PhpConverter(new ShortNamingStrategy());
     $phpcreator->addNamespace('http://www.example.com', 'Example');
     $generator = new ClassGenerator();
     $reader = new SchemaReader();
     if (!is_array($xml)) {
         $xml = ['schema.xsd' => $xml];
     }
     $schemas = [];
     foreach ($xml as $name => $str) {
         $schemas[] = $reader->readString($str, $name);
     }
     $items = $phpcreator->convert($schemas);
     $classes = array();
     foreach ($items as $k => $item) {
         $codegen = new \Zend\Code\Generator\ClassGenerator();
         if ($generator->generate($codegen, $item)) {
             $classes[$k] = $codegen;
         }
     }
     return $classes;
 }
 protected static function generatePHPFiles(array $schemas)
 {
     $phpcreator = new PhpConverter(new ShortNamingStrategy());
     $phpcreator->addNamespace('http://www.opentravel.org/OTA/2003/05', self::$namespace);
     $phpcreator->addAliasMapType('http://www.opentravel.org/OTA/2003/05', 'DateOrTimeOrDateTimeType', 'Goetas\\Xsd\\XsdToPhp\\Tests\\JmsSerializer\\OTA\\OTADateTime');
     $phpcreator->addAliasMapType('http://www.opentravel.org/OTA/2003/05', 'DateOrDateTimeType', 'Goetas\\Xsd\\XsdToPhp\\Tests\\JmsSerializer\\OTA\\OTADateTime');
     $phpcreator->addAliasMapType('http://www.opentravel.org/OTA/2003/05', 'TimeOrDateTimeType', 'Goetas\\Xsd\\XsdToPhp\\Tests\\JmsSerializer\\OTA\\OTADateTime');
     $items = $phpcreator->convert($schemas);
     $generator = new ClassGenerator();
     $pathGenerator = new Psr4PathGenerator(array(self::$namespace . "\\" => self::$phpDir));
     foreach ($items as $item) {
         $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();
         }
     }
 }
 /**
  * @param PhpConverter $converter
  * @param array $schemas
  * @param array $targets
  * @param XsdGeneratePhpArgs $input
  * @param XsdGeneratePhpCommand $command
  * @throws \Goetas\Xsd\XsdToPhp\PathGenerator\PathGeneratorException
  */
 protected function convert(PhpConverter $converter, array $schemas, array $targets, XsdGeneratePhpArgs $input, XsdGeneratePhpCommand $command)
 {
     $generator = new ClassGenerator();
     $pathGenerator = new Psr4PathGenerator($targets);
     $items = $converter->convert($schemas);
     /** @var ProgressBar $progressBar */
     $progressBar = new ProgressBar($this->output, count($items));
     $progressBar->start();
     $extendClass = null;
     if ($input->hasExtendedClass()) {
         $extendClass = new PHPClass($input->getExtendedClassName(), $input->getExtendedClassNamespaceName());
     }
     $this->outputWriteLine("Generating PHP files");
     $skippedFiles = array();
     /** @var PHPClass $item */
     foreach ($items as $item) {
         $progressBar->advance();
         $path = $pathGenerator->getPath($item);
         $fileGen = new FileGenerator();
         $fileGen->setFilename($path);
         $classGen = new \Zend\Code\Generator\ClassGenerator();
         if (!$item->getExtends() instanceof PHPClass && $extendClass instanceof PHPClass) {
             $item->setExtends($extendClass);
         }
         if (!$generator->generate($classGen, $item)) {
             $skippedFiles[] = $item->getFullName();
         }
         $fileGen->setClass($classGen);
         $fileGen->write();
     }
     $progressBar->finish();
     if (!empty($skippedFiles)) {
         foreach ($skippedFiles as $skippedFile) {
             $this->outputWriteLine(" + <info>" . $this->outputFormatterEscape($skippedFile) . "</info>... ");
         }
     }
 }