addAliasMap() публичный Метод

public addAliasMap ( $ns, $name, callable $handler )
$handler callable
Пример #1
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();
 }
Пример #2
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();
 }