查找PHP依赖项 [英] Finding PHP dependencies

查看:35
本文介绍了查找PHP依赖项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有任何工具可以列出PHP文件使用的类的名称?

Are there any tools that can list the names of classes used by a PHP file?

例如,如果我在此文件上运行它:

For example, if I ran it on this file:

<?
class Test {
  public function __construct(Obj1 $x) {
    $y = new Obj2();
    $str = "Obj3";
    $z = new $str();
  }
}
?>

它将报告"Obj1"和"Obj2".如果它真的很聪明,它也可能会报告"Obj3",但这不是必需的.

it would report "Obj1" and "Obj2". If it were really smart it might report "Obj3" as well, but that's not essential.

我正在尝试打包一些代码,并且需要一些帮助以确保我不会错过任何依赖项.

I'm trying to package up some code, and I want some help making sure that I didn't miss any dependencies.

有一个叫做 PHP_Depend 的东西,它可以显示依赖项的数量,但是可以不要报告他们是什么.

There's something called PHP_Depend, which can graph the number of dependencies, but can't report what they are.

更新:我没有找到真正的解决方案,但是我发现了足够接近我目的的东西.您可以标记文件,并搜索所有T_STRING标记.这将为您提供文件中提到的所有类名.它还将为您提供其他功能,例如函数名称和常量.但是,如果您的班级名称容易区分(例如,它们有大写字母),那么这应该没问题.

UPDATE: I didn't find a real solution, but I figured out something close enough for my purposes. You can tokenize a file, and search for all T_STRING tokens. This will give you all class names mentioned in the file. It will also give you other things, like function names and constants. But if your class names are easy to distinguish (e.g. they have initial caps), then this shouldn't be a problem.

$contents = file_get_contents($path);
$tokens = token_get_all($contents);
foreach ($tokens as $token) {
  if (is_array($token) && $token[0] === T_STRING) {
    echo $token[1]."\n";
  }
}

推荐答案

PHPXref ,它是PHP交叉引用文档生成器.

There's PHPXref, which is a PHP cross referencing document generator.

这篇关于查找PHP依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