protected static function convertToType ($rawValue, $typeStr) {
		$conversionResult = FALSE;
		$typeStr = trim($typeStr, '\\');
		if ($typeStr == 'DateTime') {
			$dateTimeFormat = 'Y-m-d H:i:s';
			if (is_numeric($rawValue)) {
				$rawValueStr = str_replace(['+','-','.'], '', strval($rawValue));
				$secData = mb_substr($rawValueStr, 0, 10);
				$dateTimeStr = date($dateTimeFormat, intval($secData));
				if (strlen($rawValueStr) > 10) 
					$dateTimeStr .= '.' . mb_substr($rawValueStr, 10);
			} else {
				$dateTimeStr = strval($rawValue);
				if (strpos($dateTimeStr, '-') === FALSE) {
					$dateTimeFormat = substr($dateTimeFormat, 6);
				} else if (strpos($dateTimeStr, ':') === FALSE) {
					$dateTimeFormat = substr($dateTimeFormat, 0, 5);
				}
				if (strpos($dateTimeStr, '.') !== FALSE) $dateTimeFormat .= '.u';
			}
			$dateTime = date_create_from_format($dateTimeFormat, $dateTimeStr);
			if ($dateTime !== FALSE) {
				$rawValue = $dateTime;
				$conversionResult = TRUE;
			}
		} else {
			if (settype($rawValue, $typeStr)) $conversionResult = TRUE;
		}
		return [$conversionResult, $rawValue];
	}
protected static function convertToType ($rawValue, $typeStr) {
		$conversionResult = FALSE;
		$typeStr = trim($typeStr, '\\');
		if ($typeStr == 'DateTime') {
			$dateTimeFormat = 'Y-m-d H:i:s';
			if (is_numeric($rawValue)) {
				$rawValueStr = str_replace(['+','-','.'], '', strval($rawValue));
				$secData = mb_substr($rawValueStr, 0, 10);
				$dateTimeStr = date($dateTimeFormat, intval($secData));
				if (strlen($rawValueStr) > 10) 
					$dateTimeStr .= '.' . mb_substr($rawValueStr, 10);
			} else {
				$dateTimeStr = strval($rawValue);
				if (strpos($dateTimeStr, '-') === FALSE) {
					$dateTimeFormat = substr($dateTimeFormat, 6);
				} else if (strpos($dateTimeStr, ':') === FALSE) {
					$dateTimeFormat = substr($dateTimeFormat, 0, 5);
				}
				if (strpos($dateTimeStr, '.') !== FALSE) $dateTimeFormat .= '.u';
			}
			$dateTime = date_create_from_format($dateTimeFormat, $dateTimeStr);
			if ($dateTime !== FALSE) {
				$rawValue = $dateTime;
				$conversionResult = TRUE;
			}
		} else {
			if (settype($rawValue, $typeStr)) $conversionResult = TRUE;
		}
		return [$conversionResult, $rawValue];
	}
protected static function convertToType ( $ rawValue , $ typeStr ) { $ conversionResult = FALSE ; $ typeStr = trim ( $ typeStr , '\\' ) ; if ( $ typeStr == 'DateTime' ) { $ dateTimeFormat = 'Y-m-d H:i:s' ; if ( is_numeric ( $ rawValue ) ) { $ rawValueStr = str_replace ( [ '+' , '-' , '.' ] , '' , strval ( $ rawValue ) ) ; $ secData = mb_substr ( $ rawValueStr , 0 , 10 ) ; $ dateTimeStr = date ( $ dateTimeFormat , intval ( $ secData ) ) ; if ( strlen ( $ rawValueStr ) > 10 ) $ dateTimeStr .= '.' . mb_substr ( $ rawValueStr , 10 ) ; } else { $ dateTimeStr = strval ( $ rawValue ) ; if ( strpos ( $ dateTimeStr , '-' ) === FALSE ) { $ dateTimeFormat = substr ( $ dateTimeFormat , 6 ) ; } else if ( strpos ( $ dateTimeStr , ':' ) === FALSE ) { $ dateTimeFormat = substr ( $ dateTimeFormat , 0 , 5 ) ; } if ( strpos ( $ dateTimeStr , '.' ) !== FALSE ) $ dateTimeFormat .= '.u' ; } $ dateTime = date_create_from_format ( $ dateTimeFormat , $ dateTimeStr ) ; if ( $ dateTime !== FALSE ) { $ rawValue = $ dateTime ; $ conversionResult = TRUE ; } } else { if ( settype ( $ rawValue , $ typeStr ) ) $ conversionResult = TRUE ; } return [ $ conversionResult , $ rawValue ] ; }
Try to convert database value into target type.
@param mixed $rawValue
@param string $typeStr
@return array
Try to convert database value into target type .