super-kernel/tokenizer extracts fully qualified named class-like declarations from PHP source read from a PSR-7
stream. It uses PHP's native tokenizer with parser validation and provides a read-only FileStream for source files
with any file extension.
The component requires psr/http-message for StreamInterface and super-kernel/attribute to bind
ClassNameParser through Provider(ClassNameParserInterface::class). PHP 8.4.27 or later in the 8.4.x series and
ext-tokenizer are execution-environment requirements. PHPUnit and PHP CS Fixer are development-only tools.
use SuperKernel\Tokenizer\ClassNameParser;
use SuperKernel\Tokenizer\Stream\FileStream;
$stream = new FileStream('/srv/project/source.inc');
$classNames = (new ClassNameParser())->parse($stream);
$stream->close();
if ($classNames === false) {
// The stream is unreadable, or its source is parser-rejected or has no named class-like declaration.
}parse() accepts any Psr\Http\Message\StreamInterface. It rewinds a seekable stream and reads it to the end, reads a
non-seekable stream from its current position, and leaves the stream open for its caller. It returns a sorted
non-empty list containing named classes, interfaces, traits, and enums; anonymous classes are ignored. An unreadable
stream, source rejected by PHP's tokenizer parser validation, or source without a named class-like declaration returns
false; these inputs are ordinary parse misses rather than exceptional control flow. Parser validation is limited to
errors surfaced by token_get_all() with TOKEN_PARSE; the component does not run a separate full PHP compilation or
lint pass.
FileStream opens a regular file for reading and throws RuntimeException when the path is not a regular file or the
file cannot be opened. It is read-only, so write() throws RuntimeException.
The component does not scan directories, build classmaps, load classes, cache results, or require a .php suffix. Those
policies belong to its callers.
composer84 validate --strict
composer84 test
composer84 format:check
composer84 format