2018-03-17 13:55:39 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Support;
|
|
|
|
|
2018-09-21 03:08:42 +08:00
|
|
|
use Composer\Autoload\ClassMapGenerator;
|
2018-03-18 07:07:13 +08:00
|
|
|
use Log;
|
2018-03-17 13:55:39 +08:00
|
|
|
|
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
|
|
|
|
*/
|
2018-03-17 13:55:39 +08:00
|
|
|
class ClassLoader
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @param $path
|
2018-08-27 00:40:04 +08:00
|
|
|
*
|
2018-03-17 13:55:39 +08:00
|
|
|
* @return array
|
|
|
|
*/
|
2018-03-20 09:50:40 +08:00
|
|
|
public static function getClassesInPath($path): array
|
2018-03-17 13:55:39 +08:00
|
|
|
{
|
|
|
|
if (!file_exists($path)) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
2018-03-18 07:07:42 +08:00
|
|
|
$classes = [];
|
2018-03-17 13:55:39 +08:00
|
|
|
$all_classes = array_keys(ClassMapGenerator::createMap($path));
|
|
|
|
foreach ($all_classes as $cl) {
|
2018-03-18 07:07:13 +08:00
|
|
|
try {
|
2018-08-27 00:40:04 +08:00
|
|
|
$klass = new $cl();
|
2018-03-18 07:07:13 +08:00
|
|
|
} catch (\Exception $e) {
|
2018-03-20 09:50:40 +08:00
|
|
|
Log::error('Error loading class: '.$e->getMessage());
|
2018-03-18 07:07:13 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2018-03-17 13:55:39 +08:00
|
|
|
$classes[] = $klass;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $classes;
|
|
|
|
}
|
|
|
|
}
|