in src/Apache/Ignite/Internal/Binary/BinaryUtils.php [75:192]
public static function checkStandardTypeCompatibility($value, $typeCode, $type = null, $signed = true)
{
$valueType = BinaryUtils::getPhpTypeName($value);
switch ($typeCode) {
case ObjectType::BYTE:
case ObjectType::SHORT:
case ObjectType::INTEGER:
if (!is_integer($value)) {
BinaryUtils::valueCastError($value, $typeCode);
}
$typeInfo = TypeInfo::getTypeInfo($typeCode);
$min = $typeInfo->getMinValue();
$max = $typeInfo->getMaxValue();
if ($signed && ($min && $value < $min || $max && $value > $max) ||
!$signed && ($value < 0 || $value > $max - $min)) {
BinaryUtils::valueCastError($value, $typeCode);
}
return;
case ObjectType::LONG:
case ObjectType::FLOAT:
case ObjectType::DOUBLE:
if (!is_integer($value) && !is_float($value)) {
BinaryUtils::valueCastError($value, $typeCode);
}
return;
case ObjectType::CHAR:
if (!is_string($value) || mb_strlen($value) !== 1) {
BinaryUtils::valueCastError($value, $typeCode);
}
return;
case ObjectType::BOOLEAN:
if (!is_bool($value)) {
BinaryUtils::valueCastError($value, $typeCode);
}
return;
case ObjectType::STRING:
if (!is_string($value)) {
BinaryUtils::valueCastError($value, $typeCode);
}
return;
case ObjectType::UUID:
if (!BinaryUtils::isIndexedArray($value) ||
count($value) !== BinaryUtils::getSize(ObjectType::UUID)) {
BinaryUtils::valueCastError($value, $typeCode);
}
foreach ($value as $element) {
BinaryUtils::checkStandardTypeCompatibility($element, ObjectType::BYTE, null, false);
}
return;
case ObjectType::DATE:
if (!($value instanceof Date)) {
BinaryUtils::valueCastError($value, $typeCode);
}
return;
case ObjectType::ENUM:
if (!($value instanceof EnumItem)) {
BinaryUtils::valueCastError($value, $typeCode);
}
return;
case ObjectType::DECIMAL:
if (!($value instanceof BigDecimal)) {
BinaryUtils::valueCastError($value, $typeCode);
}
return;
case ObjectType::TIMESTAMP:
if (!($value instanceof Timestamp)) {
BinaryUtils::valueCastError($value, $typeCode);
}
return;
case ObjectType::TIME:
if (!($value instanceof Time)) {
BinaryUtils::valueCastError($value, $typeCode);
}
return;
case ObjectType::BYTE_ARRAY:
case ObjectType::SHORT_ARRAY:
case ObjectType::INTEGER_ARRAY:
case ObjectType::LONG_ARRAY:
case ObjectType::FLOAT_ARRAY:
case ObjectType::DOUBLE_ARRAY:
case ObjectType::CHAR_ARRAY:
case ObjectType::BOOLEAN_ARRAY:
case ObjectType::STRING_ARRAY:
case ObjectType::UUID_ARRAY:
case ObjectType::DATE_ARRAY:
case ObjectType::OBJECT_ARRAY:
case ObjectType::ENUM_ARRAY:
case ObjectType::DECIMAL_ARRAY:
case ObjectType::TIMESTAMP_ARRAY:
case ObjectType::TIME_ARRAY:
if (!BinaryUtils::isIndexedArray($value)) {
BinaryUtils::typeCastError($valueType, $typeCode);
}
return;
case ObjectType::MAP:
if (!($value instanceof Map) && !is_array($value)) {
BinaryUtils::typeCastError($valueType, $typeCode);
}
return;
case ObjectType::COLLECTION:
$isSet = $type && CollectionObjectType::isSet($type->getSubType());
if (!($isSet && $value instanceof Set || BinaryUtils::isIndexedArray($value))) {
BinaryUtils::typeCastError($valueType, $isSet ? 'set' : $typeCode);
}
return;
case ObjectType::NULL:
if ($value !== null) {
BinaryUtils::typeCastError('not null', $typeCode);
}
return;
default:
$valueTypeCode = BinaryUtils::getTypeCode(BinaryUtils::calcObjectType($value));
if ($valueTypeCode === ObjectType::BINARY_OBJECT) {
BinaryUtils::typeCastError($valueTypeCode, $typeCode);
}
return;
}
}