SourceBodyExtractor
in package
Source body extractor class
Recovers a method/function/closure's body as source text by slicing its declaring file between getStartLine()/getEndLine(). Both ReflectionMethod and ReflectionFunction extend ReflectionFunctionAbstract, so one helper serves MethodReflection and FunctionReflection, which previously each carried a near-identical, independently written copy of this logic.
Tags
Table of Contents
Properties
- $fileCache : array<string, array<int, string>>
- Cache of file() results, keyed by file path -- avoids re-reading and re-splitting the same source file once per method when a class with many methods is reflected.
Methods
- extract() : string|null
- Extract a method/function's body as source text
Properties
$fileCache
Cache of file() results, keyed by file path -- avoids re-reading and re-splitting the same source file once per method when a class with many methods is reflected.
protected
static array<string, array<int, string>>
$fileCache
= []
Methods
extract()
Extract a method/function's body as source text
public
static extract(ReflectionFunctionAbstract $reflection, bool $stripBraces) : string|null
Parameters
- $reflection : ReflectionFunctionAbstract
- $stripBraces : bool