sysuser
PREMİUM
- Katılım
- 9 Kas 2025
- Mesajlar
- 174
- Tepki puanı
- 4
- Cinsiyet
- Kadın
Symfony Console ile Özel CLI Komut Yazma
Cron işleri, veri aktarımı veya toplu güncelleme işlemleri için CLI araçları yönetim panelinden çok daha pratik çözümler sunar. Symfony Console bileşeni güçlü ve test edilebilir komutlar oluşturmayı kolaylaştırır.
Komut Sınıfı
PHP:
#[AsCommand(name: 'app:sync-orders', description: 'Siparişleri dış sistemle senkronize eder')]
class SyncOrdersCommand extends Command {
protected function execute(InputInterface $input, OutputInterface $output): int {
$io = new SymfonyStyle($input, $output);
$io->progressStart(100);
// işlem...
$io->progressFinish();
$io->success('Senkronizasyon tamamlandı');
return Command::SUCCESS;
}
}
Kullanım
Bash:
php bin/console app:sync-orders --env=prod
İpuçları
- Command::SUCCESS (0) ve Command::FAILURE (1) dönüş kodlarını mutlaka kullanın; cron izleme araçları bunu okur
- SymfonyStyle ile table(), ask(), confirm() gibi zengin CLI UI'leri kurulabilir
- Komutları unit test ile test etmek için CommandTester sınıfını kullanın