diff options
Diffstat (limited to 'vendor/symfony/form/Symfony/Component/Form/Extension/Core/DataTransformer')
18 files changed, 0 insertions, 2011 deletions
diff --git a/vendor/symfony/form/Symfony/Component/Form/Extension/Core/DataTransformer/ArrayToPartsTransformer.php b/vendor/symfony/form/Symfony/Component/Form/Extension/Core/DataTransformer/ArrayToPartsTransformer.php deleted file mode 100644 index fc080f25..00000000 --- a/vendor/symfony/form/Symfony/Component/Form/Extension/Core/DataTransformer/ArrayToPartsTransformer.php +++ /dev/null | |||
@@ -1,86 +0,0 @@ | |||
1 | <?php | ||
2 | |||
3 | /* | ||
4 | * This file is part of the Symfony package. | ||
5 | * | ||
6 | * (c) Fabien Potencier <fabien@symfony.com> | ||
7 | * | ||
8 | * For the full copyright and license information, please view the LICENSE | ||
9 | * file that was distributed with this source code. | ||
10 | */ | ||
11 | |||
12 | namespace Symfony\Component\Form\Extension\Core\DataTransformer; | ||
13 | |||
14 | use Symfony\Component\Form\DataTransformerInterface; | ||
15 | use Symfony\Component\Form\Exception\TransformationFailedException; | ||
16 | |||
17 | /** | ||
18 | * @author Bernhard Schussek <bschussek@gmail.com> | ||
19 | */ | ||
20 | class ArrayToPartsTransformer implements DataTransformerInterface | ||
21 | { | ||
22 | private $partMapping; | ||
23 | |||
24 | public function __construct(array $partMapping) | ||
25 | { | ||
26 | $this->partMapping = $partMapping; | ||
27 | } | ||
28 | |||
29 | public function transform($array) | ||
30 | { | ||
31 | if (null === $array) { | ||
32 | $array = array(); | ||
33 | } | ||
34 | |||
35 | if (!is_array($array) ) { | ||
36 | throw new TransformationFailedException('Expected an array.'); | ||
37 | } | ||
38 | |||
39 | $result = array(); | ||
40 | |||
41 | foreach ($this->partMapping as $partKey => $originalKeys) { | ||
42 | if (empty($array)) { | ||
43 | $result[$partKey] = null; | ||
44 | } else { | ||
45 | $result[$partKey] = array_intersect_key($array, array_flip($originalKeys)); | ||
46 | } | ||
47 | } | ||
48 | |||
49 | return $result; | ||
50 | } | ||
51 | |||
52 | public function reverseTransform($array) | ||
53 | { | ||
54 | if (!is_array($array) ) { | ||
55 | throw new TransformationFailedException('Expected an array.'); | ||
56 | } | ||
57 | |||
58 | $result = array(); | ||
59 | $emptyKeys = array(); | ||
60 | |||
61 | foreach ($this->partMapping as $partKey => $originalKeys) { | ||
62 | if (!empty($array[$partKey])) { | ||
63 | foreach ($originalKeys as $originalKey) { | ||
64 | if (isset($array[$partKey][$originalKey])) { | ||
65 | $result[$originalKey] = $array[$partKey][$originalKey]; | ||
66 | } | ||
67 | } | ||
68 | } else { | ||
69 | $emptyKeys[] = $partKey; | ||
70 | } | ||
71 | } | ||
72 | |||
73 | if (count($emptyKeys) > 0) { | ||
74 | if (count($emptyKeys) === count($this->partMapping)) { | ||
75 | // All parts empty | ||
76 | return null; | ||
77 | } | ||
78 | |||
79 | throw new TransformationFailedException( | ||
80 | sprintf('The keys "%s" should not be empty', implode('", "', $emptyKeys) | ||
81 | )); | ||
82 | } | ||
83 | |||
84 | return $result; | ||
85 | } | ||
86 | } | ||
diff --git a/vendor/symfony/form/Symfony/Component/Form/Extension/Core/DataTransformer/BaseDateTimeTransformer.php b/vendor/symfony/form/Symfony/Component/Form/Extension/Core/DataTransformer/BaseDateTimeTransformer.php deleted file mode 100644 index e4e8932e..00000000 --- a/vendor/symfony/form/Symfony/Component/Form/Extension/Core/DataTransformer/BaseDateTimeTransformer.php +++ /dev/null | |||
@@ -1,52 +0,0 @@ | |||
1 | <?php | ||
2 | |||
3 | /* | ||
4 | * This file is part of the Symfony package. | ||
5 | * | ||
6 | * (c) Fabien Potencier <fabien@symfony.com> | ||
7 | * | ||
8 | * For the full copyright and license information, please view the LICENSE | ||
9 | * file that was distributed with this source code. | ||
10 | */ | ||
11 | |||
12 | namespace Symfony\Component\Form\Extension\Core\DataTransformer; | ||
13 | |||
14 | use Symfony\Component\Form\DataTransformerInterface; | ||
15 | use Symfony\Component\Form\Exception\UnexpectedTypeException; | ||
16 | |||
17 | abstract class BaseDateTimeTransformer implements DataTransformerInterface | ||
18 | { | ||
19 | protected static $formats = array( | ||
20 | \IntlDateFormatter::NONE, | ||
21 | \IntlDateFormatter::FULL, | ||
22 | \IntlDateFormatter::LONG, | ||
23 | \IntlDateFormatter::MEDIUM, | ||
24 | \IntlDateFormatter::SHORT, | ||
25 | ); | ||
26 | |||
27 | protected $inputTimezone; | ||
28 | |||
29 | protected $outputTimezone; | ||
30 | |||
31 | /** | ||
32 | * Constructor. | ||
33 | * | ||
34 | * @param string $inputTimezone The name of the input timezone | ||
35 | * @param string $outputTimezone The name of the output timezone | ||
36 | * | ||
37 | * @throws UnexpectedTypeException if a timezone is not a string | ||
38 | */ | ||
39 | public function __construct($inputTimezone = null, $outputTimezone = null) | ||
40 | { | ||
41 | if (!is_string($inputTimezone) && null !== $inputTimezone) { | ||
42 | throw new UnexpectedTypeException($inputTimezone, 'string'); | ||
43 | } | ||
44 | |||
45 | if (!is_string($outputTimezone) && null !== $outputTimezone) { | ||
46 | throw new UnexpectedTypeException($outputTimezone, 'string'); | ||
47 | } | ||
48 | |||
49 | $this->inputTimezone = $inputTimezone ?: date_default_timezone_get(); | ||
50 | $this->outputTimezone = $outputTimezone ?: date_default_timezone_get(); | ||
51 | } | ||
52 | } | ||
diff --git a/vendor/symfony/form/Symfony/Component/Form/Extension/Core/DataTransformer/BooleanToStringTransformer.php b/vendor/symfony/form/Symfony/Component/Form/Extension/Core/DataTransformer/BooleanToStringTransformer.php deleted file mode 100644 index 95e7332d..00000000 --- a/vendor/symfony/form/Symfony/Component/Form/Extension/Core/DataTransformer/BooleanToStringTransformer.php +++ /dev/null | |||
@@ -1,85 +0,0 @@ | |||
1 | <?php | ||
2 | |||
3 | /* | ||
4 | * This file is part of the Symfony package. | ||
5 | * | ||
6 | * (c) Fabien Potencier <fabien@symfony.com> | ||
7 | * | ||
8 | * For the full copyright and license information, please view the LICENSE | ||
9 | * file that was distributed with this source code. | ||
10 | */ | ||
11 | |||
12 | namespace Symfony\Component\Form\Extension\Core\DataTransformer; | ||
13 | |||
14 | use Symfony\Component\Form\DataTransformerInterface; | ||
15 | use Symfony\Component\Form\Exception\TransformationFailedException; | ||
16 | |||
17 | /** | ||
18 | * Transforms between a Boolean and a string. | ||
19 | * | ||
20 | * @author Bernhard Schussek <bschussek@gmail.com> | ||
21 | * @author Florian Eckerstorfer <florian@eckerstorfer.org> | ||
22 | */ | ||
23 | class BooleanToStringTransformer implements DataTransformerInterface | ||
24 | { | ||
25 | /** | ||
26 | * The value emitted upon transform if the input is true | ||
27 | * @var string | ||
28 | */ | ||
29 | private $trueValue; | ||
30 | |||
31 | /** | ||
32 | * Sets the value emitted upon transform if the input is true. | ||
33 | * | ||
34 | * @param string $trueValue | ||
35 | */ | ||
36 | public function __construct($trueValue) | ||
37 | { | ||
38 | $this->trueValue = $trueValue; | ||
39 | } | ||
40 | |||
41 | /** | ||
42 | * Transforms a Boolean into a string. | ||
43 | * | ||
44 | * @param Boolean $value Boolean value. | ||
45 | * | ||
46 | * @return string String value. | ||
47 | * | ||
48 | * @throws TransformationFailedException If the given value is not a Boolean. | ||
49 | */ | ||
50 | public function transform($value) | ||
51 | { | ||
52 | if (null === $value) { | ||
53 | return null; | ||
54 | } | ||
55 | |||
56 | if (!is_bool($value)) { | ||
57 | throw new TransformationFailedException('Expected a Boolean.'); | ||
58 | } | ||
59 | |||
60 | return true === $value ? $this->trueValue : null; | ||
61 | } | ||
62 | |||
63 | /** | ||
64 | * Transforms a string into a Boolean. | ||
65 | * | ||
66 | * @param string $value String value. | ||
67 | * | ||
68 | * @return Boolean Boolean value. | ||
69 | * | ||
70 | * @throws TransformationFailedException If the given value is not a string. | ||
71 | */ | ||
72 | public function reverseTransform($value) | ||
73 | { | ||
74 | if (null === $value) { | ||
75 | return false; | ||
76 | } | ||
77 | |||
78 | if (!is_string($value)) { | ||
79 | throw new TransformationFailedException('Expected a string.'); | ||
80 | } | ||
81 | |||
82 | return true; | ||
83 | } | ||
84 | |||
85 | } | ||
diff --git a/vendor/symfony/form/Symfony/Component/Form/Extension/Core/DataTransformer/ChoiceToBooleanArrayTransformer.php b/vendor/symfony/form/Symfony/Component/Form/Extension/Core/DataTransformer/ChoiceToBooleanArrayTransformer.php deleted file mode 100644 index 79b3f7ac..00000000 --- a/vendor/symfony/form/Symfony/Component/Form/Extension/Core/DataTransformer/ChoiceToBooleanArrayTransformer.php +++ /dev/null | |||
@@ -1,118 +0,0 @@ | |||
1 | <?php | ||
2 | |||
3 | /* | ||
4 | * This file is part of the Symfony package. | ||
5 | * | ||
6 | * (c) Fabien Potencier <fabien@symfony.com> | ||
7 | * | ||
8 | * For the full copyright and license information, please view the LICENSE | ||
9 | * file that was distributed with this source code. | ||
10 | */ | ||
11 | |||
12 | namespace Symfony\Component\Form\Extension\Core\DataTransformer; | ||
13 | |||
14 | use Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceListInterface; | ||
15 | use Symfony\Component\Form\DataTransformerInterface; | ||
16 | use Symfony\Component\Form\Exception\TransformationFailedException; | ||
17 | |||
18 | /** | ||
19 | * @author Bernhard Schussek <bschussek@gmail.com> | ||
20 | */ | ||
21 | class ChoiceToBooleanArrayTransformer implements DataTransformerInterface | ||
22 | { | ||
23 | private $choiceList; | ||
24 | |||
25 | private $placeholderPresent; | ||
26 | |||
27 | /** | ||
28 | * Constructor. | ||
29 | * | ||
30 | * @param ChoiceListInterface $choiceList | ||
31 | * @param Boolean $placeholderPresent | ||
32 | */ | ||
33 | public function __construct(ChoiceListInterface $choiceList, $placeholderPresent) | ||
34 | { | ||
35 | $this->choiceList = $choiceList; | ||
36 | $this->placeholderPresent = $placeholderPresent; | ||
37 | } | ||
38 | |||
39 | /** | ||
40 | * Transforms a single choice to a format appropriate for the nested | ||
41 | * checkboxes/radio buttons. | ||
42 | * | ||
43 | * The result is an array with the options as keys and true/false as values, | ||
44 | * depending on whether a given option is selected. If this field is rendered | ||
45 | * as select tag, the value is not modified. | ||
46 | * | ||
47 | * @param mixed $choice An array if "multiple" is set to true, a scalar | ||
48 | * value otherwise. | ||
49 | * | ||
50 | * @return mixed An array | ||
51 | * | ||
52 | * @throws TransformationFailedException If the given value is not scalar or | ||
53 | * if the choices can not be retrieved. | ||
54 | */ | ||
55 | public function transform($choice) | ||
56 | { | ||
57 | try { | ||
58 | $values = $this->choiceList->getValues(); | ||
59 | } catch (\Exception $e) { | ||
60 | throw new TransformationFailedException('Can not get the choice list', $e->getCode(), $e); | ||
61 | } | ||
62 | |||
63 | $index = current($this->choiceList->getIndicesForChoices(array($choice))); | ||
64 | |||
65 | foreach ($values as $i => $value) { | ||
66 | $values[$i] = $i === $index; | ||
67 | } | ||
68 | |||
69 | if ($this->placeholderPresent) { | ||
70 | $values['placeholder'] = false === $index; | ||
71 | } | ||
72 | |||
73 | return $values; | ||
74 | } | ||
75 | |||
76 | /** | ||
77 | * Transforms a checkbox/radio button array to a single choice. | ||
78 | * | ||
79 | * The input value is an array with the choices as keys and true/false as | ||
80 | * values, depending on whether a given choice is selected. The output | ||
81 | * is the selected choice. | ||
82 | * | ||
83 | * @param array $values An array of values | ||
84 | * | ||
85 | * @return mixed A scalar value | ||
86 | * | ||
87 | * @throws TransformationFailedException If the given value is not an array, | ||
88 | * if the recuperation of the choices | ||
89 | * fails or if some choice can't be | ||
90 | * found. | ||
91 | */ | ||
92 | public function reverseTransform($values) | ||
93 | { | ||
94 | if (!is_array($values)) { | ||
95 | throw new TransformationFailedException('Expected an array.'); | ||
96 | } | ||
97 | |||
98 | try { | ||
99 | $choices = $this->choiceList->getChoices(); | ||
100 | } catch (\Exception $e) { | ||
101 | throw new TransformationFailedException('Can not get the choice list', $e->getCode(), $e); | ||
102 | } | ||
103 | |||
104 | foreach ($values as $i => $selected) { | ||
105 | if ($selected) { | ||
106 | if (isset($choices[$i])) { | ||
107 | return $choices[$i] === '' ? null : $choices[$i]; | ||
108 | } elseif ($this->placeholderPresent && 'placeholder' === $i) { | ||
109 | return null; | ||
110 | } else { | ||
111 | throw new TransformationFailedException(sprintf('The choice "%s" does not exist', $i)); | ||
112 | } | ||
113 | } | ||
114 | } | ||
115 | |||
116 | return null; | ||
117 | } | ||
118 | } | ||
diff --git a/vendor/symfony/form/Symfony/Component/Form/Extension/Core/DataTransformer/ChoiceToValueTransformer.php b/vendor/symfony/form/Symfony/Component/Form/Extension/Core/DataTransformer/ChoiceToValueTransformer.php deleted file mode 100644 index 5a818558..00000000 --- a/vendor/symfony/form/Symfony/Component/Form/Extension/Core/DataTransformer/ChoiceToValueTransformer.php +++ /dev/null | |||
@@ -1,62 +0,0 @@ | |||
1 | <?php | ||
2 | |||
3 | /* | ||
4 | * This file is part of the Symfony package. | ||
5 | * | ||
6 | * (c) Fabien Potencier <fabien@symfony.com> | ||
7 | * | ||
8 | * For the full copyright and license information, please view the LICENSE | ||
9 | * file that was distributed with this source code. | ||
10 | */ | ||
11 | |||
12 | namespace Symfony\Component\Form\Extension\Core\DataTransformer; | ||
13 | |||
14 | use Symfony\Component\Form\DataTransformerInterface; | ||
15 | use Symfony\Component\Form\Exception\TransformationFailedException; | ||
16 | use Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceListInterface; | ||
17 | |||
18 | /** | ||
19 | * @author Bernhard Schussek <bschussek@gmail.com> | ||
20 | */ | ||
21 | class ChoiceToValueTransformer implements DataTransformerInterface | ||
22 | { | ||
23 | private $choiceList; | ||
24 | |||
25 | /** | ||
26 | * Constructor. | ||
27 | * | ||
28 | * @param ChoiceListInterface $choiceList | ||
29 | */ | ||
30 | public function __construct(ChoiceListInterface $choiceList) | ||
31 | { | ||
32 | $this->choiceList = $choiceList; | ||
33 | } | ||
34 | |||
35 | public function transform($choice) | ||
36 | { | ||
37 | return (string) current($this->choiceList->getValuesForChoices(array($choice))); | ||
38 | } | ||
39 | |||
40 | public function reverseTransform($value) | ||
41 | { | ||
42 | if (null !== $value && !is_scalar($value)) { | ||
43 | throw new TransformationFailedException('Expected a scalar.'); | ||
44 | } | ||
45 | |||
46 | // These are now valid ChoiceList values, so we can return null | ||
47 | // right away | ||
48 | if ('' === $value || null === $value) { | ||
49 | return null; | ||
50 | } | ||
51 | |||
52 | $choices = $this->choiceList->getChoicesForValues(array($value)); | ||
53 | |||
54 | if (1 !== count($choices)) { | ||
55 | throw new TransformationFailedException(sprintf('The choice "%s" does not exist or is not unique', $value)); | ||
56 | } | ||
57 | |||
58 | $choice = current($choices); | ||
59 | |||
60 | return '' === $choice ? null : $choice; | ||
61 | } | ||
62 | } | ||
diff --git a/vendor/symfony/form/Symfony/Component/Form/Extension/Core/DataTransformer/ChoicesToBooleanArrayTransformer.php b/vendor/symfony/form/Symfony/Component/Form/Extension/Core/DataTransformer/ChoicesToBooleanArrayTransformer.php deleted file mode 100644 index a13c0d4d..00000000 --- a/vendor/symfony/form/Symfony/Component/Form/Extension/Core/DataTransformer/ChoicesToBooleanArrayTransformer.php +++ /dev/null | |||
@@ -1,117 +0,0 @@ | |||
1 | <?php | ||
2 | |||
3 | /* | ||
4 | * This file is part of the Symfony package. | ||
5 | * | ||
6 | * (c) Fabien Potencier <fabien@symfony.com> | ||
7 | * | ||
8 | * For the full copyright and license information, please view the LICENSE | ||
9 | * file that was distributed with this source code. | ||
10 | */ | ||
11 | |||
12 | namespace Symfony\Component\Form\Extension\Core\DataTransformer; | ||
13 | |||
14 | use Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceListInterface; | ||
15 | use Symfony\Component\Form\DataTransformerInterface; | ||
16 | use Symfony\Component\Form\Exception\TransformationFailedException; | ||
17 | |||
18 | /** | ||
19 | * @author Bernhard Schussek <bschussek@gmail.com> | ||
20 | */ | ||
21 | class ChoicesToBooleanArrayTransformer implements DataTransformerInterface | ||
22 | { | ||
23 | private $choiceList; | ||
24 | |||
25 | public function __construct(ChoiceListInterface $choiceList) | ||
26 | { | ||
27 | $this->choiceList = $choiceList; | ||
28 | } | ||
29 | |||
30 | /** | ||
31 | * Transforms an array of choices to a format appropriate for the nested | ||
32 | * checkboxes/radio buttons. | ||
33 | * | ||
34 | * The result is an array with the options as keys and true/false as values, | ||
35 | * depending on whether a given option is selected. If this field is rendered | ||
36 | * as select tag, the value is not modified. | ||
37 | * | ||
38 | * @param mixed $array An array | ||
39 | * | ||
40 | * @return mixed An array | ||
41 | * | ||
42 | * @throws TransformationFailedException If the given value is not an array | ||
43 | * or if the choices can not be retrieved. | ||
44 | */ | ||
45 | public function transform($array) | ||
46 | { | ||
47 | if (null === $array) { | ||
48 | return array(); | ||
49 | } | ||
50 | |||
51 | if (!is_array($array)) { | ||
52 | throw new TransformationFailedException('Expected an array.'); | ||
53 | } | ||
54 | |||
55 | try { | ||
56 | $values = $this->choiceList->getValues(); | ||
57 | } catch (\Exception $e) { | ||
58 | throw new TransformationFailedException('Can not get the choice list', $e->getCode(), $e); | ||
59 | } | ||
60 | |||
61 | $indexMap = array_flip($this->choiceList->getIndicesForChoices($array)); | ||
62 | |||
63 | foreach ($values as $i => $value) { | ||
64 | $values[$i] = isset($indexMap[$i]); | ||
65 | } | ||
66 | |||
67 | return $values; | ||
68 | } | ||
69 | |||
70 | /** | ||
71 | * Transforms a checkbox/radio button array to an array of choices. | ||
72 | * | ||
73 | * The input value is an array with the choices as keys and true/false as | ||
74 | * values, depending on whether a given choice is selected. The output | ||
75 | * is an array with the selected choices. | ||
76 | * | ||
77 | * @param mixed $values An array | ||
78 | * | ||
79 | * @return mixed An array | ||
80 | * | ||
81 | * @throws TransformationFailedException If the given value is not an array, | ||
82 | * if the recuperation of the choices | ||
83 | * fails or if some choice can't be | ||
84 | * found. | ||
85 | */ | ||
86 | public function reverseTransform($values) | ||
87 | { | ||
88 | if (!is_array($values)) { | ||
89 | throw new TransformationFailedException('Expected an array.'); | ||
90 | } | ||
91 | |||
92 | try { | ||
93 | $choices = $this->choiceList->getChoices(); | ||
94 | } catch (\Exception $e) { | ||
95 | throw new TransformationFailedException('Can not get the choice list', $e->getCode(), $e); | ||
96 | } | ||
97 | |||
98 | $result = array(); | ||
99 | $unknown = array(); | ||
100 | |||
101 | foreach ($values as $i => $selected) { | ||
102 | if ($selected) { | ||
103 | if (isset($choices[$i])) { | ||
104 | $result[] = $choices[$i]; | ||
105 | } else { | ||
106 | $unknown[] = $i; | ||
107 | } | ||
108 | } | ||
109 | } | ||
110 | |||
111 | if (count($unknown) > 0) { | ||
112 | throw new TransformationFailedException(sprintf('The choices "%s" were not found', implode('", "', $unknown))); | ||
113 | } | ||
114 | |||
115 | return $result; | ||
116 | } | ||
117 | } | ||
diff --git a/vendor/symfony/form/Symfony/Component/Form/Extension/Core/DataTransformer/ChoicesToValuesTransformer.php b/vendor/symfony/form/Symfony/Component/Form/Extension/Core/DataTransformer/ChoicesToValuesTransformer.php deleted file mode 100644 index 4492865e..00000000 --- a/vendor/symfony/form/Symfony/Component/Form/Extension/Core/DataTransformer/ChoicesToValuesTransformer.php +++ /dev/null | |||
@@ -1,83 +0,0 @@ | |||
1 | <?php | ||
2 | |||
3 | /* | ||
4 | * This file is part of the Symfony package. | ||
5 | * | ||
6 | * (c) Fabien Potencier <fabien@symfony.com> | ||
7 | * | ||
8 | * For the full copyright and license information, please view the LICENSE | ||
9 | * file that was distributed with this source code. | ||
10 | */ | ||
11 | |||
12 | namespace Symfony\Component\Form\Extension\Core\DataTransformer; | ||
13 | |||
14 | use Symfony\Component\Form\Exception\TransformationFailedException; | ||
15 | |||
16 | use Symfony\Component\Form\DataTransformerInterface; | ||
17 | use Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceListInterface; | ||
18 | |||
19 | /** | ||
20 | * @author Bernhard Schussek <bschussek@gmail.com> | ||
21 | */ | ||
22 | class ChoicesToValuesTransformer implements DataTransformerInterface | ||
23 | { | ||
24 | private $choiceList; | ||
25 | |||
26 | /** | ||
27 | * Constructor. | ||
28 | * | ||
29 | * @param ChoiceListInterface $choiceList | ||
30 | */ | ||
31 | public function __construct(ChoiceListInterface $choiceList) | ||
32 | { | ||
33 | $this->choiceList = $choiceList; | ||
34 | } | ||
35 | |||
36 | /** | ||
37 | * @param array $array | ||
38 | * | ||
39 | * @return array | ||
40 | * | ||
41 | * @throws TransformationFailedException If the given value is not an array. | ||
42 | */ | ||
43 | public function transform($array) | ||
44 | { | ||
45 | if (null === $array) { | ||
46 | return array(); | ||
47 | } | ||
48 | |||
49 | if (!is_array($array)) { | ||
50 | throw new TransformationFailedException('Expected an array.'); | ||
51 | } | ||
52 | |||
53 | return $this->choiceList->getValuesForChoices($array); | ||
54 | } | ||
55 | |||
56 | /** | ||
57 | * @param array $array | ||
58 | * | ||
59 | * @return array | ||
60 | * | ||
61 | * @throws TransformationFailedException If the given value is not an array | ||
62 | * or if no matching choice could be | ||
63 | * found for some given value. | ||
64 | */ | ||
65 | public function reverseTransform($array) | ||
66 | { | ||
67 | if (null === $array) { | ||
68 | return array(); | ||
69 | } | ||
70 | |||
71 | if (!is_array($array)) { | ||
72 | throw new TransformationFailedException('Expected an array.'); | ||
73 | } | ||
74 | |||
75 | $choices = $this->choiceList->getChoicesForValues($array); | ||
76 | |||
77 | if (count($choices) !== count($array)) { | ||
78 | throw new TransformationFailedException('Could not find all matching choices for the given values'); | ||
79 | } | ||
80 | |||
81 | return $choices; | ||
82 | } | ||
83 | } | ||
diff --git a/vendor/symfony/form/Symfony/Component/Form/Extension/Core/DataTransformer/DataTransformerChain.php b/vendor/symfony/form/Symfony/Component/Form/Extension/Core/DataTransformer/DataTransformerChain.php deleted file mode 100644 index 9cc185e1..00000000 --- a/vendor/symfony/form/Symfony/Component/Form/Extension/Core/DataTransformer/DataTransformerChain.php +++ /dev/null | |||
@@ -1,86 +0,0 @@ | |||
1 | <?php | ||
2 | |||
3 | /* | ||
4 | * This file is part of the Symfony package. | ||
5 | * | ||
6 | * (c) Fabien Potencier <fabien@symfony.com> | ||
7 | * | ||
8 | * For the full copyright and license information, please view the LICENSE | ||
9 | * file that was distributed with this source code. | ||
10 | */ | ||
11 | |||
12 | namespace Symfony\Component\Form\Extension\Core\DataTransformer; | ||
13 | |||
14 | use Symfony\Component\Form\DataTransformerInterface; | ||
15 | use Symfony\Component\Form\Exception\TransformationFailedException; | ||
16 | |||
17 | /** | ||
18 | * Passes a value through multiple value transformers | ||
19 | * | ||
20 | * @author Bernhard Schussek <bschussek@gmail.com> | ||
21 | */ | ||
22 | class DataTransformerChain implements DataTransformerInterface | ||
23 | { | ||
24 | /** | ||
25 | * The value transformers | ||
26 | * @var DataTransformerInterface[] | ||
27 | */ | ||
28 | protected $transformers; | ||
29 | |||
30 | /** | ||
31 | * Uses the given value transformers to transform values | ||
32 | * | ||
33 | * @param array $transformers | ||
34 | */ | ||
35 | public function __construct(array $transformers) | ||
36 | { | ||
37 | $this->transformers = $transformers; | ||
38 | } | ||
39 | |||
40 | /** | ||
41 | * Passes the value through the transform() method of all nested transformers | ||
42 | * | ||
43 | * The transformers receive the value in the same order as they were passed | ||
44 | * to the constructor. Each transformer receives the result of the previous | ||
45 | * transformer as input. The output of the last transformer is returned | ||
46 | * by this method. | ||
47 | * | ||
48 | * @param mixed $value The original value | ||
49 | * | ||
50 | * @return mixed The transformed value | ||
51 | * | ||
52 | * @throws TransformationFailedException | ||
53 | */ | ||
54 | public function transform($value) | ||
55 | { | ||
56 | foreach ($this->transformers as $transformer) { | ||
57 | $value = $transformer->transform($value); | ||
58 | } | ||
59 | |||
60 | return $value; | ||
61 | } | ||
62 | |||
63 | /** | ||
64 | * Passes the value through the reverseTransform() method of all nested | ||
65 | * transformers | ||
66 | * | ||
67 | * The transformers receive the value in the reverse order as they were passed | ||
68 | * to the constructor. Each transformer receives the result of the previous | ||
69 | * transformer as input. The output of the last transformer is returned | ||
70 | * by this method. | ||
71 | * | ||
72 | * @param mixed $value The transformed value | ||
73 | * | ||
74 | * @return mixed The reverse-transformed value | ||
75 | * | ||
76 | * @throws TransformationFailedException | ||
77 | */ | ||
78 | public function reverseTransform($value) | ||
79 | { | ||
80 | for ($i = count($this->transformers) - 1; $i >= 0; --$i) { | ||
81 | $value = $this->transformers[$i]->reverseTransform($value); | ||
82 | } | ||
83 | |||
84 | return $value; | ||
85 | } | ||
86 | } | ||
diff --git a/vendor/symfony/form/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeToArrayTransformer.php b/vendor/symfony/form/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeToArrayTransformer.php deleted file mode 100644 index 34af2820..00000000 --- a/vendor/symfony/form/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeToArrayTransformer.php +++ /dev/null | |||
@@ -1,184 +0,0 @@ | |||
1 | <?php | ||
2 | |||
3 | /* | ||
4 | * This file is part of the Symfony package. | ||
5 | * | ||
6 | * (c) Fabien Potencier <fabien@symfony.com> | ||
7 | * | ||
8 | * For the full copyright and license information, please view the LICENSE | ||
9 | * file that was distributed with this source code. | ||
10 | */ | ||
11 | |||
12 | namespace Symfony\Component\Form\Extension\Core\DataTransformer; | ||
13 | |||
14 | use Symfony\Component\Form\Exception\TransformationFailedException; | ||
15 | use Symfony\Component\Form\Exception\UnexpectedTypeException; | ||
16 | |||
17 | /** | ||
18 | * Transforms between a normalized time and a localized time string/array. | ||
19 | * | ||
20 | * @author Bernhard Schussek <bschussek@gmail.com> | ||
21 | * @author Florian Eckerstorfer <florian@eckerstorfer.org> | ||
22 | */ | ||
23 | class DateTimeToArrayTransformer extends BaseDateTimeTransformer | ||
24 | { | ||
25 | private $pad; | ||
26 | |||
27 | private $fields; | ||
28 | |||
29 | /** | ||
30 | * Constructor. | ||
31 | * | ||
32 | * @param string $inputTimezone The input timezone | ||
33 | * @param string $outputTimezone The output timezone | ||
34 | * @param array $fields The date fields | ||
35 | * @param Boolean $pad Whether to use padding | ||
36 | * | ||
37 | * @throws UnexpectedTypeException if a timezone is not a string | ||
38 | */ | ||
39 | public function __construct($inputTimezone = null, $outputTimezone = null, array $fields = null, $pad = false) | ||
40 | { | ||
41 | parent::__construct($inputTimezone, $outputTimezone); | ||
42 | |||
43 | if (null === $fields) { | ||
44 | $fields = array('year', 'month', 'day', 'hour', 'minute', 'second'); | ||
45 | } | ||
46 | |||
47 | $this->fields = $fields; | ||
48 | $this->pad = (Boolean) $pad; | ||
49 | } | ||
50 | |||
51 | /** | ||
52 | * Transforms a normalized date into a localized date. | ||
53 | * | ||
54 | * @param \DateTime $dateTime Normalized date. | ||
55 | * | ||
56 | * @return array Localized date. | ||
57 | * | ||
58 | * @throws TransformationFailedException If the given value is not an | ||
59 | * instance of \DateTime or if the | ||
60 | * output timezone is not supported. | ||
61 | */ | ||
62 | public function transform($dateTime) | ||
63 | { | ||
64 | if (null === $dateTime) { | ||
65 | return array_intersect_key(array( | ||
66 | 'year' => '', | ||
67 | 'month' => '', | ||
68 | 'day' => '', | ||
69 | 'hour' => '', | ||
70 | 'minute' => '', | ||
71 | 'second' => '', | ||
72 | ), array_flip($this->fields)); | ||
73 | } | ||
74 | |||
75 | if (!$dateTime instanceof \DateTime) { | ||
76 | throw new TransformationFailedException('Expected a \DateTime.'); | ||
77 | } | ||
78 | |||
79 | $dateTime = clone $dateTime; | ||
80 | if ($this->inputTimezone !== $this->outputTimezone) { | ||
81 | try { | ||
82 | $dateTime->setTimezone(new \DateTimeZone($this->outputTimezone)); | ||
83 | } catch (\Exception $e) { | ||
84 | throw new TransformationFailedException($e->getMessage(), $e->getCode(), $e); | ||
85 | } | ||
86 | } | ||
87 | |||
88 | $result = array_intersect_key(array( | ||
89 | 'year' => $dateTime->format('Y'), | ||
90 | 'month' => $dateTime->format('m'), | ||
91 | 'day' => $dateTime->format('d'), | ||
92 | 'hour' => $dateTime->format('H'), | ||
93 | 'minute' => $dateTime->format('i'), | ||
94 | 'second' => $dateTime->format('s'), | ||
95 | ), array_flip($this->fields)); | ||
96 | |||
97 | if (!$this->pad) { | ||
98 | foreach ($result as &$entry) { | ||
99 | // remove leading zeros | ||
100 | $entry = (string) (int) $entry; | ||
101 | } | ||
102 | } | ||
103 | |||
104 | return $result; | ||
105 | } | ||
106 | |||
107 | /** | ||
108 | * Transforms a localized date into a normalized date. | ||
109 | * | ||
110 | * @param array $value Localized date | ||
111 | * | ||
112 | * @return \DateTime Normalized date | ||
113 | * | ||
114 | * @throws TransformationFailedException If the given value is not an array, | ||
115 | * if the value could not be transformed | ||
116 | * or if the input timezone is not | ||
117 | * supported. | ||
118 | */ | ||
119 | public function reverseTransform($value) | ||
120 | { | ||
121 | if (null === $value) { | ||
122 | return null; | ||
123 | } | ||
124 | |||
125 | if (!is_array($value)) { | ||
126 | throw new TransformationFailedException('Expected an array.'); | ||
127 | } | ||
128 | |||
129 | if ('' === implode('', $value)) { | ||
130 | return null; | ||
131 | } | ||
132 | |||
133 | $emptyFields = array(); | ||
134 | |||
135 | foreach ($this->fields as $field) { | ||
136 | if (!isset($value[$field])) { | ||
137 | $emptyFields[] = $field; | ||
138 | } | ||
139 | } | ||
140 | |||
141 | if (count($emptyFields) > 0) { | ||
142 | throw new TransformationFailedException( | ||
143 | sprintf('The fields "%s" should not be empty', implode('", "', $emptyFields) | ||
144 | )); | ||
145 | } | ||
146 | |||
147 | if (isset($value['month']) && !ctype_digit($value['month']) && !is_int($value['month'])) { | ||
148 | throw new TransformationFailedException('This month is invalid'); | ||
149 | } | ||
150 | |||
151 | if (isset($value['day']) && !ctype_digit($value['day']) && !is_int($value['day'])) { | ||
152 | throw new TransformationFailedException('This day is invalid'); | ||
153 | } | ||
154 | |||
155 | if (isset($value['year']) && !ctype_digit($value['year']) && !is_int($value['year'])) { | ||
156 | throw new TransformationFailedException('This year is invalid'); | ||
157 | } | ||
158 | |||
159 | if (!empty($value['month']) && !empty($value['day']) && !empty($value['year']) && false === checkdate($value['month'], $value['day'], $value['year'])) { | ||
160 | throw new TransformationFailedException('This is an invalid date'); | ||
161 | } | ||
162 | |||
163 | try { | ||
164 | $dateTime = new \DateTime(sprintf( | ||
165 | '%s-%s-%s %s:%s:%s %s', | ||
166 | empty($value['year']) ? '1970' : $value['year'], | ||
167 | empty($value['month']) ? '1' : $value['month'], | ||
168 | empty($value['day']) ? '1' : $value['day'], | ||
169 | empty($value['hour']) ? '0' : $value['hour'], | ||
170 | empty($value['minute']) ? '0' : $value['minute'], | ||
171 | empty($value['second']) ? '0' : $value['second'], | ||
172 | $this->outputTimezone | ||
173 | )); | ||
174 | |||
175 | if ($this->inputTimezone !== $this->outputTimezone) { | ||
176 | $dateTime->setTimezone(new \DateTimeZone($this->inputTimezone)); | ||
177 | } | ||
178 | } catch (\Exception $e) { | ||
179 | throw new TransformationFailedException($e->getMessage(), $e->getCode(), $e); | ||
180 | } | ||
181 | |||
182 | return $dateTime; | ||
183 | } | ||
184 | } | ||
diff --git a/vendor/symfony/form/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeToLocalizedStringTransformer.php b/vendor/symfony/form/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeToLocalizedStringTransformer.php deleted file mode 100644 index d755e485..00000000 --- a/vendor/symfony/form/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeToLocalizedStringTransformer.php +++ /dev/null | |||
@@ -1,169 +0,0 @@ | |||
1 | <?php | ||
2 | |||
3 | /* | ||
4 | * This file is part of the Symfony package. | ||
5 | * | ||
6 | * (c) Fabien Potencier <fabien@symfony.com> | ||
7 | * | ||
8 | * For the full copyright and license information, please view the LICENSE | ||
9 | * file that was distributed with this source code. | ||
10 | */ | ||
11 | |||
12 | namespace Symfony\Component\Form\Extension\Core\DataTransformer; | ||
13 | |||
14 | use Symfony\Component\Form\Exception\TransformationFailedException; | ||
15 | use Symfony\Component\Form\Exception\UnexpectedTypeException; | ||
16 | |||
17 | /** | ||
18 | * Transforms between a normalized time and a localized time string | ||
19 | * | ||
20 | * @author Bernhard Schussek <bschussek@gmail.com> | ||
21 | * @author Florian Eckerstorfer <florian@eckerstorfer.org> | ||
22 | */ | ||
23 | class DateTimeToLocalizedStringTransformer extends BaseDateTimeTransformer | ||
24 | { | ||
25 | private $dateFormat; | ||
26 | private $timeFormat; | ||
27 | private $pattern; | ||
28 | private $calendar; | ||
29 | |||
30 | /** | ||
31 | * Constructor. | ||
32 | * | ||
33 | * @see BaseDateTimeTransformer::formats for available format options | ||
34 | * | ||
35 | * @param string $inputTimezone The name of the input timezone | ||
36 | * @param string $outputTimezone The name of the output timezone | ||
37 | * @param integer $dateFormat The date format | ||
38 | * @param integer $timeFormat The time format | ||
39 | * @param integer $calendar One of the \IntlDateFormatter calendar constants | ||
40 | * @param string $pattern A pattern to pass to \IntlDateFormatter | ||
41 | * | ||
42 | * @throws UnexpectedTypeException If a format is not supported or if a timezone is not a string | ||
43 | */ | ||
44 | public function __construct($inputTimezone = null, $outputTimezone = null, $dateFormat = null, $timeFormat = null, $calendar = \IntlDateFormatter::GREGORIAN, $pattern = null) | ||
45 | { | ||
46 | parent::__construct($inputTimezone, $outputTimezone); | ||
47 | |||
48 | if (null === $dateFormat) { | ||
49 | $dateFormat = \IntlDateFormatter::MEDIUM; | ||
50 | } | ||
51 | |||
52 | if (null === $timeFormat) { | ||
53 | $timeFormat = \IntlDateFormatter::SHORT; | ||
54 | } | ||
55 | |||
56 | if (!in_array($dateFormat, self::$formats, true)) { | ||
57 | throw new UnexpectedTypeException($dateFormat, implode('", "', self::$formats)); | ||
58 | } | ||
59 | |||
60 | if (!in_array($timeFormat, self::$formats, true)) { | ||
61 | throw new UnexpectedTypeException($timeFormat, implode('", "', self::$formats)); | ||
62 | } | ||
63 | |||
64 | $this->dateFormat = $dateFormat; | ||
65 | $this->timeFormat = $timeFormat; | ||
66 | $this->calendar = $calendar; | ||
67 | $this->pattern = $pattern; | ||
68 | } | ||
69 | |||
70 | /** | ||
71 | * Transforms a normalized date into a localized date string/array. | ||
72 | * | ||
73 | * @param \DateTime $dateTime Normalized date. | ||
74 | * | ||
75 | * @return string|array Localized date string/array. | ||
76 | * | ||
77 | * @throws TransformationFailedException If the given value is not an instance | ||
78 | * of \DateTime or if the date could not | ||
79 | * be transformed. | ||
80 | */ | ||
81 | public function transform($dateTime) | ||
82 | { | ||
83 | if (null === $dateTime) { | ||
84 | return ''; | ||
85 | } | ||
86 | |||
87 | if (!$dateTime instanceof \DateTime) { | ||
88 | throw new TransformationFailedException('Expected a \DateTime.'); | ||
89 | } | ||
90 | |||
91 | // convert time to UTC before passing it to the formatter | ||
92 | $dateTime = clone $dateTime; | ||
93 | if ('UTC' !== $this->inputTimezone) { | ||
94 | $dateTime->setTimezone(new \DateTimeZone('UTC')); | ||
95 | } | ||
96 | |||
97 | $value = $this->getIntlDateFormatter()->format((int) $dateTime->format('U')); | ||
98 | |||
99 | if (intl_get_error_code() != 0) { | ||
100 | throw new TransformationFailedException(intl_get_error_message()); | ||
101 | } | ||
102 | |||
103 | return $value; | ||
104 | } | ||
105 | |||
106 | /** | ||
107 | * Transforms a localized date string/array into a normalized date. | ||
108 | * | ||
109 | * @param string|array $value Localized date string/array | ||
110 | * | ||
111 | * @return \DateTime Normalized date | ||
112 | * | ||
113 | * @throws TransformationFailedException if the given value is not a string, | ||
114 | * if the date could not be parsed or | ||
115 | * if the input timezone is not supported | ||
116 | */ | ||
117 | public function reverseTransform($value) | ||
118 | { | ||
119 | if (!is_string($value)) { | ||
120 | throw new TransformationFailedException('Expected a string.'); | ||
121 | } | ||
122 | |||
123 | if ('' === $value) { | ||
124 | return null; | ||
125 | } | ||
126 | |||
127 | $timestamp = $this->getIntlDateFormatter()->parse($value); | ||
128 | |||
129 | if (intl_get_error_code() != 0) { | ||
130 | throw new TransformationFailedException(intl_get_error_message()); | ||
131 | } | ||
132 | |||
133 | try { | ||
134 | // read timestamp into DateTime object - the formatter delivers in UTC | ||
135 | $dateTime = new \DateTime(sprintf('@%s UTC', $timestamp)); | ||
136 | } catch (\Exception $e) { | ||
137 | throw new TransformationFailedException($e->getMessage(), $e->getCode(), $e); | ||
138 | } | ||
139 | |||
140 | if ('UTC' !== $this->inputTimezone) { | ||
141 | try { | ||
142 | $dateTime->setTimezone(new \DateTimeZone($this->inputTimezone)); | ||
143 | } catch (\Exception $e) { | ||
144 | throw new TransformationFailedException($e->getMessage(), $e->getCode(), $e); | ||
145 | } | ||
146 | } | ||
147 | |||
148 | return $dateTime; | ||
149 | } | ||
150 | |||
151 | /** | ||
152 | * Returns a preconfigured IntlDateFormatter instance | ||
153 | * | ||
154 | * @return \IntlDateFormatter | ||
155 | */ | ||
156 | protected function getIntlDateFormatter() | ||
157 | { | ||
158 | $dateFormat = $this->dateFormat; | ||
159 | $timeFormat = $this->timeFormat; | ||
160 | $timezone = $this->outputTimezone; | ||
161 | $calendar = $this->calendar; | ||
162 | $pattern = $this->pattern; | ||
163 | |||
164 | $intlDateFormatter = new \IntlDateFormatter(\Locale::getDefault(), $dateFormat, $timeFormat, $timezone, $calendar, $pattern); | ||
165 | $intlDateFormatter->setLenient(false); | ||
166 | |||
167 | return $intlDateFormatter; | ||
168 | } | ||
169 | } | ||
diff --git a/vendor/symfony/form/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeToRfc3339Transformer.php b/vendor/symfony/form/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeToRfc3339Transformer.php deleted file mode 100644 index 0eb07422..00000000 --- a/vendor/symfony/form/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeToRfc3339Transformer.php +++ /dev/null | |||
@@ -1,82 +0,0 @@ | |||
1 | <?php | ||
2 | |||
3 | /* | ||
4 | * This file is part of the Symfony package. | ||
5 | * | ||
6 | * (c) Fabien Potencier <fabien@symfony.com> | ||
7 | * | ||
8 | * For the full copyright and license information, please view the LICENSE | ||
9 | * file that was distributed with this source code. | ||
10 | */ | ||
11 | |||
12 | namespace Symfony\Component\Form\Extension\Core\DataTransformer; | ||
13 | |||
14 | use Symfony\Component\Form\Exception\TransformationFailedException; | ||
15 | |||
16 | /** | ||
17 | * @author Bernhard Schussek <bschussek@gmail.com> | ||
18 | */ | ||
19 | class DateTimeToRfc3339Transformer extends BaseDateTimeTransformer | ||
20 | { | ||
21 | /** | ||
22 | * {@inheritDoc} | ||
23 | */ | ||
24 | public function transform($dateTime) | ||
25 | { | ||
26 | if (null === $dateTime) { | ||
27 | return ''; | ||
28 | } | ||
29 | |||
30 | if (!$dateTime instanceof \DateTime) { | ||
31 | throw new TransformationFailedException('Expected a \DateTime.'); | ||
32 | } | ||
33 | |||
34 | if ($this->inputTimezone !== $this->outputTimezone) { | ||
35 | $dateTime = clone $dateTime; | ||
36 | $dateTime->setTimezone(new \DateTimeZone($this->outputTimezone)); | ||
37 | } | ||
38 | |||
39 | return preg_replace('/\+00:00$/', 'Z', $dateTime->format('c')); | ||
40 | } | ||
41 | |||
42 | /** | ||
43 | * {@inheritDoc} | ||
44 | */ | ||
45 | public function reverseTransform($rfc3339) | ||
46 | { | ||
47 | if (!is_string($rfc3339)) { | ||
48 | throw new TransformationFailedException('Expected a string.'); | ||
49 | } | ||
50 | |||
51 | if ('' === $rfc3339) { | ||
52 | return null; | ||
53 | } | ||
54 | |||
55 | try { | ||
56 | $dateTime = new \DateTime($rfc3339); | ||
57 | } catch (\Exception $e) { | ||
58 | throw new TransformationFailedException($e->getMessage(), $e->getCode(), $e); | ||
59 | } | ||
60 | |||
61 | if ($this->outputTimezone !== $this->inputTimezone) { | ||
62 | try { | ||
63 | $dateTime->setTimezone(new \DateTimeZone($this->inputTimezone)); | ||
64 | } catch (\Exception $e) { | ||
65 | throw new TransformationFailedException($e->getMessage(), $e->getCode(), $e); | ||
66 | } | ||
67 | } | ||
68 | |||
69 | if (preg_match('/(\d{4})-(\d{2})-(\d{2})/', $rfc3339, $matches)) { | ||
70 | if (!checkdate($matches[2], $matches[3], $matches[1])) { | ||
71 | throw new TransformationFailedException(sprintf( | ||
72 | 'The date "%s-%s-%s" is not a valid date.', | ||
73 | $matches[1], | ||
74 | $matches[2], | ||
75 | $matches[3] | ||
76 | )); | ||
77 | } | ||
78 | } | ||
79 | |||
80 | return $dateTime; | ||
81 | } | ||
82 | } | ||
diff --git a/vendor/symfony/form/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeToStringTransformer.php b/vendor/symfony/form/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeToStringTransformer.php deleted file mode 100644 index 131f45cb..00000000 --- a/vendor/symfony/form/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeToStringTransformer.php +++ /dev/null | |||
@@ -1,231 +0,0 @@ | |||
1 | <?php | ||
2 | |||
3 | /* | ||
4 | * This file is part of the Symfony package. | ||
5 | * | ||
6 | * (c) Fabien Potencier <fabien@symfony.com> | ||
7 | * | ||
8 | * For the full copyright and license information, please view the LICENSE | ||
9 | * file that was distributed with this source code. | ||
10 | */ | ||
11 | |||
12 | namespace Symfony\Component\Form\Extension\Core\DataTransformer; | ||
13 | |||
14 | use Symfony\Component\Form\Exception\TransformationFailedException; | ||
15 | use Symfony\Component\Form\Exception\UnexpectedTypeException; | ||
16 | |||
17 | /** | ||
18 | * Transforms between a date string and a DateTime object | ||
19 | * | ||
20 | * @author Bernhard Schussek <bschussek@gmail.com> | ||
21 | * @author Florian Eckerstorfer <florian@eckerstorfer.org> | ||
22 | */ | ||
23 | class DateTimeToStringTransformer extends BaseDateTimeTransformer | ||
24 | { | ||
25 | /** | ||
26 | * Format used for generating strings | ||
27 | * @var string | ||
28 | */ | ||
29 | private $generateFormat; | ||
30 | |||
31 | /** | ||
32 | * Format used for parsing strings | ||
33 | * | ||
34 | * Different than the {@link $generateFormat} because formats for parsing | ||
35 | * support additional characters in PHP that are not supported for | ||
36 | * generating strings. | ||
37 | * | ||
38 | * @var string | ||
39 | */ | ||
40 | private $parseFormat; | ||
41 | |||
42 | /** | ||
43 | * Whether to parse by appending a pipe "|" to the parse format. | ||
44 | * | ||
45 | * This only works as of PHP 5.3.7. | ||
46 | * | ||
47 | * @var Boolean | ||
48 | */ | ||
49 | private $parseUsingPipe; | ||
50 | |||
51 | /** | ||
52 | * Transforms a \DateTime instance to a string | ||
53 | * | ||
54 | * @see \DateTime::format() for supported formats | ||
55 | * | ||
56 | * @param string $inputTimezone The name of the input timezone | ||
57 | * @param string $outputTimezone The name of the output timezone | ||
58 | * @param string $format The date format | ||
59 | * @param Boolean $parseUsingPipe Whether to parse by appending a pipe "|" to the parse format | ||
60 | * | ||
61 | * @throws UnexpectedTypeException if a timezone is not a string | ||
62 | */ | ||
63 | public function __construct($inputTimezone = null, $outputTimezone = null, $format = 'Y-m-d H:i:s', $parseUsingPipe = null) | ||
64 | { | ||
65 | parent::__construct($inputTimezone, $outputTimezone); | ||
66 | |||
67 | $this->generateFormat = $this->parseFormat = $format; | ||
68 | |||
69 | // The pipe in the parser pattern only works as of PHP 5.3.7 | ||
70 | // See http://bugs.php.net/54316 | ||
71 | $this->parseUsingPipe = null === $parseUsingPipe | ||
72 | ? version_compare(phpversion(), '5.3.7', '>=') | ||
73 | : $parseUsingPipe; | ||
74 | |||
75 | // See http://php.net/manual/en/datetime.createfromformat.php | ||
76 | // The character "|" in the format makes sure that the parts of a date | ||
77 | // that are *not* specified in the format are reset to the corresponding | ||
78 | // values from 1970-01-01 00:00:00 instead of the current time. | ||
79 | // Without "|" and "Y-m-d", "2010-02-03" becomes "2010-02-03 12:32:47", | ||
80 | // where the time corresponds to the current server time. | ||
81 | // With "|" and "Y-m-d", "2010-02-03" becomes "2010-02-03 00:00:00", | ||
82 | // which is at least deterministic and thus used here. | ||
83 | if ($this->parseUsingPipe && false === strpos($this->parseFormat, '|')) { | ||
84 | $this->parseFormat .= '|'; | ||
85 | } | ||
86 | } | ||
87 | |||
88 | /** | ||
89 | * Transforms a DateTime object into a date string with the configured format | ||
90 | * and timezone | ||
91 | * | ||
92 | * @param \DateTime $value A DateTime object | ||
93 | * | ||
94 | * @return string A value as produced by PHP's date() function | ||
95 | * | ||
96 | * @throws TransformationFailedException If the given value is not a \DateTime | ||
97 | * instance or if the output timezone | ||
98 | * is not supported. | ||
99 | */ | ||
100 | public function transform($value) | ||
101 | { | ||
102 | if (null === $value) { | ||
103 | return ''; | ||
104 | } | ||
105 | |||
106 | if (!$value instanceof \DateTime) { | ||
107 | throw new TransformationFailedException('Expected a \DateTime.'); | ||
108 | } | ||
109 | |||
110 | $value = clone $value; | ||
111 | try { | ||
112 | $value->setTimezone(new \DateTimeZone($this->outputTimezone)); | ||
113 | } catch (\Exception $e) { | ||
114 | throw new TransformationFailedException($e->getMessage(), $e->getCode(), $e); | ||
115 | } | ||
116 | |||
117 | return $value->format($this->generateFormat); | ||
118 | } | ||
119 | |||
120 | /** | ||
121 | * Transforms a date string in the configured timezone into a DateTime object. | ||
122 | * | ||
123 | * @param string $value A value as produced by PHP's date() function | ||
124 | * | ||
125 | * @return \DateTime An instance of \DateTime | ||
126 | * | ||
127 | * @throws TransformationFailedException If the given value is not a string, | ||
128 | * if the date could not be parsed or | ||
129 | * if the input timezone is not supported. | ||
130 | */ | ||
131 | public function reverseTransform($value) | ||
132 | { | ||
133 | if (empty($value)) { | ||
134 | return null; | ||
135 | } | ||
136 | |||
137 | if (!is_string($value)) { | ||
138 | throw new TransformationFailedException('Expected a string.'); | ||
139 | } | ||
140 | |||
141 | try { | ||
142 | $outputTz = new \DateTimeZone($this->outputTimezone); | ||
143 | $dateTime = \DateTime::createFromFormat($this->parseFormat, $value, $outputTz); | ||
144 | |||
145 | $lastErrors = \DateTime::getLastErrors(); | ||
146 | |||
147 | if (0 < $lastErrors['warning_count'] || 0 < $lastErrors['error_count']) { | ||
148 | throw new TransformationFailedException( | ||
149 | implode(', ', array_merge( | ||
150 | array_values($lastErrors['warnings']), | ||
151 | array_values($lastErrors['errors']) | ||
152 | )) | ||
153 | ); | ||
154 | } | ||
155 | |||
156 | // On PHP versions < 5.3.7 we need to emulate the pipe operator | ||
157 | // and reset parts not given in the format to their equivalent | ||
158 | // of the UNIX base timestamp. | ||
159 | if (!$this->parseUsingPipe) { | ||
160 | list($year, $month, $day, $hour, $minute, $second) = explode('-', $dateTime->format('Y-m-d-H-i-s')); | ||
161 | |||
162 | // Check which of the date parts are present in the pattern | ||
163 | preg_match( | ||
164 | '/(' . | ||
165 | '(?P<day>[djDl])|' . | ||
166 | '(?P<month>[FMmn])|' . | ||
167 | '(?P<year>[Yy])|' . | ||
168 | '(?P<hour>[ghGH])|' . | ||
169 | '(?P<minute>i)|' . | ||
170 | '(?P<second>s)|' . | ||
171 | '(?P<dayofyear>z)|' . | ||
172 | '(?P<timestamp>U)|' . | ||
173 | '[^djDlFMmnYyghGHiszU]' . | ||
174 | ')*/', | ||
175 | $this->parseFormat, | ||
176 | $matches | ||
177 | ); | ||
178 | |||
179 | // preg_match() does not guarantee to set all indices, so | ||
180 | // set them unless given | ||
181 | $matches = array_merge(array( | ||
182 | 'day' => false, | ||
183 | 'month' => false, | ||
184 | 'year' => false, | ||
185 | 'hour' => false, | ||
186 | 'minute' => false, | ||
187 | 'second' => false, | ||
188 | 'dayofyear' => false, | ||
189 | 'timestamp' => false, | ||
190 | ), $matches); | ||
191 | |||
192 | // Reset all parts that don't exist in the format to the | ||
193 | // corresponding part of the UNIX base timestamp | ||
194 | if (!$matches['timestamp']) { | ||
195 | if (!$matches['dayofyear']) { | ||
196 | if (!$matches['day']) { | ||
197 | $day = 1; | ||
198 | } | ||
199 | if (!$matches['month']) { | ||
200 | $month = 1; | ||
201 | } | ||
202 | } | ||
203 | if (!$matches['year']) { | ||
204 | $year = 1970; | ||
205 | } | ||
206 | if (!$matches['hour']) { | ||
207 | $hour = 0; | ||
208 | } | ||
209 | if (!$matches['minute']) { | ||
210 | $minute = 0; | ||
211 | } | ||
212 | if (!$matches['second']) { | ||
213 | $second = 0; | ||
214 | } | ||
215 | $dateTime->setDate($year, $month, $day); | ||
216 | $dateTime->setTime($hour, $minute, $second); | ||
217 | } | ||
218 | } | ||
219 | |||
220 | if ($this->inputTimezone !== $this->outputTimezone) { | ||
221 | $dateTime->setTimeZone(new \DateTimeZone($this->inputTimezone)); | ||
222 | } | ||
223 | } catch (TransformationFailedException $e) { | ||
224 | throw $e; | ||
225 | } catch (\Exception $e) { | ||
226 | throw new TransformationFailedException($e->getMessage(), $e->getCode(), $e); | ||
227 | } | ||
228 | |||
229 | return $dateTime; | ||
230 | } | ||
231 | } | ||
diff --git a/vendor/symfony/form/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeToTimestampTransformer.php b/vendor/symfony/form/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeToTimestampTransformer.php deleted file mode 100644 index d2ca6604..00000000 --- a/vendor/symfony/form/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeToTimestampTransformer.php +++ /dev/null | |||
@@ -1,89 +0,0 @@ | |||
1 | <?php | ||
2 | |||
3 | /* | ||
4 | * This file is part of the Symfony package. | ||
5 | * | ||
6 | * (c) Fabien Potencier <fabien@symfony.com> | ||
7 | * | ||
8 | * For the full copyright and license information, please view the LICENSE | ||
9 | * file that was distributed with this source code. | ||
10 | */ | ||
11 | |||
12 | namespace Symfony\Component\Form\Extension\Core\DataTransformer; | ||
13 | |||
14 | use Symfony\Component\Form\Exception\TransformationFailedException; | ||
15 | |||
16 | /** | ||
17 | * Transforms between a timestamp and a DateTime object | ||
18 | * | ||
19 | * @author Bernhard Schussek <bschussek@gmail.com> | ||
20 | * @author Florian Eckerstorfer <florian@eckerstorfer.org> | ||
21 | */ | ||
22 | class DateTimeToTimestampTransformer extends BaseDateTimeTransformer | ||
23 | { | ||
24 | /** | ||
25 | * Transforms a DateTime object into a timestamp in the configured timezone. | ||
26 | * | ||
27 | * @param \DateTime $value A \DateTime object | ||
28 | * | ||
29 | * @return integer A timestamp | ||
30 | * | ||
31 | * @throws TransformationFailedException If the given value is not an instance | ||
32 | * of \DateTime or if the output | ||
33 | * timezone is not supported. | ||
34 | */ | ||
35 | public function transform($value) | ||
36 | { | ||
37 | if (null === $value) { | ||
38 | return null; | ||
39 | } | ||
40 | |||
41 | if (!$value instanceof \DateTime) { | ||
42 | throw new TransformationFailedException('Expected a \DateTime.'); | ||
43 | } | ||
44 | |||
45 | $value = clone $value; | ||
46 | try { | ||
47 | $value->setTimezone(new \DateTimeZone($this->outputTimezone)); | ||
48 | } catch (\Exception $e) { | ||
49 | throw new TransformationFailedException($e->getMessage(), $e->getCode(), $e); | ||
50 | } | ||
51 | |||
52 | return (int) $value->format('U'); | ||
53 | } | ||
54 | |||
55 | /** | ||
56 | * Transforms a timestamp in the configured timezone into a DateTime object | ||
57 | * | ||
58 | * @param string $value A timestamp | ||
59 | * | ||
60 | * @return \DateTime A \DateTime object | ||
61 | * | ||
62 | * @throws TransformationFailedException If the given value is not a timestamp | ||
63 | * or if the given timestamp is invalid. | ||
64 | */ | ||
65 | public function reverseTransform($value) | ||
66 | { | ||
67 | if (null === $value) { | ||
68 | return null; | ||
69 | } | ||
70 | |||
71 | if (!is_numeric($value)) { | ||
72 | throw new TransformationFailedException('Expected a numeric.'); | ||
73 | } | ||
74 | |||
75 | try { | ||
76 | $dateTime = new \DateTime(); | ||
77 | $dateTime->setTimezone(new \DateTimeZone($this->outputTimezone)); | ||
78 | $dateTime->setTimestamp($value); | ||
79 | |||
80 | if ($this->inputTimezone !== $this->outputTimezone) { | ||
81 | $dateTime->setTimezone(new \DateTimeZone($this->inputTimezone)); | ||
82 | } | ||
83 | } catch (\Exception $e) { | ||
84 | throw new TransformationFailedException($e->getMessage(), $e->getCode(), $e); | ||
85 | } | ||
86 | |||
87 | return $dateTime; | ||
88 | } | ||
89 | } | ||
diff --git a/vendor/symfony/form/Symfony/Component/Form/Extension/Core/DataTransformer/IntegerToLocalizedStringTransformer.php b/vendor/symfony/form/Symfony/Component/Form/Extension/Core/DataTransformer/IntegerToLocalizedStringTransformer.php deleted file mode 100644 index 6bb48a9a..00000000 --- a/vendor/symfony/form/Symfony/Component/Form/Extension/Core/DataTransformer/IntegerToLocalizedStringTransformer.php +++ /dev/null | |||
@@ -1,53 +0,0 @@ | |||
1 | <?php | ||
2 | |||
3 | /* | ||
4 | * This file is part of the Symfony package. | ||
5 | * | ||
6 | * (c) Fabien Potencier <fabien@symfony.com> | ||
7 | * | ||
8 | * For the full copyright and license information, please view the LICENSE | ||
9 | * file that was distributed with this source code. | ||
10 | */ | ||
11 | |||
12 | namespace Symfony\Component\Form\Extension\Core\DataTransformer; | ||
13 | |||
14 | use Symfony\Component\Form\Exception\TransformationFailedException; | ||
15 | |||
16 | /** | ||
17 | * Transforms between an integer and a localized number with grouping | ||
18 | * (each thousand) and comma separators. | ||
19 | * | ||
20 | * @author Bernhard Schussek <bschussek@gmail.com> | ||
21 | */ | ||
22 | class IntegerToLocalizedStringTransformer extends NumberToLocalizedStringTransformer | ||
23 | { | ||
24 | /** | ||
25 | * {@inheritDoc} | ||
26 | */ | ||
27 | public function reverseTransform($value) | ||
28 | { | ||
29 | if (!is_string($value)) { | ||
30 | throw new TransformationFailedException('Expected a string.'); | ||
31 | } | ||
32 | |||
33 | if ('' === $value) { | ||
34 | return null; | ||
35 | } | ||
36 | |||
37 | if ('NaN' === $value) { | ||
38 | throw new TransformationFailedException('"NaN" is not a valid integer'); | ||
39 | } | ||
40 | |||
41 | $formatter = $this->getNumberFormatter(); | ||
42 | $value = $formatter->parse( | ||
43 | $value, | ||
44 | PHP_INT_SIZE == 8 ? $formatter::TYPE_INT64 : $formatter::TYPE_INT32 | ||
45 | ); | ||
46 | |||
47 | if (intl_is_failure($formatter->getErrorCode())) { | ||
48 | throw new TransformationFailedException($formatter->getErrorMessage()); | ||
49 | } | ||
50 | |||
51 | return $value; | ||
52 | } | ||
53 | } | ||
diff --git a/vendor/symfony/form/Symfony/Component/Form/Extension/Core/DataTransformer/MoneyToLocalizedStringTransformer.php b/vendor/symfony/form/Symfony/Component/Form/Extension/Core/DataTransformer/MoneyToLocalizedStringTransformer.php deleted file mode 100644 index 5b8e9d96..00000000 --- a/vendor/symfony/form/Symfony/Component/Form/Extension/Core/DataTransformer/MoneyToLocalizedStringTransformer.php +++ /dev/null | |||
@@ -1,90 +0,0 @@ | |||
1 | <?php | ||
2 | |||
3 | /* | ||
4 | * This file is part of the Symfony package. | ||
5 | * | ||
6 | * (c) Fabien Potencier <fabien@symfony.com> | ||
7 | * | ||
8 | * For the full copyright and license information, please view the LICENSE | ||
9 | * file that was distributed with this source code. | ||
10 | */ | ||
11 | |||
12 | namespace Symfony\Component\Form\Extension\Core\DataTransformer; | ||
13 | |||
14 | use Symfony\Component\Form\Exception\TransformationFailedException; | ||
15 | |||
16 | /** | ||
17 | * Transforms between a normalized format and a localized money string. | ||
18 | * | ||
19 | * @author Bernhard Schussek <bschussek@gmail.com> | ||
20 | * @author Florian Eckerstorfer <florian@eckerstorfer.org> | ||
21 | */ | ||
22 | class MoneyToLocalizedStringTransformer extends NumberToLocalizedStringTransformer | ||
23 | { | ||
24 | |||
25 | private $divisor; | ||
26 | |||
27 | public function __construct($precision = null, $grouping = null, $roundingMode = null, $divisor = null) | ||
28 | { | ||
29 | if (null === $grouping) { | ||
30 | $grouping = true; | ||
31 | } | ||
32 | |||
33 | if (null === $precision) { | ||
34 | $precision = 2; | ||
35 | } | ||
36 | |||
37 | parent::__construct($precision, $grouping, $roundingMode); | ||
38 | |||
39 | if (null === $divisor) { | ||
40 | $divisor = 1; | ||
41 | } | ||
42 | |||
43 | $this->divisor = $divisor; | ||
44 | } | ||
45 | |||
46 | /** | ||
47 | * Transforms a normalized format into a localized money string. | ||
48 | * | ||
49 | * @param number $value Normalized number | ||
50 | * | ||
51 | * @return string Localized money string. | ||
52 | * | ||
53 | * @throws TransformationFailedException If the given value is not numeric or | ||
54 | * if the value can not be transformed. | ||
55 | */ | ||
56 | public function transform($value) | ||
57 | { | ||
58 | if (null !== $value) { | ||
59 | if (!is_numeric($value)) { | ||
60 | throw new TransformationFailedException('Expected a numeric.'); | ||
61 | } | ||
62 | |||
63 | $value /= $this->divisor; | ||
64 | } | ||
65 | |||
66 | return parent::transform($value); | ||
67 | } | ||
68 | |||
69 | /** | ||
70 | * Transforms a localized money string into a normalized format. | ||
71 | * | ||
72 | * @param string $value Localized money string | ||
73 | * | ||
74 | * @return number Normalized number | ||
75 | * | ||
76 | * @throws TransformationFailedException If the given value is not a string | ||
77 | * or if the value can not be transformed. | ||
78 | */ | ||
79 | public function reverseTransform($value) | ||
80 | { | ||
81 | $value = parent::reverseTransform($value); | ||
82 | |||
83 | if (null !== $value) { | ||
84 | $value *= $this->divisor; | ||
85 | } | ||
86 | |||
87 | return $value; | ||
88 | } | ||
89 | |||
90 | } | ||
diff --git a/vendor/symfony/form/Symfony/Component/Form/Extension/Core/DataTransformer/NumberToLocalizedStringTransformer.php b/vendor/symfony/form/Symfony/Component/Form/Extension/Core/DataTransformer/NumberToLocalizedStringTransformer.php deleted file mode 100644 index b0c59b3e..00000000 --- a/vendor/symfony/form/Symfony/Component/Form/Extension/Core/DataTransformer/NumberToLocalizedStringTransformer.php +++ /dev/null | |||
@@ -1,184 +0,0 @@ | |||
1 | <?php | ||
2 | |||
3 | /* | ||
4 | * This file is part of the Symfony package. | ||
5 | * | ||
6 | * (c) Fabien Potencier <fabien@symfony.com> | ||
7 | * | ||
8 | * For the full copyright and license information, please view the LICENSE | ||
9 | * file that was distributed with this source code. | ||
10 | */ | ||
11 | |||
12 | namespace Symfony\Component\Form\Extension\Core\DataTransformer; | ||
13 | |||
14 | use Symfony\Component\Form\DataTransformerInterface; | ||
15 | use Symfony\Component\Form\Exception\TransformationFailedException; | ||
16 | |||
17 | /** | ||
18 | * Transforms between a number type and a localized number with grouping | ||
19 | * (each thousand) and comma separators. | ||
20 | * | ||
21 | * @author Bernhard Schussek <bschussek@gmail.com> | ||
22 | * @author Florian Eckerstorfer <florian@eckerstorfer.org> | ||
23 | */ | ||
24 | class NumberToLocalizedStringTransformer implements DataTransformerInterface | ||
25 | { | ||
26 | const ROUND_FLOOR = \NumberFormatter::ROUND_FLOOR; | ||
27 | const ROUND_DOWN = \NumberFormatter::ROUND_DOWN; | ||
28 | const ROUND_HALFDOWN = \NumberFormatter::ROUND_HALFDOWN; | ||
29 | const ROUND_HALFEVEN = \NumberFormatter::ROUND_HALFEVEN; | ||
30 | const ROUND_HALFUP = \NumberFormatter::ROUND_HALFUP; | ||
31 | const ROUND_UP = \NumberFormatter::ROUND_UP; | ||
32 | const ROUND_CEILING = \NumberFormatter::ROUND_CEILING; | ||
33 | |||
34 | protected $precision; | ||
35 | |||
36 | protected $grouping; | ||
37 | |||
38 | protected $roundingMode; | ||
39 | |||
40 | public function __construct($precision = null, $grouping = null, $roundingMode = null) | ||
41 | { | ||
42 | if (null === $grouping) { | ||
43 | $grouping = false; | ||
44 | } | ||
45 | |||
46 | if (null === $roundingMode) { | ||
47 | $roundingMode = self::ROUND_HALFUP; | ||
48 | } | ||
49 | |||
50 | $this->precision = $precision; | ||
51 | $this->grouping = $grouping; | ||
52 | $this->roundingMode = $roundingMode; | ||
53 | } | ||
54 | |||
55 | /** | ||
56 | * Transforms a number type into localized number. | ||
57 | * | ||
58 | * @param integer|float $value Number value. | ||
59 | * | ||
60 | * @return string Localized value. | ||
61 | * | ||
62 | * @throws TransformationFailedException If the given value is not numeric | ||
63 | * or if the value can not be transformed. | ||
64 | */ | ||
65 | public function transform($value) | ||
66 | { | ||
67 | if (null === $value) { | ||
68 | return ''; | ||
69 | } | ||
70 | |||
71 | if (!is_numeric($value)) { | ||
72 | throw new TransformationFailedException('Expected a numeric.'); | ||
73 | } | ||
74 | |||
75 | $formatter = $this->getNumberFormatter(); | ||
76 | $value = $formatter->format($value); | ||
77 | |||
78 | if (intl_is_failure($formatter->getErrorCode())) { | ||
79 | throw new TransformationFailedException($formatter->getErrorMessage()); | ||
80 | } | ||
81 | |||
82 | // Convert fixed spaces to normal ones | ||
83 | $value = str_replace("\xc2\xa0", ' ', $value); | ||
84 | |||
85 | return $value; | ||
86 | } | ||
87 | |||
88 | /** | ||
89 | * Transforms a localized number into an integer or float | ||
90 | * | ||
91 | * @param string $value The localized value | ||
92 | * | ||
93 | * @return integer|float The numeric value | ||
94 | * | ||
95 | * @throws TransformationFailedException If the given value is not a string | ||
96 | * or if the value can not be transformed. | ||
97 | */ | ||
98 | public function reverseTransform($value) | ||
99 | { | ||
100 | if (!is_string($value)) { | ||
101 | throw new TransformationFailedException('Expected a string.'); | ||
102 | } | ||
103 | |||
104 | if ('' === $value) { | ||
105 | return null; | ||
106 | } | ||
107 | |||
108 | if ('NaN' === $value) { | ||
109 | throw new TransformationFailedException('"NaN" is not a valid number'); | ||
110 | } | ||
111 | |||
112 | $position = 0; | ||
113 | $formatter = $this->getNumberFormatter(); | ||
114 | $groupSep = $formatter->getSymbol(\NumberFormatter::GROUPING_SEPARATOR_SYMBOL); | ||
115 | $decSep = $formatter->getSymbol(\NumberFormatter::DECIMAL_SEPARATOR_SYMBOL); | ||
116 | |||
117 | if ('.' !== $decSep && (!$this->grouping || '.' !== $groupSep)) { | ||
118 | $value = str_replace('.', $decSep, $value); | ||
119 | } | ||
120 | |||
121 | if (',' !== $decSep && (!$this->grouping || ',' !== $groupSep)) { | ||
122 | $value = str_replace(',', $decSep, $value); | ||
123 | } | ||
124 | |||
125 | $result = $formatter->parse($value, \NumberFormatter::TYPE_DOUBLE, $position); | ||
126 | |||
127 | if (intl_is_failure($formatter->getErrorCode())) { | ||
128 | throw new TransformationFailedException($formatter->getErrorMessage()); | ||
129 | } | ||
130 | |||
131 | if ($result >= PHP_INT_MAX || $result <= -PHP_INT_MAX) { | ||
132 | throw new TransformationFailedException('I don\'t have a clear idea what infinity looks like'); | ||
133 | } | ||
134 | |||
135 | if (function_exists('mb_detect_encoding') && false !== $encoding = mb_detect_encoding($value)) { | ||
136 | $strlen = function ($string) use ($encoding) { | ||
137 | return mb_strlen($string, $encoding); | ||
138 | }; | ||
139 | $substr = function ($string, $offset, $length) use ($encoding) { | ||
140 | return mb_substr($string, $offset, $length, $encoding); | ||
141 | }; | ||
142 | } else { | ||
143 | $strlen = 'strlen'; | ||
144 | $substr = 'substr'; | ||
145 | } | ||
146 | |||
147 | $length = $strlen($value); | ||
148 | |||
149 | // After parsing, position holds the index of the character where the | ||
150 | // parsing stopped | ||
151 | if ($position < $length) { | ||
152 | // Check if there are unrecognized characters at the end of the | ||
153 | // number (excluding whitespace characters) | ||
154 | $remainder = trim($substr($value, $position, $length), " \t\n\r\0\x0b\xc2\xa0"); | ||
155 | |||
156 | if ('' !== $remainder) { | ||
157 | throw new TransformationFailedException( | ||
158 | sprintf('The number contains unrecognized characters: "%s"', $remainder) | ||
159 | ); | ||
160 | } | ||
161 | } | ||
162 | |||
163 | return $result; | ||
164 | } | ||
165 | |||
166 | /** | ||
167 | * Returns a preconfigured \NumberFormatter instance | ||
168 | * | ||
169 | * @return \NumberFormatter | ||
170 | */ | ||
171 | protected function getNumberFormatter() | ||
172 | { | ||
173 | $formatter = new \NumberFormatter(\Locale::getDefault(), \NumberFormatter::DECIMAL); | ||
174 | |||
175 | if (null !== $this->precision) { | ||
176 | $formatter->setAttribute(\NumberFormatter::FRACTION_DIGITS, $this->precision); | ||
177 | $formatter->setAttribute(\NumberFormatter::ROUNDING_MODE, $this->roundingMode); | ||
178 | } | ||
179 | |||
180 | $formatter->setAttribute(\NumberFormatter::GROUPING_USED, $this->grouping); | ||
181 | |||
182 | return $formatter; | ||
183 | } | ||
184 | } | ||
diff --git a/vendor/symfony/form/Symfony/Component/Form/Extension/Core/DataTransformer/PercentToLocalizedStringTransformer.php b/vendor/symfony/form/Symfony/Component/Form/Extension/Core/DataTransformer/PercentToLocalizedStringTransformer.php deleted file mode 100644 index e099d436..00000000 --- a/vendor/symfony/form/Symfony/Component/Form/Extension/Core/DataTransformer/PercentToLocalizedStringTransformer.php +++ /dev/null | |||
@@ -1,149 +0,0 @@ | |||
1 | <?php | ||
2 | |||
3 | /* | ||
4 | * This file is part of the Symfony package. | ||
5 | * | ||
6 | * (c) Fabien Potencier <fabien@symfony.com> | ||
7 | * | ||
8 | * For the full copyright and license information, please view the LICENSE | ||
9 | * file that was distributed with this source code. | ||
10 | */ | ||
11 | |||
12 | namespace Symfony\Component\Form\Extension\Core\DataTransformer; | ||
13 | |||
14 | use Symfony\Component\Form\DataTransformerInterface; | ||
15 | use Symfony\Component\Form\Exception\TransformationFailedException; | ||
16 | use Symfony\Component\Form\Exception\UnexpectedTypeException; | ||
17 | |||
18 | /** | ||
19 | * Transforms between a normalized format (integer or float) and a percentage value. | ||
20 | * | ||
21 | * @author Bernhard Schussek <bschussek@gmail.com> | ||
22 | * @author Florian Eckerstorfer <florian@eckerstorfer.org> | ||
23 | */ | ||
24 | class PercentToLocalizedStringTransformer implements DataTransformerInterface | ||
25 | { | ||
26 | const FRACTIONAL = 'fractional'; | ||
27 | const INTEGER = 'integer'; | ||
28 | |||
29 | protected static $types = array( | ||
30 | self::FRACTIONAL, | ||
31 | self::INTEGER, | ||
32 | ); | ||
33 | |||
34 | private $type; | ||
35 | |||
36 | private $precision; | ||
37 | |||
38 | /** | ||
39 | * Constructor. | ||
40 | * | ||
41 | * @see self::$types for a list of supported types | ||
42 | * | ||
43 | * @param integer $precision The precision | ||
44 | * @param string $type One of the supported types | ||
45 | * | ||
46 | * @throws UnexpectedTypeException if the given value of type is unknown | ||
47 | */ | ||
48 | public function __construct($precision = null, $type = null) | ||
49 | { | ||
50 | if (null === $precision) { | ||
51 | $precision = 0; | ||
52 | } | ||
53 | |||
54 | if (null === $type) { | ||
55 | $type = self::FRACTIONAL; | ||
56 | } | ||
57 | |||
58 | if (!in_array($type, self::$types, true)) { | ||
59 | throw new UnexpectedTypeException($type, implode('", "', self::$types)); | ||
60 | } | ||
61 | |||
62 | $this->type = $type; | ||
63 | $this->precision = $precision; | ||
64 | } | ||
65 | |||
66 | /** | ||
67 | * Transforms between a normalized format (integer or float) into a percentage value. | ||
68 | * | ||
69 | * @param number $value Normalized value | ||
70 | * | ||
71 | * @return number Percentage value | ||
72 | * | ||
73 | * @throws TransformationFailedException If the given value is not numeric or | ||
74 | * if the value could not be transformed. | ||
75 | */ | ||
76 | public function transform($value) | ||
77 | { | ||
78 | if (null === $value) { | ||
79 | return ''; | ||
80 | } | ||
81 | |||
82 | if (!is_numeric($value)) { | ||
83 | throw new TransformationFailedException('Expected a numeric.'); | ||
84 | } | ||
85 | |||
86 | if (self::FRACTIONAL == $this->type) { | ||
87 | $value *= 100; | ||
88 | } | ||
89 | |||
90 | $formatter = $this->getNumberFormatter(); | ||
91 | $value = $formatter->format($value); | ||
92 | |||
93 | if (intl_is_failure($formatter->getErrorCode())) { | ||
94 | throw new TransformationFailedException($formatter->getErrorMessage()); | ||
95 | } | ||
96 | |||
97 | // replace the UTF-8 non break spaces | ||
98 | return $value; | ||
99 | } | ||
100 | |||
101 | /** | ||
102 | * Transforms between a percentage value into a normalized format (integer or float). | ||
103 | * | ||
104 | * @param number $value Percentage value. | ||
105 | * | ||
106 | * @return number Normalized value. | ||
107 | * | ||
108 | * @throws TransformationFailedException If the given value is not a string or | ||
109 | * if the value could not be transformed. | ||
110 | */ | ||
111 | public function reverseTransform($value) | ||
112 | { | ||
113 | if (!is_string($value)) { | ||
114 | throw new TransformationFailedException('Expected a string.'); | ||
115 | } | ||
116 | |||
117 | if ('' === $value) { | ||
118 | return null; | ||
119 | } | ||
120 | |||
121 | $formatter = $this->getNumberFormatter(); | ||
122 | // replace normal spaces so that the formatter can read them | ||
123 | $value = $formatter->parse(str_replace(' ', ' ', $value)); | ||
124 | |||
125 | if (intl_is_failure($formatter->getErrorCode())) { | ||
126 | throw new TransformationFailedException($formatter->getErrorMessage()); | ||
127 | } | ||
128 | |||
129 | if (self::FRACTIONAL == $this->type) { | ||
130 | $value /= 100; | ||
131 | } | ||
132 | |||
133 | return $value; | ||
134 | } | ||
135 | |||
136 | /** | ||
137 | * Returns a preconfigured \NumberFormatter instance | ||
138 | * | ||
139 | * @return \NumberFormatter | ||
140 | */ | ||
141 | protected function getNumberFormatter() | ||
142 | { | ||
143 | $formatter = new \NumberFormatter(\Locale::getDefault(), \NumberFormatter::DECIMAL); | ||
144 | |||
145 | $formatter->setAttribute(\NumberFormatter::FRACTION_DIGITS, $this->precision); | ||
146 | |||
147 | return $formatter; | ||
148 | } | ||
149 | } | ||
diff --git a/vendor/symfony/form/Symfony/Component/Form/Extension/Core/DataTransformer/ValueToDuplicatesTransformer.php b/vendor/symfony/form/Symfony/Component/Form/Extension/Core/DataTransformer/ValueToDuplicatesTransformer.php deleted file mode 100644 index c34a0139..00000000 --- a/vendor/symfony/form/Symfony/Component/Form/Extension/Core/DataTransformer/ValueToDuplicatesTransformer.php +++ /dev/null | |||
@@ -1,91 +0,0 @@ | |||
1 | <?php | ||
2 | |||
3 | /* | ||
4 | * This file is part of the Symfony package. | ||
5 | * | ||
6 | * (c) Fabien Potencier <fabien@symfony.com> | ||
7 | * | ||
8 | * For the full copyright and license information, please view the LICENSE | ||
9 | * file that was distributed with this source code. | ||
10 | */ | ||
11 | |||
12 | namespace Symfony\Component\Form\Extension\Core\DataTransformer; | ||
13 | |||
14 | use Symfony\Component\Form\DataTransformerInterface; | ||
15 | use Symfony\Component\Form\Exception\TransformationFailedException; | ||
16 | |||
17 | /** | ||
18 | * @author Bernhard Schussek <bschussek@gmail.com> | ||
19 | */ | ||
20 | class ValueToDuplicatesTransformer implements DataTransformerInterface | ||
21 | { | ||
22 | private $keys; | ||
23 | |||
24 | public function __construct(array $keys) | ||
25 | { | ||
26 | $this->keys = $keys; | ||
27 | } | ||
28 | |||
29 | /** | ||
30 | * Duplicates the given value through the array. | ||
31 | * | ||
32 | * @param mixed $value The value | ||
33 | * | ||
34 | * @return array The array | ||
35 | */ | ||
36 | public function transform($value) | ||
37 | { | ||
38 | $result = array(); | ||
39 | |||
40 | foreach ($this->keys as $key) { | ||
41 | $result[$key] = $value; | ||
42 | } | ||
43 | |||
44 | return $result; | ||
45 | } | ||
46 | |||
47 | /** | ||
48 | * Extracts the duplicated value from an array. | ||
49 | * | ||
50 | * @param array $array | ||
51 | * | ||
52 | * @return mixed The value | ||
53 | * | ||
54 | * @throws TransformationFailedException If the given value is not an array or | ||
55 | * if the given array can not be transformed. | ||
56 | */ | ||
57 | public function reverseTransform($array) | ||
58 | { | ||
59 | if (!is_array($array)) { | ||
60 | throw new TransformationFailedException('Expected an array.'); | ||
61 | } | ||
62 | |||
63 | $result = current($array); | ||
64 | $emptyKeys = array(); | ||
65 | |||
66 | foreach ($this->keys as $key) { | ||
67 | if (!empty($array[$key])) { | ||
68 | if ($array[$key] !== $result) { | ||
69 | throw new TransformationFailedException( | ||
70 | 'All values in the array should be the same' | ||
71 | ); | ||
72 | } | ||
73 | } else { | ||
74 | $emptyKeys[] = $key; | ||
75 | } | ||
76 | } | ||
77 | |||
78 | if (count($emptyKeys) > 0) { | ||
79 | if (count($emptyKeys) == count($this->keys)) { | ||
80 | // All keys empty | ||
81 | return null; | ||
82 | } | ||
83 | |||
84 | throw new TransformationFailedException( | ||
85 | sprintf('The keys "%s" should not be empty', implode('", "', $emptyKeys) | ||
86 | )); | ||
87 | } | ||
88 | |||
89 | return $result; | ||
90 | } | ||
91 | } | ||