/
AleksWork
/
diary_plants
Обзор
Документация
Войти
/
AleksWork
/
diary_plants
Код
Пакеты
0
Релизы
0
Аналитика
Безопасность
develop
src/Infrastructure/Console/ConvertCSVCommand.php
53 строки
2 KB
AlexeySerov
Add console and schedle ClearIncidentCommand with worker support
26 май 2026, 18:20
26 май 2026, 18:20
88eba20
Код
Авторство
О чём код?
<?php namespace App\Infrastructure\Console; use App\Domain\Service\Csv\CsvService; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; #[AsCommand( name: self::CONVERT_CSV_COMMAND_NAME, description: self::CONVERT_CSV_DESCRIPTION, )] final class ConvertCSVCommand extends Command { public const string CONVERT_CSV_COMMAND_NAME = 'app:database:convert:csv'; public const string CONVERT_CSV_DESCRIPTION = 'Convert CSV files to corresponding entities'; public function __construct( private readonly string $csvFilePrefix, private readonly CsvService $csvService ) { parent::__construct(); } protected function execute(InputInterface $input, OutputInterface $output): int { $output->write(sprintf("<info> Run command %s </info>\n", self::CONVERT_CSV_COMMAND_NAME )); if (!is_dir($this->csvFilePrefix)) { $output->writeln(sprintf("<error>Директория не найдена: %s</error>", $this->csvFilePrefix)); return Command::FAILURE; } // Get all entries (files and directories) $allEntries = scandir($this->csvFilePrefix); // Filter out '.' (current directory) and '..' (parent directory) $files = array_diff($allEntries, array('.', '..')); // Print the list of files $count = 0; foreach ($files as $file) { $count = $this->csvService->process($this->csvFilePrefix . $file); $output->write(sprintf("<info> From file %s %d records were created</info>\n", $file, $count)); } return self::SUCCESS; } }