use League\CommonMark\Inline\Element\AbstractInline;
16
17
final class CallbackGenerator implements MentionGeneratorInterface
18
{
19
/**
20
* A callback function which sets the URL on the passed mention and returns the mention, return a new AbstractInline based object or null if the mention is not a match
21
*
22
* @var callable(Mention): ?AbstractInline
23
*/
24
private $callback;
25
26
27
public function __construct(callable $callback)
27
{
28
27
$this->callback = $callback;
29
27
}
30
31
27
public function generateMention(Mention $mention): ?AbstractInline
if ($result instanceof AbstractInline && !($result instanceof Mention)) {
39
6
return $result;
40
}
41
42
18
if ($result instanceof Mention && $result->hasUrl()) {
43
9
return $mention;
44
}
45
46
9
throw new \RuntimeException('CallbackGenerator callable must set the URL on the passed mention and return the mention, return a new AbstractInline based object or null if the mention is not a match');