Skip to content

Instantly share code, notes, and snippets.

@acrossoffwest
Created August 20, 2021 08:55
Show Gist options
  • Save acrossoffwest/d0ecfb32cf3b06d0925581263a29588b to your computer and use it in GitHub Desktop.
Save acrossoffwest/d0ecfb32cf3b06d0925581263a29588b to your computer and use it in GitHub Desktop.
<?php
if (!function_exists('load_class_names_from_dir')) {
function load_class_names_from_dir(string $dir): array
{
$files = scandir($dir);
if (!$files) {
return [];
}
return array_filter(array_map(function ($filename) use ($dir) {
$extension = '.php';
if (in_array($filename, ['.', '..']) || !str_contains($filename, $extension)) {
return null;
}
return str_replace($extension, '', $filename);
}, $files));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment