validateBrokersWithPersistence($brokerId, $persistenceId); switch ($brokerId) { case self::BROKER_MEMORY: return new InMemoryQueueBroker(); case self::BROKER_RDS: return new RdsQueueBroker($persistenceId, $capacity); case self::BROKER_NEW_SQL: return new NewSqlQueueBroker($persistenceId, $capacity); case self::BROKER_SQS: return new SqsQueueBroker(common_cache_Cache::SERVICE_ID, $capacity); } throw new InvalidArgumentException(sprintf('Broker %s is not supported', $brokerId)); } private function validateBrokersWithPersistence(string $brokerId, string $persistenceId = null): void { if (in_array($brokerId, [self::BROKER_RDS, self::BROKER_NEW_SQL], true) && empty($persistenceId)) { throw new InvalidArgumentException('Persistence id (--persistence=...) needs to be set for SQL.'); } } }