This repository has been archived on 2025-02-26. You can view files and clone it, but cannot push or open issues or pull requests.
szurubooru/src/Routes/Comments/EditComment.php
2014-11-22 12:44:45 +01:00

58 lines
1.6 KiB
PHP

<?php
namespace Szurubooru\Routes\Comments;
use Szurubooru\Controllers\ViewProxies\CommentViewProxy;
use Szurubooru\Controllers\ViewProxies\PostViewProxy;
use Szurubooru\Helpers\InputReader;
use Szurubooru\Privilege;
use Szurubooru\Services\CommentService;
use Szurubooru\Services\PostService;
use Szurubooru\Services\PrivilegeService;
class EditComment extends AbstractCommentRoute
{
private $privilegeService;
private $postService;
private $commentService;
private $commentViewProxy;
private $postViewProxy;
private $inputReader;
public function __construct(
PrivilegeService $privilegeService,
PostService $postService,
CommentService $commentService,
CommentViewProxy $commentViewProxy,
PostViewProxy $postViewProxy,
InputReader $inputReader)
{
$this->privilegeService = $privilegeService;
$this->postService = $postService;
$this->commentService = $commentService;
$this->commentViewProxy = $commentViewProxy;
$this->postViewProxy = $postViewProxy;
$this->inputReader = $inputReader;
}
public function getMethods()
{
return ['PUT'];
}
public function getUrl()
{
return '/api/comments/:commentId';
}
public function work($args)
{
$comment = $this->commentService->getById($args['commentId']);
$this->privilegeService->assertPrivilege(
($comment->getUser() && $this->privilegeService->isLoggedIn($comment->getUser()))
? Privilege::EDIT_OWN_COMMENTS
: Privilege::EDIT_ALL_COMMENTS);
$comment = $this->commentService->updateComment($comment, $this->inputReader->text);
return $this->commentViewProxy->fromEntity($comment, $this->getCommentsFetchConfig());
}
}