clrghouz/app/Console/Commands/PacketProcess.php

48 lines
1.0 KiB
PHP
Raw Normal View History

<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Symfony\Component\HttpFoundation\File\File;
use App\Classes\FTN\Packet;
2021-09-06 13:39:32 +00:00
use App\Jobs\MessageProcess as Job;
use App\Models\Zone;
class PacketProcess extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'packet:process {pkt : Packet to process} {zone? : Zone the packet is from}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Process Packet';
/**
* Execute the console command.
*
* @return mixed
* @throws \App\Classes\FTN\InvalidPacketException
*/
public function handle()
{
$f = new File($this->argument('pkt'));
$z = $this->argument('zone') ? Zone::where('zone_id',$this->argument('zone'))->singleOrFail() : NULL;
foreach (Packet::open($f,$z) as $msg) {
// @todo Quick check that the packet should be processed by us.
// @todo validate that the packet's zone is in the domain.
// Dispatch job.
Job::dispatchSync($msg);
}
}
}