phpvms/app/Services/AwardService.php

42 lines
1.0 KiB
PHP
Raw Normal View History

2018-03-17 12:59:53 +08:00
<?php
namespace App\Services;
use App\Contracts\Service;
use App\Support\ClassLoader;
use Nwidart\Modules\Facades\Module;
2018-03-17 12:59:53 +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
*
* @return \App\Contracts\Award[]
2018-03-17 12:59:53 +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-08-27 00:40:04 +08:00
// Find the awards in the app/Awards directory
$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');
$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
}
}