entelisteam/lbaf-reflection
最新稳定版本:1.2
Composer 安装命令:
composer require entelisteam/lbaf-reflection
包简介
Lightweight PHP reflection utilities: enum helper, type caster, short class name resolver, cached method parameter lookup.
README 文档
README
Lightweight PHP reflection utilities. No runtime dependencies beyond the PHP standard library.
Install
composer require entelisteam/lbaf-reflection
Requires PHP 8.2 or newer.
What's inside
EntelisTeam\Lbaf\Reflection\TypeCaster
Converts a scalar value to a PHP type by name. Accepts both PHP type names (int, bool, float, string) and legacy gettype() names (integer, boolean, double).
use EntelisTeam\Lbaf\Reflection\TypeCaster; TypeCaster::cast('42', 'int'); // 42 TypeCaster::cast('1', 'bool'); // true TypeCaster::cast('true', 'bool'); // true (case-insensitive) TypeCaster::cast(3.14, 'string'); // "3.14"
EntelisTeam\Lbaf\Reflection\EnumHelper
Constructs an enum case from a value. Works for both backed enums (::from()) and unit enums (constant lookup).
use EntelisTeam\Lbaf\Reflection\EnumHelper; enum Status: string { case Active = 'active'; case Inactive = 'inactive'; } EnumHelper::formatEnumValue(Status::class, 'active'); // Status::Active enum Priority { case Low; case High; } EnumHelper::formatEnumValue(Priority::class, 'Low'); // Priority::Low
For backed enums the value is coerced to the backing type via TypeCaster::cast() first, so '42' will match an int-backed case.
EntelisTeam\Lbaf\Reflection\ClassNameHelper
Returns the short class name (without namespace) with internal caching.
use EntelisTeam\Lbaf\Reflection\ClassNameHelper; ClassNameHelper::getShortClassName(\App\Foo\Bar::class); // "Bar"
EntelisTeam\Lbaf\Reflection\MethodParameters
Cached lookup of method parameters by name.
use EntelisTeam\Lbaf\Reflection\MethodParameters; $method = new ReflectionMethod(MyController::class, 'handle'); MethodParameters::getReflection($method, 'id'); // ReflectionParameter for $id MethodParameters::getTypeName($method, 'id'); // "int" (or "mixed" if untyped) MethodParameters::getList($method); // ['id' => ReflectionParameter, ...]
Throws \InvalidArgumentException if the named parameter does not exist.
License
MIT.
统计信息
- 总下载量: 2
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 5
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-06-11