Documentation

Reflect
in package

I guess this is useful.

Table of Contents

Constants

RE_DOCTYPE  : mixed = '/@([a-zA-Z]\w+)([^\n\*]+)/'
Matching `@thing description`
RE_METHOD  : mixed = '/@method\s([a-zA-Z0-9_\|]+)\s+([a-zA-Z0-9_]+)\...
Matching `@method return name(params)`
RE_PARAM  : mixed = '/@param\s([a-zA-Z0-9_\|]+)\s+\$([a-zA-Z0-9_]+)...
Matching `@param type $name description`
RE_RETURN  : mixed = '/@return\s([a-zA-Z0-9_\|]+)\s*([^\n\*]+)/'
Matching `@return type description`

Methods

getDocDefinitions()  : array<string|int, mixed>
Get a list of doc comment definitions.
getDocDescription()  : string
Get a tidy copy of a doc comment.
getDocParameters()  : array<string|int, mixed>
Get the params and return types from a doc comment.
getDocTag()  : array<string|int, string>
Get a single set of doc tags.
getDocTags()  : array<string|int, array<string|int, mixed>>
Get a set of `@tags` within a doc comment.
getMethodDefinition()  : string
Get a php-ish string version of a method.
getMethods()  : array<string|int, mixed>
Get a list of method names and their parameters.
getMethodTags()  : array<string|int, array<string|int, mixed>>
Get a set of `@tags` within a doc comment.
getParameterDefinition()  : string
Get a php-ish string version of a parameter.
getParameters()  : array<string|int, mixed>
getProperties()  : array<string|int, mixed>
Get public properties of an object.
getTypeName()  : string
isStaticCallable()  : bool
Is this callable in a static way?
loadAllClasses()  : Generator<string|int, string>
Find all the classes in a list of directories.
loadClasses()  : Generator<string|int, string>
Find all the classes in a directory, with a filter!

Constants

RE_DOCTYPE

Matching `@thing description`

public mixed RE_DOCTYPE = '/@([a-zA-Z]\w+)([^\n\*]+)/'

RE_METHOD

Matching `@method return name(params)`

public mixed RE_METHOD = '/@method\s([a-zA-Z0-9_\|]+)\s+([a-zA-Z0-9_]+)\s*\([^)]+\)/'

RE_PARAM

Matching `@param type $name description`

public mixed RE_PARAM = '/@param\s([a-zA-Z0-9_\|]+)\s+\$([a-zA-Z0-9_]+)\s*([^\n\*]*?)/'

RE_RETURN

Matching `@return type description`

public mixed RE_RETURN = '/@return\s([a-zA-Z0-9_\|]+)\s*([^\n\*]+)/'

Methods

getDocDefinitions()

Get a list of doc comment definitions.

public static getDocDefinitions(string $comment) : array<string|int, mixed>

These can be anything you like.

Special parsing for @param + and @return ids.

TODO Parsing for @method ids.

Parameters
$comment : string
Return values
array<string|int, mixed> —

[id, type?, name?, description]

getDocDescription()

Get a tidy copy of a doc comment.

public static getDocDescription(string $comment) : string

This strips any asterisks, doctype parameters, and newlines.

Parameters
$comment : string
Return values
string

getDocParameters()

Get the params and return types from a doc comment.

public static getDocParameters(string $comment) : array<string|int, mixed>

The special '__return' key will contain the return type.

Parameters
$comment : string
Return values
array<string|int, mixed> —

[name => type]

getDocTag()

Get a single set of doc tags.

public static getDocTag(string $doc, string $tag) : array<string|int, string>

Shorthand for getDocTags($doc, ['tag'])['tag'].

Parameters
$doc : string
$tag : string
Return values
array<string|int, string>

getDocTags()

Get a set of `@tags` within a doc comment.

public static getDocTags(string $doc[, array<string|int, mixed> $filter = [] ]) : array<string|int, array<string|int, mixed>>

Filtering tags will match the tag name.

