phpactor / worse-reflection
一个比更好反射器还差的懒AST反射器
0.6.0
2024-08-09 07:17 UTC
Requires
- php: ^8.1
- amphp/amp: ^2.6
- jetbrains/phpstorm-stubs: *
- phpactor/docblock-parser: ^0.2.0
- phpactor/text-document: ^2.1.0
- phpactor/tolerant-php-parser: dev-main
- psr/log: ^1.0||^2.0||^3.0
Requires (Dev)
- ergebnis/composer-normalize: ^2.0
- friendsofphp/php-cs-fixer: ^3.0
- phpactor/class-to-file: ~0.5.0
- phpactor/test-utils: ^1.1.5
- phpbench/phpbench: dev-master
- phpspec/prophecy-phpunit: ^2.0
- phpstan/phpstan: ^1.0
- phpunit/phpunit: ^9.0
- symfony/filesystem: ^6.0
- symfony/var-dumper: ^5.2
- 0.6.0
- dev-master / 0.5.x-dev
- 0.5.4
- 0.5.3
- 0.5.2
- 0.5.1
- 0.5.0
- 0.4.10
- 0.4.9
- 0.4.8
- 0.4.7
- 0.4.6
- 0.4.5
- 0.4.4
- 0.4.3
- 0.4.2
- 0.4.1
- 0.4.0
- 0.3.1
- 0.3.0
- 0.2.0
- 0.1.0
- dev-new-docblock-parser
- dev-new-types-type-factory
- dev-enum
- dev-cache-exceptions
- dev-analyze
- dev-list-foreach
- dev-mixins
- dev-null-ast-node
- dev-ci-phpbench
- dev-virtual-method-declaration
- dev-foobar
- dev-maestro
- dev-anonymous_class_fix
- dev-refactoring
- dev-resolver_extraction
- dev-validate_class_name
- dev-parameter_inferred_type
- dev-phpstan_docblock
- dev-performance_fixes
- dev-typeobject
- dev-docblock
- dev-frame_tree
- dev-phpbench_reports
- dev-namespace_reflection
- dev-accept_sourcecode_as_argument
- dev-scf-filesystem
- dev-property_type
- dev-node_reflector
- dev-explicit_reflector_methods
- dev-more_symbols
- dev-phpbench
- dev-traits
- dev-node_resolve_unknown_classes
- dev-service_locator
- dev-stub_locator
- dev-constants
- dev-class_interface_parents
- dev-hotfixes
This package is auto-updated.
Last update: 2024-09-09 07:43:19 UTC
README
此软件包在此处未积极开发,而是在主要的 phpactor 仓库中开发。它偶尔会更新。有关此存储库的任何问题请在此处提出。
此库旨在提供一个轻量级的基于类的AST "反射"库。
不如更好
它受到 BetterReflection 的影响,以下是一些不同之处
- 可以反射变量。
- 不旨在实现内置PHP反射API。
- 使用惊人的 Tolerant Parser。
- 使用PHPStorm存根提供内部类的反射。
它正在开发中,以提供对 Phpactor 内省和重构工具的支持。因此,它由该用例驱动。
如果您需要全面的反射,请使用BetterReflection。如果您需要更快的反射,包括无支持的类型/值流,并且频繁的BC中断,则可以使用此软件包(请注意,我有一段时间没有基准测试BR了,它现在可能更快)。
用法
$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
查看测试以获取更多示例...
贡献
此软件包是开源的,欢迎贡献!请随意在此存储库上打开一个拉取请求。
支持
- 在主要的 Phpactor 仓库中创建一个问题。
- 加入Slack上的
#phpactor
频道 Symfony Devs。