Procházet zdrojové kódy

[Form] Add argument type checking in BaseDateTimeTransformer

Victor Berchet před 14 roky
rodič
revize
2e68801ff3

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