public static function normalizeJson($value) { if (is_string($value) && mb_strlen($value) >= 2 && preg_match('%^(\\{.*\\}|\\[.*\\])$%s', $value)) { return $value; } else { return !is_string($value) && ValidateValue::isFloat($value) ? "{$value}" : json_encode($value, JSON_UNESCAPED_UNICODE); } }
/** * Converts $value to required date-time format * @param int|string $value - int: unix timestamp | string: valid date/time/date-time string * @param string $format - resulting value format * @param string|int|bool $now - current unix timestamp or any valid strtotime() string * @return string */ public static function formatDateTime($value, $format, $now = 'now') { if (is_string($value) && strtotime($value) != 0) { // convert string value to unix timestamp and then to required date format if (!is_string($now) && !is_int($now)) { $now = 'now'; } if (strtolower($now) === 'now' || empty($now)) { $value = strtotime($value); } else { if (is_numeric($now)) { $value = strtotime($value, $now); } else { $value = strtotime($value, strtotime($now)); } } } return ValidateValue::isInteger($value, false) ? date($format, $value) : null; }
/** * @param int $pngQuality * @return $this * @throws ImageVersionConfigException */ public function setPngQuality($pngQuality) { if (!ValidateValue::isInteger($pngQuality, true) || $pngQuality <= 0 || $pngQuality > 9) { throw new ImageVersionConfigException('PNG image quality should be within 1 and 9'); } $this->pngQuality = $pngQuality; return $this; }