key = $key; $this->name = $name; $this->offset = $offset; $this->registers = $registers; $this->subgroups = $subgroups; $this->subgroupReferences = $subgroupReferences; } public function getRegister(array|string $keys): ?Register { if (is_string($keys)) { $keys = explode('.', $keys); } $registerKey = array_pop($keys); $group = !empty($keys) > 1 ? $this->getSubgroup($keys) : $this; if ($group instanceof RegisterGroup) { foreach ($group->registers as $register) { if ($register->key === $registerKey) { return $register; } } } return null; } public function getSubgroup(array|string $subgroupKeys): ?RegisterGroup { if (is_string($subgroupKeys)) { $subgroupKeys = explode('.', $subgroupKeys); } $firstLevelSubgroupKey = array_shift($subgroupKeys); foreach ($this->subgroups as $subgroup) { if ($subgroup->key === $firstLevelSubgroupKey) { return !empty($subgroupKeys) ? $subgroup->getSubgroup($subgroupKeys) : $subgroup; } } return null; } }