nette/reflection
最新稳定版本:v2.4.2
Composer 安装命令:
composer require nette/reflection
包简介
Nette Reflection: docblock annotations parser and common reflection classes
关键字:
README 文档
README
Install it using Composer:
composer require nette/reflection
The last stable release requires PHP version 5.6 or newer (is compatible with PHP 7.0 and 7.1).
If you like Nette, please make a donation now. Thank you!
If you need to find every information about any class, reflection is the right tool to do it. You can easily find out which methods does any class have, what parameters do those methods accept, etc.
// getting PDO class reflection $classReflection = new Nette\Reflection\ClassType('PDO'); // getting PDO::query method reflection $methodReflection = new Nette\Reflection\Method('PDO', 'query');
Annotations
Reflection has really a lot to do with annotations. The annotations are written into phpDoc comments (two opening asterisks are mandatory!) and start with @. You can annotate classes, variables and methods:
/** * @author John Doe * @author Tomas Marny * @secured */ class FooClass { /** @Persistent */ public $foo; /** @User(loggedIn, role=Admin) */ public function bar() {} }
In the code there are these annotations:
@author John Doe- string, contains text value'John Doe'@Persistent- boolean, its presence meanstrue@User(loggedIn, role=Admin)- contains associativearray('loggedIn', 'role' => 'Admin')
The existence of a class annotation can be checked via hasAnnotation() method:
$fooReflection = new Nette\Reflection\ClassType('FooClass'); $fooReflection->hasAnnotation('author'); // returns true $fooReflection->hasAnnotation('copyright'); // returns false
Values can be acquired with getAnnotation():
$fooReflection->getAnnotation('author'); // returns string 'Tomas Marny' $fooReflection->getMethod('bar')->getAnnotation('User'); // returns array('loggedIn', 'role' => 'Admin')
.[caution] Previous definitions are overwritten with the latter ones, sou you will always get the last one.
All annotations can be obtained with getAnnotations():
array(3) {
"author" => array(2) {
0 => string(8) "John Doe"
1 => string(11) "Tomas Marny"
}
"secured" => array(1) {
0 => bool(true)
}
}
nette/reflection 适用场景与选型建议
nette/reflection 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4.78M 次下载、GitHub Stars 达 81, 最近一次更新时间为 2026 年 01 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「reflection」 「annotation」 「nette」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 nette/reflection 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 nette/reflection 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 nette/reflection 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Library emulating the PHP internal reflection using just the tokenized source code.
Parse use statements for a reflection object
Symfony bundle to add arbitrary metadata to classes and their constants by annotation
Nette Framework adapter for I18n package
Build forms from schema
Asynchronous MQTT client built on React
统计信息
- 总下载量: 4.78M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 85
- 点击次数: 31
- 依赖项目数: 116
- 推荐数: 1
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2026-01-04