Skip to content

Commit

Permalink
Add explicit boolean conversion for doctrine types
Browse files Browse the repository at this point in the history
We do not want any random type to be converted to boolean.

For PostgreSQL, Doctrine has platform specific options.

For other platforms, it relies on PHPs default (and lenient) type conversion.
  • Loading branch information
Alex Rothuis committed Jul 28, 2016
1 parent 56e3926 commit 7e1714a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,17 @@ public function convertToPHPValue($value, AbstractPlatform $platform)
return $value;
}

// Prevent a too lenient boolean conversion on non-postgresql platforms
if ($platform->getName() !== 'postgresql') {
if ($value !== 1 && $value !== 0 && $value !== '1' && $value !== '0' && !is_bool($value)) {
throw ConversionException::conversionFailed($value, $this->getName());
}
}

try {
$showRaaContactInformationOption = new ShowRaaContactInformationOption($value);
$showRaaContactInformationOption = new ShowRaaContactInformationOption(
$platform->convertFromBoolean($value)
);
} catch (InvalidArgumentException $e) {
// get nice standard message, so we can throw it keeping the exception chain
$doctrineExceptionMessage = ConversionException::conversionFailedFormat(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,15 @@ public function convertToPHPValue($value, AbstractPlatform $platform)
return $value;
}

// Prevent a too lenient boolean conversion on non-postgresql platforms
if ($platform->getName() !== 'postgresql') {
if ($value !== 1 && $value !== 0 && $value !== '1' && $value !== '0' && !is_bool($value)) {
throw ConversionException::conversionFailed($value, $this->getName());
}
}

try {
$useRaLocationsOption = new UseRaLocationsOption($value);
$useRaLocationsOption = new UseRaLocationsOption($platform->convertFromBoolean($value));
} catch (InvalidArgumentException $e) {
// get nice standard message, so we can throw it keeping the exception chain
$doctrineExceptionMessage = ConversionException::conversionFailedFormat(
Expand Down

0 comments on commit 7e1714a

Please sign in to comment.