mirror of
https://github.com/MrUnknownDE/panel.git
synced 2026-04-19 06:43:45 +02:00
Add nests & eggs
Cleanup middleware handling and parameters on controllers...
This commit is contained in:
@@ -3,11 +3,33 @@
|
||||
namespace Pterodactyl\Http\Middleware\Api;
|
||||
|
||||
use Closure;
|
||||
use Pterodactyl\Models\Egg;
|
||||
use Pterodactyl\Models\Nest;
|
||||
use Pterodactyl\Models\Node;
|
||||
use Pterodactyl\Models\Server;
|
||||
use Pterodactyl\Models\Database;
|
||||
use Pterodactyl\Models\Location;
|
||||
use Pterodactyl\Models\Allocation;
|
||||
use Illuminate\Routing\Middleware\SubstituteBindings;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
|
||||
class ApiSubstituteBindings extends SubstituteBindings
|
||||
{
|
||||
/**
|
||||
* Mappings to automatically assign route parameters to a model.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected static $mappings = [
|
||||
'allocation' => Allocation::class,
|
||||
'database' => Database::class,
|
||||
'egg' => Egg::class,
|
||||
'location' => Location::class,
|
||||
'nest' => Nest::class,
|
||||
'node' => Node::class,
|
||||
'server' => Server::class,
|
||||
];
|
||||
|
||||
/**
|
||||
* Perform substitution of route parameters without triggering
|
||||
* a 404 error if a model is not found.
|
||||
@@ -20,6 +42,10 @@ class ApiSubstituteBindings extends SubstituteBindings
|
||||
{
|
||||
$route = $request->route();
|
||||
|
||||
foreach (self::$mappings as $key => $model) {
|
||||
$this->router->model($key, $model);
|
||||
}
|
||||
|
||||
$this->router->substituteBindings($route);
|
||||
|
||||
// Attempt to resolve bindings for this route. If one of the models
|
||||
@@ -35,4 +61,14 @@ class ApiSubstituteBindings extends SubstituteBindings
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the registered mappings.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getMappings()
|
||||
{
|
||||
return self::$mappings;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user