在使用psr-4约定的项目( symfony项目)中,我希望(只)打印具有特定名称空间的所有类的所有方法(这些类位于同一目录中)。
我尝试了这里的文档https://getcomposer.org/doc/00-intro.md,但我失败了,并且不太理解这个库是如何工作的(可能是我糟糕的英语技能?:/ )
有人能帮我吗?
我最后一次尝试:
class myUtils{
public function getAllMethods(){
$loader = new ClassLoader();
$loader->loadClass('App\DIR1');
$loader->register();
// Faa and Foo are the name of the classes of the file Fii.php and Faa.php located in DIR1 directory, the namespace of theses classes is App\DIR1
if (class_exists("Foo") && class_exists("Faa")){
dump('Its OK !');
}else{
dump('its NOT OK');
}
// the dump "Its NOT OK" is printed, I don't find how I can load dynamically Faa and Foo classes..
}
}发布于 2018-10-17 22:26:19
只是使用ClassLoader::getClassMap(),你没有其他方法,因为只有当你尝试使用它时,类才会被加载。您必须通过自定义函数筛选类。
无论如何,如果您没有预定义的类列表,那么解决方案将是脏的。
对于使用Reflection的方法,这很容易。
https://stackoverflow.com/questions/52856753
复制相似问题