phpactor/worse-reflection 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

phpactor/worse-reflection

Composer 安装命令:

composer require phpactor/worse-reflection

包简介

Lazy AST reflector that is much worse than better

README 文档

README

This package is not actively developed here but in the main phpactor repository. It is occasionally updated. Raise any issues about this repository there.

This library aims to provide a light class-based AST based "reflection" library.

Worse than Better

It is influenced by BetterReflection, diffrerences are as follows:

  • Can reflect variables.
  • Does not aim to implement built-in PHP reflection API.
  • Uses the amazing Tolerant Parser.
  • Uses the PHPStorm stubs to provide reflections of internal classes.

It is being developed to provide support for the Phpactor introspection and refactoring tool. And is therefore driven by that use case.

If you want comprehsnsive reflection, use BetterReflection. If you want faster reflection including type/value flow with no support and frequent BC breaks, then you can use this one (note that I havn't benchmarked BR in sometime, it may well be faster now).

Usage

$reflector = ReflectorBuilder::create()
    ->addSource('<?php ...')
    ->build();

$class = $reflector->reflectClass('Foobar');

$class->methods()->get('foobar')->visiblity()    == Visibility::public();
$class->properties()->get('barbar')->visiblity() == Visibility::public();

/** @var ReflectionMethod */
foreach ($class->methods() as $method) {
    echo $method->name();                                  // methodName
    echo $method->returnType()->short();                   // Foobar
    echo (string) $method->returnType();                   // This\Is\Foobar
    echo (string) $method->inferredReturnTypes()->best(); // from docblock if it exists

    foreach ($method->parameters() as $parameter) {
        $parameter->name();                      // paramName
        (string) $parameter->inferredType();     // Fully\Qualified\ParamType
    }

}

foreach ($class->traits() as $trait) {
    // ...
}

foreach ($class->interfaes() as $interface) {
    // ...
}

foreach ($class->method('foobar')->frame()->locals() as $variable) {
    $variable->offset()->toInt(); // byte offset
    $variable->type();            // variable type (if available )
    $variable->value();           // variable value (if available)
}

$offset = $reflection->reflectOffset(
    SourceCode::fromString('...'), 
    Offset::fromInt(1234)
);

$offset->value()->type();    // type at offset (if available)
$offset->value()->value();   // value (e.g. 1234)
$offset->frame();            // return frame

See tests for more examples...

Contributing

This package is open source and welcomes contributions! Feel free to open a pull request on this repository.

Support

  • Create an issue on the main Phpactor repository.
  • Join the #phpactor channel on the Slack Symfony Devs channel.

phpactor/worse-reflection 适用场景与选型建议

phpactor/worse-reflection 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 136.91k 次下载、GitHub Stars 达 21, 最近一次更新时间为 2017 年 08 月 15 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 phpactor/worse-reflection 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 phpactor/worse-reflection 我们能提供哪些服务?
定制开发 / 二次开发

基于 phpactor/worse-reflection 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 136.91k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 21
  • 点击次数: 0
  • 依赖项目数: 12
  • 推荐数: 0

GitHub 信息

  • Stars: 21
  • Watchers: 4
  • Forks: 10
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-08-15