-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Closed
Description
Symfony version(s) affected
>=5.4
Description
According to the docs it should be possible to use DSN to configure the PDOAdapter, how an exception is thrown instead:
Unsupported DSN: it does not start with "redis[s]:", "memcached:" nor "couchbase:".
This happens because the AbstractAdapter::createConnection()
supports only certain adapters:
symfony/src/Symfony/Component/Cache/Adapter/AbstractAdapter.php
Lines 127 to 144 in 58353d1
public static function createConnection(string $dsn, array $options = []) | |
{ | |
if (str_starts_with($dsn, 'redis:') || str_starts_with($dsn, 'rediss:')) { | |
return RedisAdapter::createConnection($dsn, $options); | |
} | |
if (str_starts_with($dsn, 'memcached:')) { | |
return MemcachedAdapter::createConnection($dsn, $options); | |
} | |
if (0 === strpos($dsn, 'couchbase:')) { | |
if (CouchbaseBucketAdapter::isSupported()) { | |
return CouchbaseBucketAdapter::createConnection($dsn, $options); | |
} | |
return CouchbaseCollectionAdapter::createConnection($dsn, $options); | |
} | |
throw new InvalidArgumentException('Unsupported DSN: it does not start with "redis[s]:", "memcached:" nor "couchbase:".'); | |
} |
I'm not sure if this is a bug in the documentation (and possible new feature) or a bug in the code.
How to reproduce
framework:
cache:
pools:
my.cache:
adapter: cache.adapter.pdo
provider: "pgsql:host=localhost;port=5432;dbname=postgres;user=postgres;password=pass"
#[AsCommand('app:test')]
class TestCommand extends Command
{
public function __construct(
#[Autowire(service: 'my.cache')] private CacheInterface $cache,
) {
parent::__construct();
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
return Command::SUCCESS;
}
}
Possible Solution
Add the necessary logic to AbstractAdapter::createConnection()
.
Additional Context
No response