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/Posts/GetPost.php
2014-11-21 12:45:47 +01:00

41 lines
963 B
PHP

<?php
namespace Szurubooru\Routes\Posts;
use Szurubooru\Controllers\ViewProxies\PostViewProxy;
use Szurubooru\Privilege;
use Szurubooru\Services\PostService;
use Szurubooru\Services\PrivilegeService;
class GetPost extends AbstractPostRoute
{
private $privilegeService;
private $postService;
private $postViewProxy;
public function __construct(
PrivilegeService $privilegeService,
PostService $postService,
PostViewProxy $postViewProxy)
{
$this->privilegeService = $privilegeService;
$this->postService = $postService;
$this->postViewProxy = $postViewProxy;
}
public function getMethods()
{
return ['GET'];
}
public function getUrl()
{
return '/api/posts/:postNameOrId';
}
public function work()
{
$this->privilegeService->assertPrivilege(Privilege::VIEW_POSTS);
$post = $this->postService->getByNameOrId($this->getArgument(postNameOrId));
return $this->postViewProxy->fromEntity($post, $this->getFullFetchConfig());
}
}