Browse Source

Dep injection

imwald
Nuša Pukšič 3 months ago
parent
commit
242449c14f
  1. 6
      src/Util/CommonMark/Converter.php
  2. 10
      src/Util/CommonMark/NostrSchemeExtension/NostrSchemeExtension.php

6
src/Util/CommonMark/Converter.php

@ -6,6 +6,7 @@ use App\Service\NostrClient; @@ -6,6 +6,7 @@ use App\Service\NostrClient;
use App\Service\RedisCacheService;
use App\Util\CommonMark\ImagesExtension\RawImageLinkExtension;
use App\Util\CommonMark\NostrSchemeExtension\NostrSchemeExtension;
use App\Util\NostrKeyUtil;
use League\CommonMark\Environment\Environment;
use League\CommonMark\Exception\CommonMarkException;
use League\CommonMark\Extension\Autolink\AutolinkExtension;
@ -29,7 +30,8 @@ readonly class Converter @@ -29,7 +30,8 @@ readonly class Converter
public function __construct(
private RedisCacheService $redisCacheService,
private NostrClient $nostrClient,
private TwigEnvironment $twig
private TwigEnvironment $twig,
private NostrKeyUtil $nostrKeyUtil
){}
/**
@ -68,7 +70,7 @@ readonly class Converter @@ -68,7 +70,7 @@ readonly class Converter
$environment->addExtension(new TableExtension());
$environment->addExtension(new StrikethroughExtension());
// create a custom extension, that handles nostr mentions
$environment->addExtension(new NostrSchemeExtension($this->redisCacheService, $this->nostrClient, $this->twig));
$environment->addExtension(new NostrSchemeExtension($this->redisCacheService, $this->nostrClient, $this->twig, $this->nostrKeyUtil));
$environment->addExtension(new SmartPunctExtension());
$environment->addExtension(new EmbedExtension());
$environment->addRenderer(Embed::class, new HtmlDecorator(new EmbedRenderer(), 'div', ['class' => 'embedded-content']));

10
src/Util/CommonMark/NostrSchemeExtension/NostrSchemeExtension.php

@ -4,6 +4,7 @@ namespace App\Util\CommonMark\NostrSchemeExtension; @@ -4,6 +4,7 @@ namespace App\Util\CommonMark\NostrSchemeExtension;
use App\Service\NostrClient;
use App\Service\RedisCacheService;
use App\Util\NostrKeyUtil;
use League\CommonMark\Environment\EnvironmentBuilderInterface;
use League\CommonMark\Extension\ExtensionInterface;
use Twig\Environment;
@ -14,16 +15,17 @@ class NostrSchemeExtension implements ExtensionInterface @@ -14,16 +15,17 @@ class NostrSchemeExtension implements ExtensionInterface
public function __construct(
private readonly RedisCacheService $redisCacheService,
private readonly NostrClient $nostrClient,
private readonly Environment $twig
private readonly Environment $twig,
private readonly NostrKeyUtil $nostrKeyUtil
) {
}
public function register(EnvironmentBuilderInterface $environment): void
{
$environment
->addInlineParser(new NostrMentionParser($this->redisCacheService), 200)
->addInlineParser(new NostrSchemeParser($this->redisCacheService, $this->nostrClient, $this->twig), 199)
->addInlineParser(new NostrRawNpubParser($this->redisCacheService), 198)
->addInlineParser(new NostrMentionParser($this->redisCacheService, $this->nostrKeyUtil), 200)
->addInlineParser(new NostrSchemeParser($this->redisCacheService, $this->nostrClient, $this->twig, $this->nostrKeyUtil), 199)
->addInlineParser(new NostrRawNpubParser($this->redisCacheService, $this->nostrKeyUtil), 198)
->addRenderer(NostrSchemeData::class, new NostrEventRenderer(), 2)
->addRenderer(NostrEmbeddedCard::class, new NostrEmbeddedCardRenderer(), 3)

Loading…
Cancel
Save