Skip to content

Instantly share code, notes, and snippets.

@asgrim
Created April 2, 2019 12:03
Show Gist options
  • Save asgrim/e2cd7aeb17c88bbd3ebafeeaa8041678 to your computer and use it in GitHub Desktop.
Save asgrim/e2cd7aeb17c88bbd3ebafeeaa8041678 to your computer and use it in GitHub Desktop.
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