final class CallbackGenerator implements MentionGeneratorInterface
20
{
21
/**
22
* 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
23
*
24
* @var callable(Mention): ?AbstractInline
25
*/
26
private $callback;
27
28
27
public function __construct(callable $callback)
29
{
30
27
$this->callback = $callback;
31
27
}
32
33
27
public function generateMention(Mention $mention): ?AbstractInline
if ($result instanceof AbstractInline && ! ($result instanceof Mention)) {
41
6
return $result;
42
}
43
44
18
if ($result instanceof Mention && $result->hasUrl()) {
45
9
return $mention;
46
}
47
48
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');