contexts as $key => $context) { if ($docGeneratorTemplate->getContext() === $key) { return $context; } } throw new ContextNotFoundException($docGeneratorTemplate->getContext()); } public function getContextByKey(string $searchedKey): DocGeneratorContextInterface { foreach ($this->contexts as $key => $context) { if ($searchedKey === $key) { return $context; } } throw new ContextNotFoundException($searchedKey); } public function getContexts(): array { return iterator_to_array($this->contexts); } }