Skip to content

Instantly share code, notes, and snippets.

@asgrim

asgrim/test.php

Created Apr 2, 2019
Embed
What would you like to do?
Get all the classes and functions in a file
<?php
declare(strict_types=1);
use Roave\BetterReflection\BetterReflection;
use Roave\BetterReflection\Reflector\ClassReflector;
use Roave\BetterReflection\Reflector\FunctionReflector;
use Roave\BetterReflection\SourceLocator\Type\SingleFileSourceLocator;
$fileName = 'my-file-with-stuff.php';
$sourceLocator = new SingleFileSourceLocator($fileName, (new BetterReflection())->astLocator());
$classReflector = new ClassReflector($sourceLocator);
$allTheClasses = $classReflector->getAllClasses();
$allTheFunctions = (new FunctionReflector($sourceLocator, $classReflector))->getAllFunctions();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment