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\Interfaces\Service;
use App\Support\ClassLoader;
2018-03-17 12:59:53 +08:00
use Module;
/**
* Class AwardService
* @package App\Services
*/
class AwardService extends Service
2018-03-17 12:59:53 +08:00
{
/**
* Find any of the award classes
* @return \App\Interfaces\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 = [];
# Find the awards in the app/Awards directory
$classes = ClassLoader::getClassesInPath(app_path('/Awards'));
$awards = array_merge($awards, $classes);
2018-03-18 01:17:38 +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);
$awards = array_merge($awards, $classes);
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
}
}