<?php
 namespace Engine\RemoteData\InfoBox; abstract class ContainerAbstract { protected $title; protected $code; protected $children = []; final public function __construct($title=null, $code=null) { $this->setTitle($title); $this->code = $code; } static public function create($title=null, $code=null) { return new static($title, $code); } public function setTitle($title) { $this->title = $title; return $this; } public function getCode() { return $this->code; } public function addIcon(\Engine\RemoteData\InfoBox\IconAbstract $icon, $index=null) { if ($index!==null) { array_splice($this->children, $index, 0, [$icon]); } else { $this->children[] = $icon; } return $this; } public function addField(\Engine\RemoteData\InfoBox\FieldAbstract $field, $index=null) { if ($index!==null) { array_splice($this->children, $index, 0, [$field]); } else { $this->children[] = $field; } return $this; } public function addContainer(\Engine\RemoteData\InfoBox\ContainerAbstract $container, $index=null) { if ($index!==null) { array_splice($this->children, $index, 0, [$container]); } else { $this->children[] = $container; } return $this; } abstract public function exportAsArray(); abstract public function exportAsStdObj(); public function getChildren() { return $this->children; } public function getContainerByCode($code) :?\Engine\RemoteData\InfoBox\ContainerAbstract { foreach($this->children as $childObj) { if ($childObj instanceof \Engine\RemoteData\InfoBox\ContainerAbstract) { if ($childObj->getCode()==$code) { return $childObj; } else { $foundContainer = $childObj->getContainerByCode($code); if ($foundContainer) { return $foundContainer; } } } } return null; } }