mapperFactory = $mapperFactory; } protected array $mappers; public function getMapper(string $name): Mapper { if (!class_exists($name)) { throw new \InvalidArgumentException("Mapper {$name} not found."); } if (!isset($this->mappers)) { $this->mappers = []; } if (!isset($this->mappers[$name])) { $this->mappers[$name] = $this->mapperFactory->get($name); } return $this->mappers[$name]; } }