Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Using Better Reflection to get details on classes in multiple directories
<?php
use Roave\BetterReflection\BetterReflection;
use Roave\BetterReflection\Reflector\ClassReflector;
use Roave\BetterReflection\SourceLocator\Type\DirectoriesSourceLocator;
require __DIR__ . '/vendor/autoload.php';
$refSubscriptions = [];
$astLocator = (new BetterReflection())->astLocator();
$directoriesSourceLocator = new DirectoriesSourceLocator([__DIR__ . '/src/Components'], $astLocator);
$reflector = new ClassReflector($directoriesSourceLocator);
foreach ($reflector->getAllClasses() as $class) {
echo sprintf("%s (%s)\n", $class->getName(), $class->getNamespaceName());
foreach ($class->getProperties() as $prop) {
if (!$prop->isPublic()) {
continue;
}
$dockBlock = $prop->getDocComment();
$propStrings = $prop->getDocBlockTypeStrings();
$nullable = in_array('null', $propStrings);
$removable = strstr($dockBlock, '@removable') !== false;
if (preg_match('/@on (?P<class>.*)::(?P<property>.*)/i', $dockBlock, $matches)) {
$refSubscriptions[$matches['class']][$matches['property']] = [
'prop' => $prop->getName(),
'value' => ''
];
}
if (($key = array_search('null', $propStrings)) !== false) {
unset($propStrings[$key]);
}
echo sprintf("\t%s (%s) %s\n", $prop->getName(), join(', ', $propStrings), $nullable ? '🤫' : '');
foreach ($prop->getDocBlockTypes() as $propType) {
//var_dump($propType);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.