Implement lexer class for tokenization and replace all line endings by PHP_EOL

This commit is contained in:
Tim
2025-05-10 14:35:11 +02:00
parent 771f354346
commit cda03f7b67
3 changed files with 60 additions and 21 deletions

View File

@ -0,0 +1,45 @@
<?php
namespace App\Command;
use App\Entity\SnipContent;
use App\Repository\SnipContentRepository;
use App\Service\SnipContent\Lexer;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
#[AsCommand(
name: 'app:snip:update-content',
description: 'Update Snip content line endings',
)]
class SnipUpdateContentCommand extends Command
{
public function __construct(
private readonly SnipContentRepository $snipContentRepository,
)
{
parent::__construct();
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);
$qb = $this->snipContentRepository->createQueryBuilder('s');
$qb->where('s.text IS NOT NULL');
$c = 0;
/** @var SnipContent $snipContent */
foreach ($qb->getQuery()->getResult() as $snipContent) {
$text = $snipContent->getText();
$text = Lexer::reconstruct(Lexer::tokenize($text));
$snipContent->setText($text);
$this->snipContentRepository->save($snipContent);
}
return Command::SUCCESS;
}
}