rikudou/reflection-file
最新稳定版本:v2.0.0
Composer 安装命令:
composer require rikudou/reflection-file
包简介
Reflection file implementation
README 文档
README
Allows you to get info about PHP file.
Usage
<?php use Rikudou\ReflectionFile; use Rikudou\Exception\ReflectionException; try { $reflection = new ReflectionFile("/path/to/file.php"); } catch (ReflectionException $exception) { var_dump("The file does not exist!"); } // true if the file contains a class $reflection->containsClass(); // true if the file contains any namespace $reflection->containsNamespace(); // true if the file contains any inline html, e.g. content that is not php $reflection->containsInlineHtml(); // true if the file contains any php code $reflection->containsPhpCode(); // true if the file contains echo or print statements $reflection->printsOutput(); // true if the file contains functions (not methods) $reflection->containsFunctions(); try { // returns the namespace as a string, throws exception if the // file does not contain a namespace $reflection->getNamespace(); } catch (ReflectionException $exception) { var_dump("The class does not contain a namespace!"); } // the previous example can be rewritten as follows if($reflection->containsNamespace()) { $reflection->getNamespace(); } try { // returns instance of \ReflectionClass if the file contains a class // otherwise throws an exception $reflection->getClass(); } catch (ReflectionException $exception) { var_dump("The class does not contain a class!"); } // returns array with \ReflectionFunction instances // can throw exception if the functions could not be found // which happnes when the file is not included foreach ($reflection->getFunctions() as $function) { var_dump("Function name: {$function->getName()}"); }
Limitations
The ReflectionFile cannot parse multiple classes or namespaces.
If the file contains more than one class (or namespace) the latest one will be returned.
统计信息
- 总下载量: 12.79k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 3
- 推荐数: 0
其他信息
- 授权协议: WTFPL
- 更新时间: 2019-02-06