/** * CommentViewModel constructor. * @param Comment $comment */ public function __construct(Comment $comment) { $this->comment = $comment; preg_match_all('/(?:[^\\.,?!])[\\.,?!]/', $comment->getText(), $matches, PREG_OFFSET_CAPTURE); if (!empty($matches) && count($matches[0]) > 1) { $this->headline = substr($comment->getText(), 0, $matches[0][0][1] + 2); $this->body = substr($comment->getText(), $matches[0][0][1] + 2); } else { $this->headline = 'untitled'; $this->body = $comment->getText(); } }