| @@ 9-35 (lines=27) @@ | ||
| 6 | use Illuminate\Database\Eloquent\Builder; |
|
| 7 | use Spatie\ServerMonitor\Exceptions\InvalidConfiguration; |
|
| 8 | ||
| 9 | class CheckRepository |
|
| 10 | { |
|
| 11 | public static function allThatShouldRun(): CheckCollection |
|
| 12 | { |
|
| 13 | $checks = self::query()->get()->filter->shouldRun(); |
|
| 14 | ||
| 15 | return new CheckCollection($checks); |
|
| 16 | } |
|
| 17 | ||
| 18 | protected static function query(): Builder |
|
| 19 | { |
|
| 20 | $modelClass = static::determineCheckModel(); |
|
| 21 | ||
| 22 | return $modelClass::enabled(); |
|
| 23 | } |
|
| 24 | ||
| 25 | public static function determineCheckModel(): string |
|
| 26 | { |
|
| 27 | $monitorModel = config('server-monitor.check_model') ?? Check::class; |
|
| 28 | ||
| 29 | if (! is_a($monitorModel, Check::class, true)) { |
|
| 30 | throw InvalidConfiguration::checkModelIsNotValid($monitorModel); |
|
| 31 | } |
|
| 32 | ||
| 33 | return $monitorModel; |
|
| 34 | } |
|
| 35 | } |
|
| 36 | ||
| @@ 10-43 (lines=34) @@ | ||
| 7 | use Illuminate\Database\Eloquent\Collection; |
|
| 8 | use Spatie\ServerMonitor\Exceptions\InvalidConfiguration; |
|
| 9 | ||
| 10 | class HostRepository |
|
| 11 | { |
|
| 12 | public static function all(): Collection |
|
| 13 | { |
|
| 14 | $hosts = self::query()->get(); |
|
| 15 | ||
| 16 | return $hosts; |
|
| 17 | } |
|
| 18 | ||
| 19 | protected static function query(): Builder |
|
| 20 | { |
|
| 21 | $modelClass = static::determineHostModel(); |
|
| 22 | ||
| 23 | return $modelClass::query(); |
|
| 24 | } |
|
| 25 | ||
| 26 | /** |
|
| 27 | * Determine the host model class name. |
|
| 28 | * |
|
| 29 | * @return string |
|
| 30 | * |
|
| 31 | * @throws \Spatie\ServerMonitor\Exceptions\InvalidConfiguration |
|
| 32 | */ |
|
| 33 | public static function determineHostModel(): string |
|
| 34 | { |
|
| 35 | $hostModel = config('server-monitor.host_model') ?? Host::class; |
|
| 36 | ||
| 37 | if (! is_a($hostModel, Host::class, true)) { |
|
| 38 | throw InvalidConfiguration::hostModelIsNotValid($hostModel); |
|
| 39 | } |
|
| 40 | ||
| 41 | return $hostModel; |
|
| 42 | } |
|
| 43 | } |
|
| 44 | ||