Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ jobs:
- php: 8.2
phpunit: '12.4.0'
include:
- php: 8.5
phpunit: '12.4.0'
stability: prefer-stable
- php: 8.3
phpunit: '12.1.0'
stability: prefer-stable
Expand Down Expand Up @@ -119,6 +122,9 @@ jobs:
- php: 8.2
phpunit: '12.4.0'
include:
- php: 8.5
phpunit: '12.4.0'
stability: prefer-stable
- php: 8.3
phpunit: '12.1.0'
stability: prefer-stable
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
"league/flysystem-sftp-v3": "^3.25.1",
"mockery/mockery": "^1.6.10",
"opis/json-schema": "^2.4.1",
"orchestra/testbench-core": "^10.7.0",
"orchestra/testbench-core": "dev-10/php85 as 10.999.999",
"pda/pheanstalk": "^5.0.6|^7.0.0",
"php-http/discovery": "^1.15",
"phpstan/phpstan": "^2.0",
Expand Down
14 changes: 8 additions & 6 deletions config/database.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

use Illuminate\Database\Connectors\MariaDbConnector;
use Illuminate\Database\Connectors\MySqlConnector;
use Illuminate\Support\Str;

return [
Expand Down Expand Up @@ -60,9 +62,9 @@
'prefix_indexes' => true,
'strict' => true,
'engine' => null,
'options' => extension_loaded('pdo_mysql') ? array_filter([
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
]) : [],
'options' => MySqlConnector::features([
'ATTR_SSL_CA' => env('MYSQL_ATTR_SSL_CA'),
]),
],

'mariadb' => [
Expand All @@ -80,9 +82,9 @@
'prefix_indexes' => true,
'strict' => true,
'engine' => null,
'options' => extension_loaded('pdo_mysql') ? array_filter([
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
]) : [],
'options' => MariaDbConnector::features([
'ATTR_SSL_CA' => env('MYSQL_ATTR_SSL_CA'),
]),
],

'pgsql' => [
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Database/Connectors/Connector.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function createConnection($dsn, array $config, array $options)
*/
protected function createPdoConnection($dsn, $username, #[\SensitiveParameter] $password, $options)
{
return version_compare(phpversion(), '8.4.0', '<')
return PHP_VERSION_ID < 80400
? new PDO($dsn, $username, $password, $options)
: PDO::connect($dsn, $username, $password, $options); /** @phpstan-ignore staticMethod.notFound (PHP 8.4) */
}
Expand Down
20 changes: 20 additions & 0 deletions src/Illuminate/Database/Connectors/MySqlConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,30 @@

namespace Illuminate\Database\Connectors;

use Illuminate\Support\Collection;
use Illuminate\Support\Str;
use PDO;

class MySqlConnector extends Connector implements ConnectorInterface
{
/**
* Determine of PDO feature constant.
*
* @param array<string, mixed> $features
* @return array<string, mixed>
*/
public static function features(array $features)
{
if (! extension_loaded('pdo_mysql')) {
return [];
}

return (new Collection($features))
->mapWithKeys(fn ($value, $feature) => [(string) Str::of($feature)->prepend(PHP_VERSION_ID < 80400 ? 'PDO::MYSQL_' : 'Pdo\Mysql::') => $value])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@crynobone

Where does the constant name as a string get converted to a constant value?

Shouldn't we call constant() after prefixing the constant names to convert them to their values?

Otherwise this would result in something like this:

[
    // constant name as a string value
    'PDO::MYSQL_ATTR_SSL_CA' => env('MYSQL_ATTR_SSL_CA'),
]

Instead of

[
    // PDO::MYSQL_ATTR_SSL_CA = 1009 in my local PHP binary
    1009 => env('MYSQL_ATTR_SSL_CA'),
]

reference: https://www.php.net/manual/en/function.constant.php

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, Stringable@pipe() returns a new Stringable instance and not the result of the callback.

Otherwise, this could be fixed by adding a ->pipe('constant') call to the Str::of() chain when mapping the keys.

If the constant's value is an integer, I guess the key might also be an integer.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR will remain as a draft and wait for symfony/polyfill#549

  1. I'm not sure using ATTR_SSL_CA, for example, as key is good for DX, This means we need to include the usage documentation.
  2. Only mysql and sqlite has the deprecation at the moment. This means Connector::features() is only available for some drivers.

->filter()
->all();
}

/**
* Establish a database connection.
*
Expand Down
20 changes: 20 additions & 0 deletions src/Illuminate/Database/Connectors/SQLiteConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,29 @@
namespace Illuminate\Database\Connectors;

use Illuminate\Database\SQLiteDatabaseDoesNotExistException;
use Illuminate\Support\Collection;
use Illuminate\Support\Str;

class SQLiteConnector extends Connector implements ConnectorInterface
{
/**
* Determine of PDO feature constant.
*
* @param array<string, mixed> $features
* @return array<string, mixed>
*/
public static function features(array $features)
{
if (! extension_loaded('pdo_sqlite')) {
return [];
}

return (new Collection($features))
->mapWithKeys(fn ($value, $feature) => [(string) Str::of($feature)->prepend(PHP_VERSION_ID < 80400 ? 'PDO::SQLITE_' : 'Pdo\Sqlite::') => $value])
->filter()
->all();
}

/**
* Establish a database connection.
*
Expand Down
Loading