31 lines
541 B
PHP
31 lines
541 B
PHP
|
<?php
|
||
|
|
||
|
namespace App\Traits;
|
||
|
|
||
|
use App\Models\Zone;
|
||
|
|
||
|
trait ParseNodes
|
||
|
{
|
||
|
/**
|
||
|
* Parse a seenby or path list and return node models
|
||
|
*/
|
||
|
protected function parse_nodes(Zone $zone,string $line,$create=TRUE)
|
||
|
{
|
||
|
$net = FALSE;
|
||
|
$result = collect();
|
||
|
foreach (explode(' ',$line) as $node)
|
||
|
{
|
||
|
if (preg_match('#/#',$node))
|
||
|
{
|
||
|
list($net,$node) = preg_split('#/#',$node);
|
||
|
}
|
||
|
|
||
|
if (! $net)
|
||
|
throw new \Exception('Missing Net?',$node);
|
||
|
|
||
|
$result->push($this->get_node($zone->id,$net,$node,0),$create);
|
||
|
}
|
||
|
|
||
|
return $result;
|
||
|
}
|
||
|
}
|