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();
}