phpvms/app/Support/ClassLoader.php

36 lines
712 B
PHP
Raw Normal View History

<?php
namespace App\Support;
use Symfony\Component\ClassLoader\ClassMapGenerator;
use Log;
class ClassLoader
{
/**
* @param $path
* @return array
*/
public static function getClassesInPath($path)
{
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 {
$klass = new $cl;
} catch (\Exception $e) {
Log::error('Error loading class: ' . $e->getMessage());
continue;
}
$classes[] = $klass;
}
return $classes;
}
}