Skip to content

Commit

Permalink
Convenience Method for Instantiating the Right FakePDO
Browse files Browse the repository at this point in the history
Given that there are different versions for php7 vs. php8, provide a
convenience method for getting the right one rather than having to have
switching logic in the calling code...
  • Loading branch information
sergiosalvatore committed Jan 23, 2024
1 parent 3425b60 commit e550bd5
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/FakePdo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
namespace Vimeo\MysqlEngine;

use PDO;

class FakePdo
{
/**
* @param string $connection_string the connection string
* @param string $username the username
* @param string $password the password
* @param array<array-key, string> $options any options
* @return PDO
*/
public static function getFakePdo(
string $connection_string,
string $username,
string $password,
array $options
): PDO {
if (\PHP_MAJOR_VERSION === 8) {
return new Php8\FakePdo($connection_string, $username, $password, $options);
}

return new Php7\FakePdo($connection_string, $username, $password, $options);
}
}

0 comments on commit e550bd5

Please sign in to comment.