/** * Test convert float values from localized values to internal */ public function testConvertFloatFromLocalizedValues() { $this->setCustomLocale('ru_RU'); $this->assertEquals(0.9, LocaleUtility::convertFromLocalizedValue('0,9', 'float')); $this->assertEquals(1, LocaleUtility::convertFromLocalizedValue(1, 'float')); $this->setCustomLocale('en_US'); $this->assertEquals(0.9, LocaleUtility::convertFromLocalizedValue(0.9, 'float')); $this->assertEquals(1, LocaleUtility::convertFromLocalizedValue(1, 'float')); $this->setCustomLocale('fr_FR'); $this->assertEquals(0.9, LocaleUtility::convertFromLocalizedValue('0,9', 'float')); $this->assertEquals(1, LocaleUtility::convertFromLocalizedValue(1, 'float')); }
/** * Validate the date end * * @param $value * @param array $context * @return boolean */ public function validateDateEnd($value, array $context = []) { // compare the date start and date end if (!empty($context['date_start'])) { return LocalizationLocaleUtility::convertFromLocalizedValue($value, 'date_unixtime') > LocalizationLocaleUtility::convertFromLocalizedValue($context['date_start'], 'date_unixtime'); } return true; }
/** * Validate xml map priority * * @param $value * @param array $context * @return boolean */ public function validateXmlMapPriority($value, array $context = []) { $value = (double) LocalizationUtility::convertFromLocalizedValue($value, 'float'); return $value >= 0 && $value <= 1; }
/** * Retrieve the validated data * * By default, retrieves normalized values; pass one of the * FormInterface::VALUES_* constants to shape the behavior. * * @param boolean $localizeData * @param int $flag * @throws Exception\DomainException * @return array|object */ public function getData($localizeData = true, $flag = FormInterface::VALUES_NORMALIZED) { $formData = parent::getData($flag); // process form data $processedData = []; foreach ($formData as $fieldName => $fieldValue) { // skip all ignored elements if (in_array($fieldName, $this->ignoredElements)) { continue; } // convert from localized data $processedData[$fieldName] = $localizeData ? LocaleUtility::convertFromLocalizedValue($fieldValue, $this->customElements[$fieldName]) : $fieldValue; } return $processedData; }