getPath() public method

public getPath ( PHPClass $php )
$php Goetas\Xsd\XsdToPhp\Php\Structure\PHPClass
Esempio n. 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();
 }
Esempio n. 2
0
 protected function convert(AbstractConverter $converter, array $schemas, array $targets, OutputInterface $output)
 {
     $generator = new ClassGenerator();
     $pathGenerator = new Psr4PathGenerator($targets);
     $progress = $this->getHelperSet()->get('progress');
     $converter->addAliasMap('http://schemas.microsoft.com/exchange/services/2006/types', 'Or', function ($type) use($schemas) {
         return "OrElement";
     });
     $converter->addAliasMap('http://schemas.microsoft.com/exchange/services/2006/types', 'And', function ($type) use($schemas) {
         return "AndElement";
     });
     $converter->addAliasMap('http://schemas.microsoft.com/exchange/services/2006/types', 'EmailAddress', function ($type) use($schemas) {
         return "jamesiarmes\\PEWS\\API\\Type\\EmailAddressType";
     });
     $items = $converter->convert($schemas);
     $progress->start($output, count($items));
     $classMap = [];
     foreach ($items as $item) {
         /** @var PHPClass $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();
         $itemClass = $item->getNamespace() . '\\' . $item->getName();
         if (class_exists($itemClass)) {
             $existingClass = Generator\ClassGenerator::fromReflection(new ClassReflection($itemClass));
             $classGen = $existingClass;
         }
         if ($generator->generate($classGen, $item)) {
             $fileGen->setClass($classGen);
             $fileGen->write();
             $output->writeln("done.");
             if (isset($item->type) && $item->type->getName() != "") {
                 $classMap[$item->type->getName()] = '\\' . $classGen->getNamespaceName() . '\\' . $classGen->getName();
             }
         } else {
             $output->write("skip.");
         }
     }
     $mappingClassReflection = new ClassReflection(ClassMap::class);
     $mappingClass = Generator\ClassGenerator::fromReflection($mappingClassReflection);
     $mappingClass->getProperty('classMap')->setDefaultValue($classMap);
     $fileGen = new FileGenerator();
     $fileGen->setFilename($mappingClassReflection->getFileName());
     $fileGen->setClass($mappingClass);
     $fileGen->write();
     $progress->finish();
 }
Esempio n. 3
0
 protected function convert(AbstractConverter $converter, array $schemas, array $targets, OutputInterface $output)
 {
     $this->setClientMethodDocblocks();
     $generator = new ClassGenerator();
     $pathGenerator = new Psr4PathGenerator($targets);
     $converter->addAliasMap('http://schemas.microsoft.com/exchange/services/2006/types', 'Or', function ($type) use($schemas) {
         return "OrElement";
     });
     $converter->addAliasMap('http://schemas.microsoft.com/exchange/services/2006/types', 'And', function ($type) use($schemas) {
         return "AndElement";
     });
     $converter->addAliasMap('http://schemas.microsoft.com/exchange/services/2006/types', 'EmailAddress', function ($type) use($schemas) {
         return "garethp\\ews\\API\\Type\\EmailAddressType";
     });
     $items = $converter->convert($schemas);
     $progress = new ProgressBar($output, count($items));
     $progress->start(count($items));
     $classMap = [];
     foreach ($items as $item) {
         /** @var PHPClass $item */
         $progress->advance(1, true);
         $path = $pathGenerator->getPath($item);
         $fileGen = new FileGenerator();
         $fileGen->setFilename($path);
         $classGen = new \Zend\Code\Generator\ClassGenerator();
         $itemClass = $item->getNamespace() . '\\' . $item->getName();
         if (class_exists($itemClass)) {
             $fileGen = FileGenerator::fromReflectedFileName($path);
             $fileGen->setFilename($path);
             $classGen = Generator\ClassGenerator::fromReflection(new ClassReflection($itemClass));
         }
         if ($generator->generate($classGen, $item)) {
             $namespace = $classGen->getNamespaceName();
             $fileGen->setClass($classGen);
             $fileGen->write();
             if (isset($item->type) && $item->type->getName() != "" && $item->getNamespace() !== Enumeration::class) {
                 $classMap[$item->type->getName()] = '\\' . $namespace . '\\' . $classGen->getName();
             }
         } else {
         }
     }
     $mappingClassReflection = new ClassReflection(ClassMap::class);
     $mappingClass = Generator\ClassGenerator::fromReflection($mappingClassReflection);
     $mappingClass->getProperty('classMap')->setDefaultValue($classMap);
     $fileGen = new FileGenerator();
     $fileGen->setFilename($mappingClassReflection->getFileName());
     $fileGen->setClass($mappingClass);
     $fileGen->write();
     $progress->finish();
 }
 public function testWriter()
 {
     $generator = new Psr4PathGenerator(array('myns\\' => $this->tmpdir));
     $path = $generator->getPath(new PHPClass('Bar', 'myns'));
     $this->assertEquals($path, $this->tmpdir . "/Bar.php");
 }
Esempio n. 5
0
 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();
         }
     }
 }
Esempio n. 6
0
 /**
  * @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>... ");
         }
     }
 }