/** * Checks query parameters types correspondence. * * @param array $params Parameters of the query. * @param string $types Types of the parameters ("idsb"). * * @throws DBCoreException */ private static function checkParameterTypes($params, $types) { if (count($params) == strlen($types)) { foreach ($params as $key => $value) { $type = $types[$key]; if (!in_array($type, array('i', 'd', 's', 'b'))) { throw new DBCoreException("Invalid query parameters types string (type '" . $type . "' is undefined, only 'i', 'd', 's' and 'b' types are acceptable)"); } $typeByValue = DBField::getType($value); if ($typeByValue != 's') { if ($type != $typeByValue && !($type == 'd' && $typeByValue == 'i' || $type == 's' && $typeByValue == 'i')) { throw new DBCoreException("Invalid query parameters types string ('" . $value . "' is not '" . $type . "' type but '" . $typeByValue . "' detected)"); } } else { // in case if we try send non-string parameters as a string value switch ($type) { case 'i': if (!(Tools::isNumeric($value) && (string) (int) $value === $value)) { throw new DBCoreException("Invalid query parameters types string ('" . $value . "' is not '" . $type . ")"); } break; case 'd': if (!Tools::isDoubleString($value)) { throw new DBCoreException("Invalid query parameters types string ('" . $value . "' is not '" . $type . ")"); } break; case 'b': if (!in_array(strtolower($value), array('true', 'false'))) { throw new DBCoreException("Invalid query parameters types string ('" . $value . "' is not '" . $type . ")"); } break; } } } } else { throw new DBCoreException("Number of types is not equal parameters number"); } }