collectObjects(); foreach ($this->objects as $object) { if ($object->getName() === $name) { return $object; } } throw new ObjectNotFoundException("Internal object '{$name}' was not found"); } /** * @throws ObjectNotFoundException */ public function getObjectByEntityName(string $entityName): ObjectInterface { $this->collectObjects(); foreach ($this->objects as $object) { if ($object->getEntityName() === $entityName) { return $object; } } throw new ObjectNotFoundException("Internal object was not found for entity '{$entityName}'"); } /** * Dispatches an event to collect all internal objects. * It caches the objects to a local property so it won't dispatch every time but only once. */ private function collectObjects(): void { if (empty($this->objects)) { $event = new InternalObjectEvent(); $this->dispatcher->dispatch($event, IntegrationEvents::INTEGRATION_COLLECT_INTERNAL_OBJECTS); $this->objects = $event->getObjects(); } } }