phpvms/app/Support/ClassLoader.php

41 lines
837 B
PHP
Raw Normal View History

<?php
namespace App\Support;
use Composer\Autoload\ClassMapGenerator;
use Log;
2018-04-07 06:23:55 +08:00
/**
* Class find/load related functionality. Is used to find
* the award classes right now that might be in a module
*/
class ClassLoader
{
/**
* @param $path
2018-08-27 00:40:04 +08:00
*
* @return array
*/
public static function getClassesInPath($path): array
{
if (!file_exists($path)) {
return [];
}
2018-03-18 07:07:42 +08:00
$classes = [];
$all_classes = array_keys(ClassMapGenerator::createMap($path));
foreach ($all_classes as $cl) {
try {
2018-08-27 00:40:04 +08:00
$klass = new $cl();
} catch (\Exception $e) {
Log::error('Error loading class: '.$e->getMessage());
continue;
}
$classes[] = $klass;
}
return $classes;
}
}