mirror of
https://github.com/MrUnknownDE/panel.git
synced 2026-04-18 14:23:44 +02:00
Update repository base code to be cleaner and make use of PHP 7 features
This commit is contained in:
@@ -1,16 +1,11 @@
|
||||
<?php
|
||||
/**
|
||||
* Pterodactyl - Panel
|
||||
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
|
||||
*
|
||||
* This software is licensed under the terms of the MIT license.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
namespace Pterodactyl\Repositories\Eloquent;
|
||||
|
||||
use Pterodactyl\Models\Location;
|
||||
use Illuminate\Support\Collection;
|
||||
use Pterodactyl\Repositories\Concerns\Searchable;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
use Pterodactyl\Exceptions\Repository\RecordNotFoundException;
|
||||
use Pterodactyl\Contracts\Repository\LocationRepositoryInterface;
|
||||
|
||||
@@ -19,7 +14,9 @@ class LocationRepository extends EloquentRepository implements LocationRepositor
|
||||
use Searchable;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
* Return the model backing this repository.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function model()
|
||||
{
|
||||
@@ -27,44 +24,56 @@ class LocationRepository extends EloquentRepository implements LocationRepositor
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
* Return locations with a count of nodes and servers attached to it.
|
||||
*
|
||||
* @return \Illuminate\Support\Collection
|
||||
*/
|
||||
public function getAllWithDetails()
|
||||
public function getAllWithDetails(): Collection
|
||||
{
|
||||
return $this->getBuilder()->withCount('nodes', 'servers')->get($this->getColumns());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
* Return all of the available locations with the nodes as a relationship.
|
||||
*
|
||||
* @return \Illuminate\Support\Collection
|
||||
*/
|
||||
public function getAllWithNodes()
|
||||
public function getAllWithNodes(): Collection
|
||||
{
|
||||
return $this->getBuilder()->with('nodes')->get($this->getColumns());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
* Return all of the nodes and their respective count of servers for a location.
|
||||
*
|
||||
* @param int $id
|
||||
* @return mixed
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
*/
|
||||
public function getWithNodes($id)
|
||||
public function getWithNodes(int $id): Location
|
||||
{
|
||||
$instance = $this->getBuilder()->with('nodes.servers')->find($id, $this->getColumns());
|
||||
if (! $instance) {
|
||||
try {
|
||||
return $this->getBuilder()->with('nodes.servers')->findOrFail($id, $this->getColumns());
|
||||
} catch (ModelNotFoundException $exception) {
|
||||
throw new RecordNotFoundException;
|
||||
}
|
||||
|
||||
return $instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
* Return a location and the count of nodes in that location.
|
||||
*
|
||||
* @param int $id
|
||||
* @return mixed
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
*/
|
||||
public function getWithNodeCount($id)
|
||||
public function getWithNodeCount(int $id): Location
|
||||
{
|
||||
$instance = $this->getBuilder()->withCount('nodes')->find($id, $this->getColumns());
|
||||
if (! $instance) {
|
||||
try {
|
||||
return $this->getBuilder()->withCount('nodes')->findOrFail($id, $this->getColumns());
|
||||
} catch (ModelNotFoundException $exception) {
|
||||
throw new RecordNotFoundException;
|
||||
}
|
||||
|
||||
return $instance;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user