/** * @group parser */ public function testParseMentionTags() { $this->assertContains('tom', Tags::parseMentionTags('@tom')); $this->assertContains('tom', Tags::parseMentionTags('What about @tom?')); $this->assertContains('tom24', Tags::parseMentionTags('My username is @tom24')); $this->assertContains('tom_24', Tags::parseMentionTags('@tom_24')); $this->assertContains('tom-24', Tags::parseMentionTags('@alice @tom-24')); $this->assertContains('alice', Tags::parseMentionTags('@alice @tom-24')); $this->assertContains('1.JesseChen', Tags::parseMentionTags('@1.JesseChen')); $this->assertContains('alice', Tags::parseMentionTags('@alice.')); $this->assertContains('mobile1.mobile', Tags::parseMentionTags('@mobile1.mobile ')); }
public function handleCommentContent(BaseComment $comment) { $content = $this->escape($comment->getCommentBody()); $replacements = []; $users = []; $mentions = Tags::parseMentionTags($content); foreach ($mentions as $username) { $tag = '@' . $username; if (!isset($replacements[$tag])) { $user = $this->userRepo->findOneByUsername($username); if ($user) { $users[$username] = $user; $replacements[$tag] = "<a data-user-id=\"{$user->getId()}\">{$tag}</a>"; } } } $content = UrlConverter::wrapLinks($content); $content = Tags::replaceMentionTags($content, $replacements); $content = Tags::wrapHashTags($content); $comment->setCommentBodyHtml($content); return $users; }