You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

32 lines
743 B

<?php
namespace core\services\post;
use core\entities\post\PostComment;
use core\forms\post\PostCommentForm;
use core\repositories\post\PostRepository;
use core\repositories\user\UserRepository;
class PostCommentService
{
private $posts;
private $users;
public function __construct(PostRepository $posts, UserRepository $users)
{
$this->posts = $posts;
$this->users = $users;
}
public function create($postId, $userId, PostCommentForm $form): PostComment
{
$post = $this->posts->get($postId);
$user = $this->users->get($userId);
$comment = $post->addComment($user->id, $form->parentId, $form->text);
$this->posts->save($post);
return $comment;
}
}