Skip to content

Commit

Permalink
fix: use __callStatic for wrapped PDO methods
Browse files Browse the repository at this point in the history
  • Loading branch information
tbreuss committed Feb 8, 2024
1 parent 7f50ebd commit 507008d
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/PDO.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* @method array errorInfo() Fetch extended error information associated with the last operation on the database handle
* @method int|false exec(string $statement) Execute an SQL statement and return the number of affected rows
* @method mixed getAttribute(int $attribute) Retrieve a database connection attribute
* @method array getAvailableDrivers() Return an array of available PDO drivers
* @method bool inTransaction() Checks if inside a transaction
* @method string|false lastInsertId(?string $name = null) Returns the ID of the last inserted row or sequence value
* @method bool rollBack() Rolls back a transaction
Expand Down Expand Up @@ -112,7 +113,7 @@ public function __construct(string $dsn, ?string $username = NULL, ?string $pass
}

/**
* Calls the method of the original PDO object
* Calls the method of the underlying PDO instance
*/
public function __call(string $name, array $arguments): mixed
{
Expand All @@ -137,11 +138,20 @@ public function __call(string $name, array $arguments): mixed
}

/**
* Return an array of available PDO drivers
*
* Calls the static method of the underlying PDO instance
*/
public static function getAvailableDrivers(): array
public static function __callStatic(string $name, array $arguments): mixed
{
return \PDO::getAvailableDrivers();
$methods = [
'getAvailableDrivers',
];

if (in_array($name, $methods)) {
return call_user_func_array([\PDO::class, $name], $arguments);
}

throw new \BadMethodCallException("Static method $name doesn't exist");
}

/**
Expand Down

0 comments on commit 507008d

Please sign in to comment.