Add nests & eggs

Cleanup middleware handling and parameters on controllers...
This commit is contained in:
Dane Everitt 2018-01-27 12:38:56 -06:00
parent de07b3cc7f
commit 8afced3410
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
26 changed files with 737 additions and 446 deletions

View file

@ -3,9 +3,11 @@
namespace Pterodactyl\Http\Requests\Api\Application;
use Pterodactyl\Models\ApiKey;
use Illuminate\Database\Eloquent\Model;
use Pterodactyl\Services\Acl\Api\AdminAcl;
use Illuminate\Foundation\Http\FormRequest;
use Pterodactyl\Exceptions\PterodactylException;
use Pterodactyl\Http\Middleware\Api\ApiSubstituteBindings;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
abstract class ApplicationApiRequest extends FormRequest
@ -73,6 +75,25 @@ abstract class ApplicationApiRequest extends FormRequest
return $this->attributes->get('api_key');
}
/**
* Grab a model from the route parameters. If no model exists under
* the specified key a default response is returned.
*
* @param string $model
* @param mixed $default
* @return mixed
*/
public function getModel(string $model, $default = null)
{
$parameterKey = array_get(array_flip(ApiSubstituteBindings::getMappings()), $model);
if (! is_null($parameterKey)) {
$model = $this->route()->parameter($parameterKey);
}
return $model ?? $default;
}
/*
* Determine if the request passes the authorization check as well
* as the exists check.