learning-center/app/Forum/Category/Controllers/DeleteController.php

36 lines
894 B
PHP
Raw Normal View History

2024-09-08 13:48:26 +03:00
<?php
declare(strict_types=1);
namespace App\Forum\Category\Controllers;
use App\Access\Models\AccessChecker\Forum\CategoryAccessChecker;
use App\Access\Models\Forbidden;
use App\Forum\Category\Models\CategoryWriteRepository;
use Ramsey\Uuid\Uuid;
final class DeleteController extends \Phalcon\Mvc\Controller
{
public function mainAction(string $id): void
{
if (!$this->getCategoryAccessChecker()->canDelete()) {
throw new Forbidden();
}
$category = $this->getCategoryRepository()->get(Uuid::fromString($id));
$category->delete();
$this->response->redirect('/');
}
private function getCategoryRepository(): CategoryWriteRepository
{
return new CategoryWriteRepository();
}
private function getCategoryAccessChecker(): CategoryAccessChecker
{
return new CategoryAccessChecker();
}
}