Implement lexer class for tokenization and replace all line endings by PHP_EOL
This commit is contained in:
45
src/Command/SnipUpdateContentCommand.php
Normal file
45
src/Command/SnipUpdateContentCommand.php
Normal 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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user