How to find all PHP classes that belongs to namespace?

Sorry if such topic already discussed but I found nothing about it.

Is it possible to find all PHP classes that belongs to some namespace?

I tried to look at FileBasesIndex and Stub index in PHP open API but could not find proper way how it could be done

0
2 comments
Official comment

First, you need to collect all classes, then filter them by a namespace. Note: the same set of methods exists for interfaces and traits.

final Collection<PhpClass> result = new THashSet<>();
final PhpIndex index = PhpIndex.getInstance(project);
final Collection<String> names = index.getAllClassNames(prefixMatcher);
for (final String name : names) {
final Collection<PhpClass> classes = index.getClassesByName(name);
final Collection<PhpClass> filteredClasses = index.filterByNamespace(classes, namespaceName);
result.addAll(filteredClasses);
}
Avatar
Permanently deleted user

Thanks a lot!

0

Please sign in to leave a comment.