misc_pterodactyl-panel/app/Http/Controllers/Admin/VariableController.php

134 lines
4.8 KiB
PHP
Raw Normal View History

<?php
2017-09-26 02:43:01 +00:00
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
2017-09-26 02:43:01 +00:00
* This software is licensed under the terms of the MIT license.
* https://opensource.org/licenses/MIT
*/
namespace Pterodactyl\Http\Controllers\Admin;
use Prologue\Alerts\AlertsMessageBag;
use Pterodactyl\Models\ServiceOption;
use Pterodactyl\Models\ServiceVariable;
2017-08-12 20:32:34 +00:00
use Pterodactyl\Http\Controllers\Controller;
use Pterodactyl\Http\Requests\Admin\OptionVariableFormRequest;
use Pterodactyl\Repositories\Eloquent\ServiceVariableRepository;
use Pterodactyl\Services\Services\Variables\VariableUpdateService;
2017-08-12 20:32:34 +00:00
use Pterodactyl\Services\Services\Variables\VariableCreationService;
use Pterodactyl\Contracts\Repository\ServiceOptionRepositoryInterface;
class VariableController extends Controller
{
/**
* @var \Prologue\Alerts\AlertsMessageBag
*/
protected $alert;
/**
* @var \Pterodactyl\Services\Services\Variables\VariableCreationService
*/
protected $creationService;
/**
* @var \Pterodactyl\Contracts\Repository\ServiceOptionRepositoryInterface
*/
protected $serviceOptionRepository;
/**
* @var \Pterodactyl\Repositories\Eloquent\ServiceVariableRepository
*/
protected $serviceVariableRepository;
/**
* @var \Pterodactyl\Services\Services\Variables\VariableUpdateService
*/
protected $updateService;
public function __construct(
AlertsMessageBag $alert,
ServiceOptionRepositoryInterface $serviceOptionRepository,
ServiceVariableRepository $serviceVariableRepository,
VariableCreationService $creationService,
VariableUpdateService $updateService
) {
$this->alert = $alert;
$this->creationService = $creationService;
$this->serviceOptionRepository = $serviceOptionRepository;
$this->serviceVariableRepository = $serviceVariableRepository;
$this->updateService = $updateService;
}
/**
* Handles POST request to create a new option variable.
*
2017-08-22 03:10:48 +00:00
* @param \Pterodactyl\Http\Requests\Admin\OptionVariableFormRequest $request
* @param \Pterodactyl\Models\ServiceOption $option
* @return \Illuminate\Http\RedirectResponse
*
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
* @throws \Pterodactyl\Exceptions\Service\ServiceVariable\ReservedVariableNameException
*/
public function store(OptionVariableFormRequest $request, ServiceOption $option)
{
$this->creationService->handle($option->id, $request->normalize());
$this->alert->success(trans('admin/services.variables.notices.variable_created'))->flash();
return redirect()->route('admin.services.option.variables', $option->id);
}
/**
* Display variable overview page for a service option.
*
2017-08-22 03:10:48 +00:00
* @param int $option
* @return \Illuminate\View\View
*/
public function view($option)
{
$option = $this->serviceOptionRepository->getWithVariables($option);
return view('admin.services.options.variables', ['option' => $option]);
}
/**
* Handles POST when editing a configration for a service variable.
*
2017-08-22 03:10:48 +00:00
* @param \Pterodactyl\Http\Requests\Admin\OptionVariableFormRequest $request
* @param \Pterodactyl\Models\ServiceOption $option
* @param \Pterodactyl\Models\ServiceVariable $variable
* @return \Illuminate\Http\RedirectResponse
*
* @throws \Pterodactyl\Exceptions\DisplayException
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
2017-08-13 19:55:09 +00:00
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
* @throws \Pterodactyl\Exceptions\Service\ServiceVariable\ReservedVariableNameException
*/
public function update(OptionVariableFormRequest $request, ServiceOption $option, ServiceVariable $variable)
{
$this->updateService->handle($variable, $request->normalize());
$this->alert->success(trans('admin/services.variables.notices.variable_updated', [
'variable' => $variable->name,
]))->flash();
return redirect()->route('admin.services.option.variables', $option->id);
}
/**
* Delete a service variable from the system.
*
2017-08-22 03:10:48 +00:00
* @param \Pterodactyl\Models\ServiceOption $option
* @param \Pterodactyl\Models\ServiceVariable $variable
* @return \Illuminate\Http\RedirectResponse
*/
public function delete(ServiceOption $option, ServiceVariable $variable)
{
$this->serviceVariableRepository->delete($variable->id);
$this->alert->success(trans('admin/services.variables.notices.variable_deleted', [
'variable' => $variable->name,
]))->flash();
return redirect()->route('admin.services.option.variables', $option->id);
}
}