Spaces:
No application file
No application file
File size: 2,182 Bytes
d2897cd |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
<?php
declare(strict_types=1);
namespace Mautic\IntegrationsBundle\Sync\ValueNormalizer;
use Mautic\IntegrationsBundle\Sync\DAO\Value\NormalizedValueDAO;
final class ValueNormalizer implements ValueNormalizerInterface
{
/**
* @param mixed $value
*/
public function normalizeForMautic(string $type, $value): NormalizedValueDAO
{
switch ($type) {
case NormalizedValueDAO::STRING_TYPE:
case NormalizedValueDAO::TEXT_TYPE:
case NormalizedValueDAO::TEXTAREA_TYPE:
case NormalizedValueDAO::URL_TYPE:
case NormalizedValueDAO::EMAIL_TYPE:
case NormalizedValueDAO::SELECT_TYPE:
case NormalizedValueDAO::MULTISELECT_TYPE:
case NormalizedValueDAO::REGION_TYPE:
case NormalizedValueDAO::LOOKUP_TYPE:
return new NormalizedValueDAO($type, $value, (string) $value);
case NormalizedValueDAO::INT_TYPE:
return new NormalizedValueDAO($type, $value, (int) $value);
case NormalizedValueDAO::FLOAT_TYPE:
case NormalizedValueDAO::DOUBLE_TYPE:
return new NormalizedValueDAO($type, $value, (float) $value);
case NormalizedValueDAO::DATE_TYPE:
case NormalizedValueDAO::DATETIME_TYPE:
// We expect a string value.
if (is_string($value)) {
return new NormalizedValueDAO($type, $value, new \DateTime($value));
}
// Other value types we normalize to null.
return new NormalizedValueDAO($type, $value, null);
case NormalizedValueDAO::BOOLEAN_TYPE:
$value = 'false' === $value ? false : $value;
$value = 'true' === $value ? true : $value;
return new NormalizedValueDAO($type, $value, (bool) $value);
default:
throw new \InvalidArgumentException('Variable type, '.$type.', not supported');
}
}
/**
* @return mixed
*/
public function normalizeForIntegration(NormalizedValueDAO $value)
{
return $value->getNormalizedValue();
}
}
|