typhoon/formatter
最新稳定版本:0.1.0
Composer 安装命令:
composer require typhoon/formatter
包简介
Thesis Formatter
README 文档
README
A collection of functions for formatting PHP values and code elements into human-readable strings. Useful for error messages, exceptions, and debugging output.
Installation
composer require thesis/formatter
Functions
All functions are in the Thesis\Formatter namespace.
format(mixed $value): string
Formats any PHP value.
format(null); // null format(true); // true format(42); // 42 format("it's fine"); // 'it\'s fine' format([1, 2, 3]); // list{1, 2, 3} format(['a' => 1, 'b' => 2]); // array{a: 1, b: 2} format((object)['x' => 1]); // object{x: 1} format(Status::Active); // Status::Active format(new MyClass()); // MyClass format(fn() => null); // function@src/foo.php:12()
formatClass(string|object $class): string
Formats a class name. Anonymous classes get a readable file:line label.
formatClass(MyClass::class); // MyClass formatClass(new MyClass()); // MyClass formatClass(new class {}); // class@src/foo.php:42
formatFunction(callable $function): string
Formats a callable.
formatFunction('strlen'); // strlen() formatFunction('MyClass::myMethod'); // MyClass::myMethod() formatFunction([MyClass::class, 'myMethod']); // MyClass::myMethod() formatFunction(fn() => null); // function@src/foo.php:12() formatFunction(new MyInvokable()); // MyInvokable()
formatParameter(callable $function, int|string $parameter): string
Formats a parameter reference by index or name.
formatParameter('myFunction', 'value'); // myFunction($value) formatParameter('myFunction', 0); // myFunction($0)
formatProperty(string|object $class, string $property): string
Formats a property reference.
formatProperty(MyClass::class, 'name'); // MyClass::$name formatProperty(new MyClass(), 'name'); // MyClass::$name
Reflection-based functions
Convenient wrappers around the functions above.
| Function | Example output |
|---|---|
formatReflectedClass(\ReflectionClass $class) |
MyClass |
formatReflectedFunction(\ReflectionFunctionAbstract $function) |
MyClass::myMethod() |
formatReflectedParameter(\ReflectionParameter $parameter) |
MyClass::myMethod($param) |
formatReflectedProperty(\ReflectionProperty $property) |
MyClass::$name |
formatReflectedType(?\ReflectionType $type) |
string|int, ?Foo, A&B |
统计信息
- 总下载量: 1.07k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 3
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-05-06