clrghouz/app/Traits/ParseNodes.php

32 lines
560 B
PHP
Raw Normal View History

2019-04-27 13:57:39 +00:00
<?php
namespace App\Traits;
use App\Models\Zone;
trait ParseNodes
{
/**
* Parse a seenby or path list and return node models
*/
2019-05-20 07:18:18 +00:00
protected function parse_nodes(Zone $zo,string $line,$create=TRUE)
2019-04-27 13:57:39 +00:00
{
$net = FALSE;
$result = collect();
2019-05-06 12:29:29 +00:00
2019-04-27 13:57:39 +00:00
foreach (explode(' ',$line) as $node)
{
if (preg_match('#/#',$node))
{
list($net,$node) = preg_split('#/#',$node);
}
if (! $net)
throw new \Exception('Missing Net?',$node);
2019-05-20 07:18:18 +00:00
$result->push($this->get_node(['z'=>$zo->id,'n'=>$net,'f'=>$node,'p'=>0],$create));
2019-04-27 13:57:39 +00:00
}
return $result;
}
}