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