소스 검색

[Form] Add argument type checking in BaseDateTimeTransformer

Victor Berchet 14 년 전
부모
커밋
2e68801ff3
1개의 변경된 파일10개의 추가작업 그리고 0개의 파일을 삭제
  1. 10 0
      src/Symfony/Component/Form/Extension/Core/DataTransformer/BaseDateTimeTransformer.php

+ 10 - 0
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();
     }