-
Notifications
You must be signed in to change notification settings - Fork 100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Correct behaviour to match PHP 8.4 PDO returned types for connect and __construct for the internal pdo object #231
base: 6.x
Are you sure you want to change the base?
Changes from all commits
70c4cfc
411f2db
db09b4f
ac06acf
0740b1b
d8f1ad5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,9 @@ | |
*/ | ||
class ExtendedPdo extends AbstractExtendedPdo | ||
{ | ||
public const string CONNECT_IMMEDIATELY = 'auraSqlImmediate'; | ||
public const string DRIVER_SPECIFIC = 'auraSqlDriverSpecific'; | ||
|
||
/** | ||
* | ||
* Constructor arguments for instantiating the PDO connection. | ||
|
@@ -30,6 +33,14 @@ class ExtendedPdo extends AbstractExtendedPdo | |
*/ | ||
protected array $args = []; | ||
|
||
|
||
/** | ||
* | ||
* Flag for how to construct the PDO object | ||
* | ||
* @var bool | ||
*/ | ||
protected bool $driverSpecific = false; | ||
/** | ||
* | ||
* Constructor. | ||
|
@@ -64,6 +75,12 @@ public function __construct( | |
$options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION; | ||
} | ||
|
||
// check option for driver specific construct and set flag for lazy loading later | ||
if (isset($options[static::DRIVER_SPECIFIC])) { | ||
$this->driverSpecific = (bool) $options[static::DRIVER_SPECIFIC]; | ||
unset($options[static::DRIVER_SPECIFIC]); | ||
} | ||
|
||
// retain the arguments for later | ||
$this->args = [ | ||
$dsn, | ||
|
@@ -83,17 +100,29 @@ public function __construct( | |
|
||
// set quotes for identifier names | ||
$this->setQuoteName($parts[0]); | ||
|
||
// create a connection immediately | ||
if (isset($options[static::CONNECT_IMMEDIATELY])) { | ||
if($options[static::CONNECT_IMMEDIATELY]) { | ||
unset($options[static::CONNECT_IMMEDIATELY]); | ||
$this->establishConnection(); | ||
} else { | ||
unset($options[static::CONNECT_IMMEDIATELY]); | ||
} | ||
} | ||
} | ||
|
||
public static function connect( | ||
string $dsn, | ||
?string $username = null, | ||
?string $password = null, | ||
?array $options = [], | ||
?array $options = null, | ||
array $queries = [], | ||
?ProfilerInterface $profiler = null | ||
): static { | ||
return new static($dsn, $username, $password, $options ?? [], $queries, $profiler); | ||
$options ??= []; | ||
$options[static::DRIVER_SPECIFIC] = true; | ||
return new static($dsn, $username, $password, $options, $queries, $profiler); | ||
} | ||
|
||
/** | ||
|
@@ -111,7 +140,11 @@ public function establishConnection(): void | |
// connect | ||
$this->profiler->start(__FUNCTION__); | ||
list($dsn, $username, $password, $options, $queries) = $this->args; | ||
$this->pdo = PDO::connect($dsn, $username, $password, $options); | ||
if ($this->driverSpecific) { | ||
$this->pdo = PDO::connect($dsn, $username, $password, $options); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought we don't need the connect method itself as this is implemented internally in the PDO. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was looking at the final release of the new PDO
So if you use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That behaviour of PDO is expected. But in our case we are not calling the parent construct. |
||
} else { | ||
$this->pdo = new PDO($dsn, $username, $password, $options); | ||
} | ||
$this->profiler->finish(); | ||
|
||
// connection-time queries | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can't we actually use [] instead of null, this will also remove the usage of
$options ??= [];
right ?