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
						
					
					
						
							783 B
						
					
					
				
			
		
		
	
	
							32 lines
						
					
					
						
							783 B
						
					
					
				| <?php | |
|  | |
| namespace common\modules\blog\services; | |
|  | |
| use common\modules\blog\entities\BlogComment; | |
| use common\modules\blog\forms\BlogCommentForm; | |
| use common\modules\blog\repositories\BlogRepository; | |
| use core\repositories\user\UserRepository; | |
|  | |
| class BlogCommentService | |
| { | |
|     private $posts; | |
|     private $users; | |
|  | |
|     public function __construct(BlogRepository $posts, UserRepository $users) | |
|     { | |
|         $this->posts = $posts; | |
|         $this->users = $users; | |
|     } | |
|  | |
|     public function create($postId, $userId, BlogCommentForm $form): BlogComment | |
|     { | |
|         $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; | |
|     } | |
| } |