protected function analyzeByValue($value) { $acceptableValues = BooleanSanitizerUtil::getAcceptableValues(); $acceptableValuesMapping = BooleanSanitizerUtil::getAcceptableValuesResolvingValues(); if (!in_array(strtolower($value), $acceptableValues)) { $this->messageCountData[static::INVALID]++; } }
/** * Given a value, attempt to convert the value to either true/false based on a mapping array of possible * boolean values. If the value is not present, attemp to utilize the default value specified. * If the value presented is not a valid mapping value then a * InvalidValueToSanitizeException will be thrown. * @param mixed $value * @return sanitized value * @throws InvalidValueToSanitizeException */ public function sanitizeValue($value) { $acceptableValues = BooleanSanitizerUtil::getAcceptableValues(); $acceptableValuesResolvingValues = BooleanSanitizerUtil::getAcceptableValuesResolvingValues(); if ($value == null) { if (isset($this->mappingRuleData['defaultValue']) && $this->mappingRuleData['defaultValue'] != null) { $key = array_search($this->mappingRuleData['defaultValue'], $acceptableValues); return $acceptableValuesResolvingValues[$this->mappingRuleData['defaultValue']]; } else { return null; } } if (!in_array(strtolower($value), $acceptableValues)) { throw new InvalidValueToSanitizeException(Zurmo::t('ImportModule', 'Invalid check box format.')); } else { $key = array_search(strtolower($value), $acceptableValues); return $acceptableValuesResolvingValues[$key]; } }
/** * Given a value, attempt to convert the value to either true/false based on a mapping array of possible * boolean values. If the value is not present, attemp to utilize the default value specified. * If the value presented is not a valid mapping value then a * InvalidValueToSanitizeException will be thrown. * @param string $modelClassName * @param string $attributeName * @param mixed $value * @param array $mappingRuleData */ public static function sanitizeValue($modelClassName, $attributeName, $value, $mappingRuleData) { assert('is_string($modelClassName)'); assert('is_string($attributeName)'); assert('$mappingRuleData["defaultValue"] == null || $mappingRuleData["defaultValue"] == "1" || $mappingRuleData["defaultValue"] == "0"'); $acceptableValues = BooleanSanitizerUtil::getAcceptableValues(); $acceptableValuesResolvingValues = BooleanSanitizerUtil::getAcceptableValuesResolvingValues(); if ($value == null) { if ($mappingRuleData['defaultValue'] != null) { $key = array_search($mappingRuleData['defaultValue'], $acceptableValues); return $acceptableValuesResolvingValues[$mappingRuleData['defaultValue']]; } else { return null; } } if (!in_array(strtolower($value), $acceptableValues)) { throw new InvalidValueToSanitizeException(Zurmo::t('ImportModule', 'Invalid check box format.')); } else { $key = array_search(strtolower($value), $acceptableValues); return $acceptableValuesResolvingValues[$key]; } }