2018-03-17 12:59:53 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Services;
|
|
|
|
|
2019-07-16 03:44:31 +08:00
|
|
|
use App\Contracts\Service;
|
2018-03-17 13:55:39 +08:00
|
|
|
use App\Support\ClassLoader;
|
2019-09-17 01:08:26 +08:00
|
|
|
use Nwidart\Modules\Facades\Module;
|
2018-03-17 12:59:53 +08:00
|
|
|
|
2018-03-20 09:50:40 +08:00
|
|
|
class AwardService extends Service
|
2018-03-17 12:59:53 +08:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Find any of the award classes
|
2018-08-27 00:40:04 +08:00
|
|
|
*
|
2019-07-16 03:44:31 +08:00
|
|
|
* @return \App\Contracts\Award[]
|
2018-03-17 12:59:53 +08:00
|
|
|
*/
|
2018-03-20 09:50:40 +08:00
|
|
|
public function findAllAwardClasses(): array
|
2018-03-17 12:59:53 +08:00
|
|
|
{
|
|
|
|
$awards = [];
|
2018-03-18 01:17:38 +08:00
|
|
|
$formatted_awards = [];
|
2018-03-17 13:55:39 +08:00
|
|
|
|
2018-08-27 00:40:04 +08:00
|
|
|
// Find the awards in the app/Awards directory
|
2018-03-17 13:55:39 +08:00
|
|
|
$classes = ClassLoader::getClassesInPath(app_path('/Awards'));
|
|
|
|
$awards = array_merge($awards, $classes);
|
|
|
|
|
2018-08-27 00:40:04 +08:00
|
|
|
// Look throughout all the other modules, in the module/{MODULE}/Awards directory
|
2018-03-17 12:59:53 +08:00
|
|
|
foreach (Module::all() as $module) {
|
|
|
|
$path = $module->getExtraPath('Awards');
|
2018-03-17 13:55:39 +08:00
|
|
|
$classes = ClassLoader::getClassesInPath($path);
|
2019-04-08 06:35:55 +08:00
|
|
|
|
|
|
|
foreach ($classes as $class) {
|
|
|
|
$awards[] = $class;
|
|
|
|
}
|
2018-03-17 12:59:53 +08:00
|
|
|
}
|
|
|
|
|
2018-03-18 01:17:38 +08:00
|
|
|
foreach ($awards as $award) {
|
|
|
|
$formatted_awards[\get_class($award)] = $award;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $formatted_awards;
|
2018-03-17 12:59:53 +08:00
|
|
|
}
|
|
|
|
}
|