You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
bug symfony#26227 Add support for URL-like DSNs for the PdoSessionHandler (stof)
This PR was merged into the 3.4 branch.
Discussion
----------
Add support for URL-like DSNs for the PdoSessionHandler
| Q | A
| ------------- | ---
| Branch? | 3.4
| Bug fix? | no
| New feature? | yes
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | symfony#25186
| License | MIT
| Doc PR |
This allows migrating away from the deprecated DbalSessionHandler when DBAL was used for its ability to be configured through a URL (which is what is provided on Heroku and some other PaaS).
I know that this is technically a new feature (and so may target master instead), but we currently have no way to configure a database session storage on Heroku in 4.0 (and in 3.4, it requires using a deprecated class).
I decided to add support for the URL-like configuration directly rather than adding support for passing a DBAL connection, to minimize the code changes.
I also left out the support for OCI in this feature, as the PDO DSN for the Oracle driver is totally crazy (it has nothing in common with other drivers). If someone wants to use a Oracle DB, they should pass the PDO DSN directly instead of a URL.
Differences with the URL handling in Doctrine DBAL:
- schemeless URLs are not supported (DBAL allows configuring the driver separately in case you don't have it in the URL)
- the query string is ignored (DBAL allows to use the query string to configure any supported DBAL params, which are driver-specific. Just use a DSN directly if you need them. PaaS are unlikely to provide such params anyway and they are the main motivation for this PR)
Commits
-------
14c35ad Add support for URL-like DSNs for the PdoSessionHandler
// Doctrine DBAL supports passing its internal pdo_* driver names directly too (allowing both dashes and underscores). This allows supporting the same here.
if (isset($params['host']) && '' !== $params['host']) {
492
+
$dsn .= 'host='.$params['host'].';';
493
+
}
494
+
495
+
if (isset($params['port']) && '' !== $params['port']) {
496
+
$dsn .= 'port='.$params['port'].';';
497
+
}
498
+
499
+
if (isset($params['path'])) {
500
+
$dbName = substr($params['path'], 1); // Remove the leading slash
501
+
$dsn .= 'dbname='.$dbName.';';
502
+
}
503
+
504
+
return$dsn;
505
+
506
+
case'sqlite':
507
+
return'sqlite:'.substr($params['path'], 1);
508
+
509
+
case'sqlsrv':
510
+
$dsn = 'sqlsrv:server=';
511
+
512
+
if (isset($params['host'])) {
513
+
$dsn .= $params['host'];
514
+
}
515
+
516
+
if (isset($params['port']) && '' !== $params['port']) {
517
+
$dsn .= ','.$params['port'];
518
+
}
519
+
520
+
if (isset($params['path'])) {
521
+
$dbName = substr($params['path'], 1); // Remove the leading slash
522
+
$dsn .= ';Database='.$dbName;
523
+
}
524
+
525
+
return$dsn;
526
+
527
+
default:
528
+
thrownew \InvalidArgumentException(sprintf('The scheme "%s" is not supported by the PdoSessionHandler URL configuration. Pass a PDO DSN directly.', $params['scheme']));
0 commit comments