<?php
namespace App\Utils\BaseParser\Structure\StructureParser\Types; abstract class Relations extends \App\Utils\BaseParser\Structure\StructureParser\Types\BaseAbstract implements \App\Utils\BaseParser\NoParamsConstructorInterface { public $relations = []; public function __construct() { } public function appendRelation(\App\Utils\BaseParser\Structure\StructureParser\Types\Relation $relation) { $this->relations[] = $relation; } public function filter($type) { $ret = new static(); foreach ($this->relations as $rel) { if ($rel->relationType==$type) { $ret->appendRelation($rel); } } return $ret; } public function first() { return $this->relations[0]; } public function remove(\App\Utils\BaseParser\Structure\StructureParser\Types\Relation $relation) { $removed = false; foreach ($this->relations as $k=>$rel) { if ($rel === $relation) { $this->relations[$k] = null; $removed = true; } } if (!$removed) { throw new \App\Utils\BaseParser\Structure\StructureParser\Types\Exception\Exception("No relation was removed"); } $this->relations = array_filter($this->relations); return $this; } } 