phpdocumentor/reflection
Composer 安装命令:
composer require --dev phpdocumentor/reflection
包简介
Reflection library to do Static Analysis for PHP Projects
README 文档
README
Reflection
Using this library it is possible to statically reflect one or more files and create an object graph representing your application's structure, including accompanying in-source documentation using DocBlocks.
The information that this library provides is similar to what the (built-in) Reflection extension of PHP provides; there are however several advantages to using this library:
- Due to its Static nature it does not execute procedural code in your reflected files where Dynamic Reflection does.
- Because the none of the code is interpreted by PHP (and executed) Static Reflection uses less memory.
- Can reflect complete files
- Can reflect a whole project by reflecting multiple files.
- Reflects the contents of a DocBlock instead of just mentioning there is one.
- Is capable of analyzing code written for any PHP version (starting at 5.2) up to and including your installed PHP version.
Features
- [Creates an object graph] containing the structure of your application much like a site map shows the structure of a website.
- Can read and interpret code of any PHP version starting with 5.2 up to and including your currently installed version of PHP.
- Due it's clean interface it can be in any application without a complex setup.
Installation
In order to inspect a codebase you need to tell composer to include the phpdocumentor/reflection package. This
can easily be done using the following command in your command line terminal:
composer require phpdocumentor/reflection:~6.0
After the installation is complete no further configuration is necessary and you can immediately start using it.
Basic Usage
This Reflection library uses PSR-4 and it is recommended to use a PSR-4 compatible autoloader to load all the files containing the classes for this library.
An easy way to do this is by including the composer autoloader as shown here:
include 'vendor/autoload.php';
Once that is done you can use the createInstance() method of the \phpDocumentor\Reflection\Php\ProjectFactory class to instantiate a new project factory and
pre-configure it with sensible defaults. Optional you can specify the parser version that shall be used as an argument of createInstance().
By default the php7 parser is prefered. And php5 is used as a fallback. See the documentation of phpparser for more info.
$projectFactory = \phpDocumentor\Reflection\Php\ProjectFactory::createInstance();
At this point we are ready to analyze your complete project or just one file at the time. Just pass an array of file paths to the create method of the project factory.
$projectFiles = [new \phpDocumentor\Reflection\File\LocalFile('tests/example.file.php')];
$project = $projectFactory->create('My Project', $projectFiles);
When the process is ready a new object of type phpDocumentor\Reflection\Php\Project will be returned that
contains a complete hierarchy of all files with their classes, traits and interfaces (and everything in there), but also
all namespaces and packages as a hierarchical tree.
See the example script for a detailed and commented example
phpdocumentor/reflection 适用场景与选型建议
phpdocumentor/reflection 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 25.4M 次下载、GitHub Stars 达 125, 最近一次更新时间为 2012 年 11 月 27 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「phpdoc」 「reflection」 「static analysis」 「phpDocumentor」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 phpdocumentor/reflection 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 phpdocumentor/reflection 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 phpdocumentor/reflection 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Library emulating the PHP internal reflection using just the tokenized source code.
A simple tool for checking that your PHP classes and methods use PHPDocs (PHP DocBlocks Checker fork).
Bookdown.io With Bootswatch Styles And Prism Syntax Highlighting
TwigStan is a static analyzer for Twig templates powered by PHPStan
Laravel package that generates RESTful API documentation in Markdown based on PHPDoc.
Parse use statements for a reflection object
统计信息
- 总下载量: 25.4M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 126
- 点击次数: 23
- 依赖项目数: 109
- 推荐数: 8
其他信息
- 授权协议: MIT
- 更新时间: 2012-11-27