Created
January 6, 2020 18:04
-
-
Save amnuts/f28c1c975f2031014536243e50371248 to your computer and use it in GitHub Desktop.
Using Better Reflection to get details on classes in multiple directories
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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