2018-03-17 13:55:39 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Support;
|
|
|
|
|
2018-03-18 07:07:13 +08:00
|
|
|
use Log;
|
2018-03-20 09:50:40 +08:00
|
|
|
use Symfony\Component\ClassLoader\ClassMapGenerator;
|
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
|
|
|
|
* @package App\Support
|
|
|
|
*/
|
2018-03-17 13:55:39 +08:00
|
|
|
class ClassLoader
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @param $path
|
|
|
|
* @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 {
|
|
|
|
$klass = new $cl;
|
|
|
|
} 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;
|
|
|
|
}
|
|
|
|
}
|