Add base routes for managing servers as a client
This commit is contained in:
parent
9a32b9fd03
commit
cef3e4ced4
18 changed files with 262 additions and 270 deletions
|
@ -32,6 +32,11 @@ class ApiSubstituteBindings extends SubstituteBindings
|
|||
'user' => User::class,
|
||||
];
|
||||
|
||||
/**
|
||||
* @var \Illuminate\Routing\Router
|
||||
*/
|
||||
protected $router;
|
||||
|
||||
/**
|
||||
* Perform substitution of route parameters without triggering
|
||||
* a 404 error if a model is not found.
|
||||
|
@ -45,6 +50,10 @@ class ApiSubstituteBindings extends SubstituteBindings
|
|||
$route = $request->route();
|
||||
|
||||
foreach (self::$mappings as $key => $model) {
|
||||
if (! is_null($this->router->getBindingCallback($key))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->router->model($key, $model, function () use ($request) {
|
||||
$request->attributes->set('is_missing_model', true);
|
||||
});
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
|
||||
namespace Pterodactyl\Http\Middleware\Api\Client;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Container\Container;
|
||||
use Pterodactyl\Http\Middleware\Api\ApiSubstituteBindings;
|
||||
use Pterodactyl\Exceptions\Repository\RecordNotFoundException;
|
||||
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
|
||||
|
||||
class SubstituteClientApiBindings extends ApiSubstituteBindings
|
||||
{
|
||||
/**
|
||||
* Perform substitution of route parameters without triggering
|
||||
* a 404 error if a model is not found.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
// Override default behavior of the model binding to use a specific table
|
||||
// column rather than the default 'id'.
|
||||
$this->router->bind('server', function ($value) use ($request) {
|
||||
try {
|
||||
return Container::getInstance()->make(ServerRepositoryInterface::class)->findFirstWhere([
|
||||
['uuidShort', '=', $value],
|
||||
]);
|
||||
} catch (RecordNotFoundException $ex) {
|
||||
$request->attributes->set('is_missing_model', true);
|
||||
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
return parent::handle($request, $next);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue