From 2e68801ff3524d1a7ee1856d25151d7cffc373d6 Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Tue, 10 May 2011 20:19:39 +0200 Subject: [PATCH] [Form] Add argument type checking in BaseDateTimeTransformer --- .../Core/DataTransformer/BaseDateTimeTransformer.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/Symfony/Component/Form/Extension/Core/DataTransformer/BaseDateTimeTransformer.php b/src/Symfony/Component/Form/Extension/Core/DataTransformer/BaseDateTimeTransformer.php index bdf3db8c4d38..2eee7c05d0ef 100644 --- a/src/Symfony/Component/Form/Extension/Core/DataTransformer/BaseDateTimeTransformer.php +++ b/src/Symfony/Component/Form/Extension/Core/DataTransformer/BaseDateTimeTransformer.php @@ -32,9 +32,19 @@ abstract class BaseDateTimeTransformer implements DataTransformerInterface * * @param string $inputTimezone The name of the input timezone * @param string $outputTimezone The name of the output timezone + * + * @throws UnexpectedTypeException if a timezone is not a string */ public function __construct($inputTimezone = null, $outputTimezone = null) { + if (!is_string($inputTimezone) && null !== $inputTimezone) { + throw new UnexpectedTypeException($inputTimezone, 'string'); + } + + if (!is_string($outputTimezone) && null !== $outputTimezone) { + throw new UnexpectedTypeException($outputTimezone, 'string'); + } + $this->inputTimezone = $inputTimezone ?: date_default_timezone_get(); $this->outputTimezone = $outputTimezone ?: date_default_timezone_get(); }