Just optimisations
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace App\Traits;
|
||||
|
||||
use Illuminate\Support\Arr;
|
||||
|
||||
use App\Models\{Node,Zone};
|
||||
|
||||
trait GetNode
|
||||
@@ -10,11 +12,19 @@ trait GetNode
|
||||
* Get an FTN record
|
||||
* If the record doesnt exist, we'll create it
|
||||
*/
|
||||
protected function get_node($z,$n,$f,$p=0,$create=TRUE)
|
||||
protected function get_node(array $address,$create=TRUE)
|
||||
{
|
||||
if (! $z=Arr::get($address,'z'))
|
||||
throw new \Exception('Zone cannot be zero');
|
||||
|
||||
$zo = Zone::firstOrCreate(['id'=>$z]);
|
||||
|
||||
$no = Node::firstOrNew(['zone_id'=>$zo->id,'host_id'=>$n,'node_id'=>$f,'point_id'=>$p]);
|
||||
$no = Node::firstOrNew([
|
||||
'zone_id'=>$zo->id,
|
||||
'host_id'=>Arr::get($address,'n'),
|
||||
'node_id'=>Arr::get($address,'f'),
|
||||
'point_id'=>Arr::get($address,'p',0)
|
||||
]);
|
||||
|
||||
if (! $no->exists AND $create)
|
||||
{
|
||||
|
@@ -9,7 +9,7 @@ trait ParseNodes
|
||||
/**
|
||||
* Parse a seenby or path list and return node models
|
||||
*/
|
||||
protected function parse_nodes(Zone $zone,string $line,$create=TRUE)
|
||||
protected function parse_nodes(Zone $zo,string $line,$create=TRUE)
|
||||
{
|
||||
$net = FALSE;
|
||||
$result = collect();
|
||||
@@ -24,7 +24,7 @@ trait ParseNodes
|
||||
if (! $net)
|
||||
throw new \Exception('Missing Net?',$node);
|
||||
|
||||
$result->push($this->get_node($zone->id,$net,$node,0,$create));
|
||||
$result->push($this->get_node(['z'=>$zo->id,'n'=>$net,'f'=>$node,'p'=>0],$create));
|
||||
}
|
||||
|
||||
return $result;
|
||||
|
@@ -1,26 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Traits;
|
||||
|
||||
trait ParseZNFPDomain
|
||||
{
|
||||
private function parse_znfp_domain(string $data,$create=TRUE)
|
||||
{
|
||||
$z = substr($data,0,strpos($data,':'));
|
||||
|
||||
$x = strpos($data,':')+1;
|
||||
$n = substr($data,$x,strpos($data,'/')-$x);
|
||||
|
||||
$x = strpos($data,'/')+1;
|
||||
$f = substr($data,$x,(strpos($data,'.') OR strpos($data,'@')) ?: strlen($data)-$x);
|
||||
|
||||
$x = strpos($data,'.');
|
||||
$p = $x ? substr($data,$x+1,strpos($data,'@') ?: strlen($data)-$x) : 0;
|
||||
|
||||
// @todo We dont handle domain yet.
|
||||
$x = strpos($data,'@');
|
||||
$d = $x ? substr($data,$x+1) : 0;
|
||||
|
||||
return $this->get_node($z,$n,$f,$p,$create);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user