Skip to content

Commit e550bd5

Browse files
Convenience Method for Instantiating the Right FakePDO
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...
1 parent 3425b60 commit e550bd5

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/FakePdo.php

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
namespace Vimeo\MysqlEngine;
3+
4+
use PDO;
5+
6+
class FakePdo
7+
{
8+
/**
9+
* @param string $connection_string the connection string
10+
* @param string $username the username
11+
* @param string $password the password
12+
* @param array<array-key, string> $options any options
13+
* @return PDO
14+
*/
15+
public static function getFakePdo(
16+
string $connection_string,
17+
string $username,
18+
string $password,
19+
array $options
20+
): PDO {
21+
if (\PHP_MAJOR_VERSION === 8) {
22+
return new Php8\FakePdo($connection_string, $username, $password, $options);
23+
}
24+
25+
return new Php7\FakePdo($connection_string, $username, $password, $options);
26+
}
27+
}

0 commit comments

Comments
 (0)