ParserFile
ParserFile
Parses a PHP source file and indexes its top-level declarations.
class ParserFile extends \Hazaar\Parser\PHP\TokenParserExtends: Hazaar\Parser\PHP\TokenParser
The parser stores file metadata and discovered symbols such as constants, functions, interfaces, classes, and traits.
Properties
source
Absolute path to the parsed source file.
private string $sourceType: string
size
File size in bytes.
private int $sizeType: int
constants
Top-level constants discovered in the file.
private array $constantsType: array
functions
Top-level functions discovered in the file.
private array $functionsType: array
interfaces
Interface declarations discovered in the file.
private array $interfacesType: array
classes
Class declarations discovered in the file.
private array $classesType: array
traits
Trait declarations discovered in the file.
private array $traitsType: array
enums
Enum declarations discovered in the file.
private array $enumsType: array
uses
Import map from top-level use declarations.
private array $usesType: array
Keyed by the imported short name/alias, valued by the fully-qualified name (with a leading \) it resolves to. Populated from use X\Y\Z;, use X\Y\Z as Alias;, and grouped use X\Y\{Z, W as V}; declarations. use function/use const imports are not class references and are not included.
Methods
__construct
Creates a parser instance and immediately parses the given file.
public __construct(string $filename): voidParameters
| Parameter | Type | Description |
|---|---|---|
$filename | string | path to a readable PHP source file |
getSource
Returns the source file path.
public getSource(): stringReturns: string
getSize
Returns the size of the file in bytes.
public getSize(): intReturns: int
getConstants
Returns an array of constants defined in the file.
public getConstants(): arrayReturns: array
getFunctions
Returns an array of functions defined in the file.
public getFunctions(): arrayReturns: array
getInterfaces
Returns an array of interfaces defined in the file.
public getInterfaces(): arrayReturns: array
getClasses
Returns an array of classes defined in the file.
public getClasses(): arrayReturns: array
getTraits
Returns an array of traits defined in the file.
public getTraits(): arrayReturns: array
getEnums
Returns an array of enums defined in the file.
public getEnums(): arrayReturns: array
getDocBlock
Returns the file-level docblock marked with @file, when present.
public getDocBlock(): ?DocBlockReturns: Hazaar\Parser\DocBlock
getUses
Returns the file's use import map.
public getUses(): arrayReturns: array
resolveClassName
Resolves a relative, qualified, or fully-qualified name to its
public resolveClassName(string $name, ?ParserNamespace $namespace): stringReturns: string
fully-qualified form, following PHP's own name resolution rules.
A leading \ is returned unchanged. Otherwise the name's first segment is checked against this file's use import map (an import always takes precedence, exactly as it does at compile time); if there's no match, the name is applied to the given namespace, or treated as a global (root-namespace) name when none is given.
Parameters
| Parameter | Type | Description |
|---|---|---|
$name | string | relative, qualified, or fully-qualified name as written in source (e.g. from a {@see} tag) |
$namespace | Hazaar\Parser\PHP\ParserNamespace | namespace context the name was referenced from |
parseUseStatement
Parses a top-level use import statement, starting with the pointer
private parseUseStatement(array $tokens): voidReturns: void
on the T_USE token.
use function ...; and use const ...; imports are skipped since they don't name a class/interface/trait/enum.
Parameters
| Parameter | Type | Description |
|---|---|---|
$tokens | array | token stream passed by reference with the internal pointer used for parsing |
parseUseImports
Parses a comma-separated list of imported names, optionally with as
private parseUseImports(array $tokens, string $prefix, string $terminator): voidReturns: void
aliases and a nested {...} group, and stores each into Hazaar\Parser\PHP\ParserFile::uses. Recurses to parse a grouped use Foo\{Bar, Baz}; declaration, in which case $terminator is } instead of ;.
Parameters
| Parameter | Type | Description |
|---|---|---|
$tokens | array | token stream passed by reference with the internal pointer used for parsing |
$prefix | string | namespace prefix applied to each imported name |
$terminator | string | token that ends this list: ; for a plain statement, } when parsing a nested group |
fixTokenArray
Converts raw token output into parser token objects.
private fixTokenArray(array $tokens): arrayReturns: array
Whitespace tokens are intentionally excluded to simplify higher-level declaration parsing.
Parameters
| Parameter | Type | Description |
|---|---|---|
$tokens | array | raw tokens from token_get_all() |
Generated by Hazaar API Doc Generator on Fri, 04 Sep 2026 23:32:16 +0000