php - PHP,来自 PSR-4 项目,使用相同的命名空间打印所有类的所有方法
问题描述
从使用 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..
}
}
解决方案
只是玩,ClassLoader::getClassMap()
你没有其他办法,因为只有当你尝试使用它时才会加载类。您必须通过自定义函数过滤类。
无论如何,如果您没有预定义的类列表,那么解决方案将是肮脏的。
对于使用反射的方法,这很容易。
推荐阅读
- node.js - 具有多个查询的 MongoDB findOne 返回错误的结果
- python - 使用 Pandas 将数据帧作为 JSON 编码的字典写入文本文件
- c# - 在 C# 中解析 pdf417 aamvaid
- sql - 使用 SQL 计算每组 id 的相关性
- microsoft-graph-api - Outlook 使用 Graph API 添加
- c# - 有没有办法将证书从 azure keyvault 导入 .NET 中的 azure Web 应用程序?
- android - nRF52840 - Android Kotlin 应用程序:16 位 UUID 的问题
- for-loop - 如何在批处理文件上使用命令 FOR 获取文本文件的内容
- elasticsearch - Fluentd - 弹性搜索批量大小的配置设置
- flutter - 颤动中带有列表视图构建器的下拉菜单