Change snip content text rebuilding to static, allowing a lot cleaner interface getting the lastest text
This commit is contained in:
@ -16,7 +16,7 @@ readonly class SnipContentService
|
||||
public function update(Snip $snip, string $snipContents): void
|
||||
{
|
||||
$parentContent = $snip->getActiveVersion();
|
||||
if ($this->rebuildText($parentContent) === $snipContents) {
|
||||
if (self::rebuildText($parentContent) === $snipContents) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -39,12 +39,7 @@ readonly class SnipContentService
|
||||
$this->em->flush();
|
||||
}
|
||||
|
||||
public function getActiveText(Snip $snip): string
|
||||
{
|
||||
return $this->rebuildText($snip->getActiveVersion());
|
||||
}
|
||||
|
||||
public function rebuildText(?SnipContent $snipContent): string
|
||||
public static function rebuildText(?SnipContent $snipContent): string
|
||||
{
|
||||
if ($snipContent === null) {
|
||||
return '';
|
||||
@ -59,7 +54,7 @@ readonly class SnipContentService
|
||||
}
|
||||
|
||||
return MyersDiff::rebuildBFromCompact(
|
||||
$this->rebuildText($parentContent), $snipContent->getDiff()
|
||||
self::rebuildText($parentContent), $snipContent->getDiff()
|
||||
);
|
||||
}
|
||||
|
||||
@ -80,7 +75,7 @@ readonly class SnipContentService
|
||||
return;
|
||||
}
|
||||
$contentText = $content->getText();
|
||||
$parentText = $this->rebuildText($content->getParent());
|
||||
$parentText = self::rebuildText($content->getParent());
|
||||
$diff = MyersDiff::calculate($parentText, $contentText);
|
||||
$content->setDiff($diff);
|
||||
$content->setText(null);
|
||||
@ -93,7 +88,7 @@ readonly class SnipContentService
|
||||
if ($content->getDiff() === null) {
|
||||
return;
|
||||
}
|
||||
$content->setText($this->rebuildText($content));
|
||||
$content->setText(self::rebuildText($content));
|
||||
$content->setDiff(null);
|
||||
$this->em->persist($content);
|
||||
$this->em->flush();
|
||||
|
@ -17,7 +17,6 @@ class IncludeReferenceStage implements StageInterface
|
||||
#[Autowire(lazy: true)] private readonly SnipRepository $snipRepository,
|
||||
#[Autowire(lazy: true)] private readonly SnipContentRepository $snipContentRepository,
|
||||
#[Autowire(lazy: true)] private readonly GenericParser $pipeline,
|
||||
#[Autowire(lazy: true)] private readonly SnipContentService $snipContentService,
|
||||
) {}
|
||||
|
||||
public function __invoke(mixed $payload): string
|
||||
@ -53,7 +52,7 @@ class IncludeReferenceStage implements StageInterface
|
||||
}
|
||||
|
||||
return $this->pipeline->parseView(
|
||||
$this->snipContentService->rebuildText($content)
|
||||
SnipContentService::rebuildText($content)
|
||||
);
|
||||
}, $payload);
|
||||
}
|
||||
|
@ -15,13 +15,12 @@ class SnipLoader implements LoaderInterface
|
||||
{
|
||||
public function __construct(
|
||||
private readonly SnipRepository $repository,
|
||||
private readonly SnipContentService $contentService,
|
||||
private readonly Security $security,
|
||||
) {}
|
||||
|
||||
public function getSourceContext(string $name): Source
|
||||
{
|
||||
return new Source($this->contentService->getActiveText($this->getFromKey($name)), $name);
|
||||
return new Source($this->getFromKey($name)->getActiveText(), $name);
|
||||
}
|
||||
|
||||
public function getCacheKey(string $name): string
|
||||
|
Reference in New Issue
Block a user