What am trying to do is use scandir()
to scan a directory and get all the files there, then use the ReflectionClass
to read or access the class.
I was able to get all the files in the directory and assigned it to an array but was unable to read or access the properties
and the methods
using the \ReflectionClass
as it keeps returning
Class App\Controllers\AtController does not exist
This is the code I have so far
// The directory to scan and assign it to a variable
$classControllers = scandir($cur_dir . '/app/Controllers');
// Change to the ReflectionClass to access
chdir($cur_dir . '/app/Controllers/');
// Dump the $classControllers to see if it truly scan the directory
var_dump($classControllers);
$control = '';
// Loop over the $classControllers
foreach($classControllers as $classController){
if($classController != "." && $classController != "..")
{
$classController = str_ireplace(".php", "", $classController);
echo $classController . PHP_EOL;
// Use ReflectionClass to read the class name, methods and properties of each class.
$controllers = new \ReflectionClass("App\\Controllers\\$classController")#App\Controllers is the namespace of the files in the directory;
$controller = $controllers->getName();
$control = substr($controller, 12);
$control = ucfirst($control);
$routeScript .= "\t$control" . "," . PHP_EOL;
}
}
NB: new \ReflectionClass("App\\Controllers\\$classController"); #App\Controllers is the namespace of the files in the directory
Aucun commentaire:
Enregistrer un commentaire