mindplay/filereflection

此包已被废弃且不再维护。作者建议使用 roave/better-reflection 包代替。

补充PHP反射API缺失的ReflectionFile类

1.2.1 2015-06-17 16:00 UTC

This package is auto-updated.

Last update: 2023-11-29 13:55:45 UTC


README

⚠️ 已弃用 ⚠️

考虑使用 Roave/BetterReflection 代替。

https://github.com/mindplay-dk/filereflection

此库补充了PHP 反射API 缺失的ReflectionFile类。

Build Status

已经有一些库可以完成这个功能,但这个库实现了一个其他实现中我没有找到的重要功能:根据 命名解析规则 解析本地类型名。

接口非常简单

ReflectionFile {

    public __construct( string $path )

    public string getPath ( void )
    public string getNamespaceName ( void )
    public string resolveName ( string $name )
    public ReflectionClass getClass ( string $name )
    public ReflectionClass[] getClasses ( void )

}

用法也很直观

use mindplay\filereflection\ReflectionFile;

$file = new ReflectionFile('/path/to/MyNamespace/MyClass.php');

var_dump($file->resolveName('MyOtherClass')); // => '\MyNamespace\MyOtherClass'

请注意,此库当前省略了函数、常量等的反射和枚举。