Parameters
$doc : string
$filter : array<string|int, mixed> = []
Return values
array<string|int, array<string|int, mixed>> —

[ tag => value[] ]

getMethodDefinition()

Get a php-ish string version of a method.

public static getMethodDefinition(ReflectionMethod $method[, array<string|int, string> $fallbacks = null ]) : string
Parameters
$method : ReflectionMethod
$fallbacks : array<string|int, string> = null

[name => class_name]

Return values
string

getMethods()

Get a list of method names and their parameters.

public static getMethods(string $class[, string|null $filter = null ]) : array<string|int, mixed>

Note, these are only the public methods of a class.

Parameters
$class : string
$filter : string|null = null

regex filter

Return values
array<string|int, mixed>

getMethodTags()

Get a set of `@tags` within a doc comment.

public static getMethodTags(string $doc[, array<string|int, mixed> $filter = [] ]) : array<string|int, array<string|int, mixed>>

use getDocTags()

Filtering tags will match the tag name.

Parameters
$doc : string
$filter : array<string|int, mixed> = []
Return values
array<string|int, array<string|int, mixed>> —

[ tag => value[] ]

getParameterDefinition()

Get a php-ish string version of a parameter.

public static getParameterDefinition(ReflectionParameter $parameter[, string|null $fallback = null ]) : string
Parameters
$parameter : ReflectionParameter
$fallback : string|null = null
Return values
string

getParameters()

public static getParameters(ReflectionFunctionAbstract|array<string|int, string>|string $function[, array<string|int, string>|null $fallbacks = null ]) : array<string|int, mixed>
Parameters
$function : ReflectionFunctionAbstract|array<string|int, string>|string
$fallbacks : array<string|int, string>|null = null
Return values
array<string|int, mixed>

getProperties()

Get public properties of an object.

public static getProperties(object $target[, bool|int|null $flags = true ]) : array<string|int, mixed>

Because PHP lacks a IS_NOT_STATIC flag, this method will treat an absence of the IS_STATIC flag to mean "Don't include static properties". Conversely, when specified the flag will restrict results to include only static properties. The exception is when no flags are specified, i.e. 0 - where all properties are included, static or otherwise.

Note, there is value to NOT using get_object_vars and using this wrapper instead, even though it uses get_object_vars itself. From this external context it will only include public properties. If used from within an object it includes both protected + private properties.

Parameters
$target : object
$flags : bool|int|null = true
  • true: use the iterator, if available (otherwise get_object_vars)
  • false: use get_object_vars
  • int: enum ReflectionProperty::IS modifier types
Return values
array<string|int, mixed>

getTypeName()

public static getTypeName(ReflectionType|null $type[, string|null $fallback = null ]) : string
Parameters
$type : ReflectionType|null
$fallback : string|null = null
Return values
string

isStaticCallable()

Is this callable in a static way?

public static isStaticCallable(array<string|int, mixed>|string $callable) : bool

is_callable() handles this just fine.

Provide an array like: [self::class, 'methodName'] Or a string like: ns\to\Class::methodName

Parameters
$callable : array<string|int, mixed>|string
Tags
phpstan-assert-if-true

callable $callable

Return values
bool

loadAllClasses()

Find all the classes in a list of directories.

public static loadAllClasses(array<string|int, string> $paths[, string|null $filter = null ]) : Generator<string|int, string>

This is not recursive.

Parameters
$paths : array<string|int, string>
$filter : string|null = null
Tags
params

string $filter A full namespaced class name

Return values
Generator<string|int, string>

loadClasses()

Find all the classes in a directory, with a filter!

public static loadClasses(string $path[, string $filter = null ]) : Generator<string|int, string>

This is not recursive.

Yes, this cheats the autoloader. Idk how to do this otherwise. This relies heavily on PSR-4 - if anything is out of place it won't pick it up. I would think nested namespaces would also fail here too.

This actually loads (require_once) the class. Use this carefully.

Parameters
$path : string
$filter : string = null

A full namespaced class name

Return values
Generator<string|int, string>
On this page

Search results