| 148 |
lars |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
declare(strict_types=1);
|
|
|
4 |
|
|
|
5 |
/*
|
|
|
6 |
* This file is part of the league/commonmark package.
|
|
|
7 |
*
|
|
|
8 |
* (c) Colin O'Dell <colinodell@gmail.com>
|
|
|
9 |
*
|
|
|
10 |
* For the full copyright and license information, please view the LICENSE
|
|
|
11 |
* file that was distributed with this source code.
|
|
|
12 |
*/
|
|
|
13 |
|
|
|
14 |
namespace League\CommonMark\Extension\Mention\Generator;
|
|
|
15 |
|
|
|
16 |
use League\CommonMark\Extension\Mention\Mention;
|
|
|
17 |
use League\CommonMark\Node\Inline\AbstractInline;
|
|
|
18 |
|
|
|
19 |
final class StringTemplateLinkGenerator implements MentionGeneratorInterface
|
|
|
20 |
{
|
|
|
21 |
private string $urlTemplate;
|
|
|
22 |
|
|
|
23 |
public function __construct(string $urlTemplate)
|
|
|
24 |
{
|
|
|
25 |
$this->urlTemplate = $urlTemplate;
|
|
|
26 |
}
|
|
|
27 |
|
|
|
28 |
public function generateMention(Mention $mention): ?AbstractInline
|
|
|
29 |
{
|
|
|
30 |
$mention->setUrl(\sprintf($this->urlTemplate, $mention->getIdentifier()));
|
|
|
31 |
|
|
|
32 |
return $mention;
|
|
|
33 |
}
|
|
|
34 |
}
|