clrghouz/app/Classes/FTN.php

65 lines
1.2 KiB
PHP
Raw Normal View History

2019-03-03 14:29:35 +00:00
<?php
namespace App\Classes;
use App\Models\Domain;
2021-06-29 10:43:29 +00:00
2019-03-03 14:29:35 +00:00
abstract class FTN
{
protected ?Domain $domain; // Domain the packet is from
2021-06-29 10:43:29 +00:00
public function __get($key)
{
switch ($key) {
case 'fftn':
return sprintf('%d:%d/%d.%d',
$this->fz,
$this->fn,
$this->ff,
$this->fp,
).($this->domain ? sprintf('@%s',$this->domain->name) : '');
2021-06-29 10:43:29 +00:00
case 'tftn':
return sprintf('%d:%d/%d.%d',
$this->tz,
$this->tn,
$this->tf,
$this->tp,
).($this->domain ? sprintf('@%s',$this->domain->name) : '');
2021-06-29 10:43:29 +00:00
default:
throw new \Exception('Unknown key: '.$key);
}
}
2019-03-03 14:29:35 +00:00
/**
* Determine if a line is a kludge line.
*
* @param string $kludge
* @param string $string
* @return string
*/
protected function kludge(string $kludge,string $string)
{
return (preg_match("/^{$kludge}/",$string))
? chop(preg_replace("/^{$kludge}/",'',$string),"\r")
: FALSE;
}
/**
* This function creates our unpack header
2021-06-29 10:43:29 +00:00
*
* @param array $pack
2019-03-03 14:29:35 +00:00
* @return string
*/
protected static function unpackheader(array $pack): string
2019-03-03 14:29:35 +00:00
{
2021-06-29 10:43:29 +00:00
return join('/',
collect($pack)
->sortBy(function($k,$v) {return $k[0];})
->transform(function($k,$v) {return $k[1].$v;})
->values()
->toArray()
);
2019-03-03 14:29:35 +00:00
}
}