ReflectionUtils
in package
Just another place to put static functions.
..
Table of Contents
Methods
- castTypeSoftly() : mixed
- Cast the $value to the preferred $type (if we're fairly confident).
- findMethodHelpers() : iterable<string|int, mixed>
- Find any methods in this class which match the given prefix.
- findStandardProperties() : iterable<string|int, mixed>
- Get a list of standard properties which can be written+read by outside callers.
- getCodeDocs() : array<string|int, mixed>
- getTraits() : array<string|int, string>
- List all traits used by a class and its parents.
- isMethodDeprecated() : bool
- Check if a class method is deprecated
- parseDocBlock() : array<string|int, mixed>
Methods
castTypeSoftly()
Cast the $value to the preferred $type (if we're fairly confident).
public
static castTypeSoftly(mixed $value, array<string|int, mixed> $paramInfo) : mixed
This is like PHP's settype()
but totally not. It only casts in narrow circumstances.
This reflects an opinion that some castings are better than others.
These will be converted:
cast('123', 'int') => 123 cast('123.4', 'float') => 123.4 cast('0', 'bool') => FALSE cast(1, 'bool') => TRUE
However, a string like 'hello' will never cast to bool, int, or float -- because that's a senseless request. We'll leave that to someone else to figure.
Parameters
- $value : mixed
- $paramInfo : array<string|int, mixed>
Return values
mixed —If the $value is agreeable to casting according to a type-rule from $paramInfo, then we return the converted value. Otherwise, return the original value.
findMethodHelpers()
Find any methods in this class which match the given prefix.
public
static findMethodHelpers(string $class, string $prefix) : iterable<string|int, mixed>
Parameters
- $class : string
- $prefix : string
Return values
iterable<string|int, mixed>findStandardProperties()
Get a list of standard properties which can be written+read by outside callers.
public
static findStandardProperties(string $class) : iterable<string|int, mixed>
Parameters
- $class : string
Return values
iterable<string|int, mixed>getCodeDocs()
public
static getCodeDocs(Reflector|ReflectionClass $reflection[, string $type = NULL ][, array<string|int, mixed> $vars = [] ]) : array<string|int, mixed>
Parameters
- $reflection : Reflector|ReflectionClass
- $type : string = NULL
-
If we are not reflecting the class itself, specify "Method", "Property", etc.
- $vars : array<string|int, mixed> = []
-
Variable substitutions to perform in the docblock
Return values
array<string|int, mixed>getTraits()
List all traits used by a class and its parents.
public
static getTraits(object|string $class) : array<string|int, string>
Parameters
- $class : object|string
Return values
array<string|int, string>isMethodDeprecated()
Check if a class method is deprecated
public
static isMethodDeprecated(string $className, string $methodName) : bool
Parameters
- $className : string
- $methodName : string
Tags
Return values
boolparseDocBlock()
public
static parseDocBlock(string $comment) : array<string|int, mixed>
Parameters
- $comment : string