Skip to content

Commit 355ab4f

Browse files
jlagneaudunglas
authored andcommitted
Allow the possibility to resolve empty namespace aliases
1 parent a4303b4 commit 355ab4f

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/TypesGenerator.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -828,10 +828,22 @@ private function generateClassUses(array $annotationGenerators, array $classes,
828828
private function namespaceToDir(array $config, string $namespace): string
829829
{
830830
if (!empty($config['namespaces']['alias'])) {
831+
$prepend = '';
831832
foreach ($config['namespaces']['alias'] as $a) {
832-
$namespace = str_replace($a['namespace'], $a['resolvePath'], $namespace);
833+
if (!file_exists($a['resolvePath']) && !is_dir($a['resolvePath'])) {
834+
$this->logger->warning(sprintf('the path to resolve "%s" does not exists or is not a directory.', $a['resolvePath']));
835+
} else {
836+
if (null !== $a['namespace']) {
837+
$namespace = str_replace($a['namespace'], $a['resolvePath'], $namespace);
838+
} else {
839+
// Keep the last resolvePath if there is multiple definition with empty namespace.
840+
$prepend = $a['resolvePath'];
841+
}
842+
}
833843
}
844+
$namespace = $prepend . $namespace;
834845
}
846+
835847
return sprintf('%s/%s/', $config['output'], strtr($namespace, '\\', '/'));
836848
}
837849

0 commit comments

Comments
 (0)