Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5883 from derrabus/sa/pdo
Make sure only PDO parameter types are passed to PDO methods
- Loading branch information
Showing
4 changed files
with
57 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\DBAL\Driver\PDO; | ||
|
||
use Doctrine\DBAL\Driver\Exception\UnknownParameterType; | ||
use Doctrine\DBAL\ParameterType; | ||
use PDO; | ||
|
||
/** @internal */ | ||
final class ParameterTypeMap | ||
{ | ||
private const PARAM_TYPE_MAP = [ | ||
ParameterType::NULL => PDO::PARAM_NULL, | ||
ParameterType::INTEGER => PDO::PARAM_INT, | ||
ParameterType::STRING => PDO::PARAM_STR, | ||
ParameterType::ASCII => PDO::PARAM_STR, | ||
ParameterType::BINARY => PDO::PARAM_LOB, | ||
ParameterType::LARGE_OBJECT => PDO::PARAM_LOB, | ||
ParameterType::BOOLEAN => PDO::PARAM_BOOL, | ||
]; | ||
|
||
/** | ||
* Converts DBAL parameter type to PDO parameter type | ||
* | ||
* @psalm-return PDO::PARAM_* | ||
* | ||
* @throws UnknownParameterType | ||
*/ | ||
public static function convertParamType(int $type): int | ||
{ | ||
if (! isset(self::PARAM_TYPE_MAP[$type])) { | ||
throw UnknownParameterType::new($type); | ||
} | ||
|
||
return self::PARAM_TYPE_MAP[$type]; | ||
} | ||
|
||
private function __construct() | ||
{ | ||
} | ||
|
||
private function __clone() | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters