/** * @param array $connection * @param null|string $alternativeKey * @throws \InvalidArgumentException */ public function updateConnection(array $connection, $alternativeKey = null) { if (is_null($alternativeKey)) { if (!isset($connection['dbname'])) { throw new \InvalidArgumentException('Missing dbname key in connection configuration'); } $connectionObj = $this->findByDbName($connection['dbname']); if (!$connectionObj) { throw new \InvalidArgumentException('No connection found for db: ' . $connection['dbname']); } $alternativeKey = $this->connections->indexOf($connectionObj); } Assertion::string($alternativeKey); if (!$this->connections->containsKey($alternativeKey)) { throw new \InvalidArgumentException(sprintf('Connection for DB %s can not be found', $connection['dbname'])); } $this->connections->set($alternativeKey, DbalConnection::fromConfiguration($connection)); $this->saveConnections(); }