diff --git a/src/php7/php_solr_collapse_function.c b/src/php7/php_solr_collapse_function.c index a350024f..efbf38e9 100644 --- a/src/php7/php_solr_collapse_function.c +++ b/src/php7/php_solr_collapse_function.c @@ -178,11 +178,23 @@ PHP_METHOD(SolrCollapseFunction, setSize) { solr_char_t *key = "size", *arg; COMPAT_ARG_SIZE_T key_len = sizeof("size"), arg_len; + zval *tmp; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &arg, &arg_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &tmp) == FAILURE) { RETURN_NULL(); } + if (Z_TYPE_P(tmp) == IS_LONG) { + convert_to_string(tmp); + } + + if (Z_TYPE_P(tmp) != IS_STRING) { + solr_throw_exception(solr_ce_SolrIllegalArgumentException, "Argument 1 must be an int", SOLR_ERROR_4000, SOLR_FILE_LINE_FUNC); + } + + arg = Z_STRVAL_P(tmp); + arg_len = Z_STRLEN_P(tmp); + if (solr_solrfunc_update_string(getThis(), key, key_len, (solr_char_t *)arg, arg_len) == FAILURE) { php_error_docref(NULL, E_ERROR, "Error assigning field"); RETURN_NULL(); diff --git a/src/php7/php_solr_dismax_query.c b/src/php7/php_solr_dismax_query.c index 047d3dc7..071b95e8 100644 --- a/src/php7/php_solr_dismax_query.c +++ b/src/php7/php_solr_dismax_query.c @@ -429,12 +429,25 @@ PHP_METHOD(SolrDisMaxQuery, setPhraseSlop) int add_result = -1; solr_char_t *pvalue = NULL; COMPAT_ARG_SIZE_T pvalue_len = 0; + zval *tmp; - if(zend_parse_parameters(ZEND_NUM_ARGS(), "s", &pvalue, &pvalue_len) == FAILURE) + if(zend_parse_parameters(ZEND_NUM_ARGS(), "z", &tmp) == FAILURE) { php_error_docref(NULL, E_WARNING, "Invalid parameters"); RETURN_NULL(); } + + if (Z_TYPE_P(tmp) == IS_LONG) { + convert_to_string(tmp); + } + + if (Z_TYPE_P(tmp) != IS_STRING) { + solr_throw_exception(solr_ce_SolrIllegalArgumentException, "Argument 1 must be an int", SOLR_ERROR_4000, SOLR_FILE_LINE_FUNC); + } + + pvalue = Z_STRVAL_P(tmp); + pvalue_len = Z_STRLEN_P(tmp); + add_result = solr_add_or_set_normal_param(getThis(), pname, pname_len, pvalue, pvalue_len, 0); if(add_result == FAILURE) @@ -455,12 +468,25 @@ PHP_METHOD(SolrDisMaxQuery, setQueryPhraseSlop) int add_result = -1; solr_char_t *pvalue = NULL; COMPAT_ARG_SIZE_T pvalue_len = 0; + zval *tmp; - if(zend_parse_parameters(ZEND_NUM_ARGS(), "s", &pvalue, &pvalue_len) == FAILURE) + if(zend_parse_parameters(ZEND_NUM_ARGS(), "z", &tmp) == FAILURE) { php_error_docref(NULL, E_WARNING, "Invalid parameters"); RETURN_NULL(); } + + if (Z_TYPE_P(tmp) == IS_LONG) { + convert_to_string(tmp); + } + + if (Z_TYPE_P(tmp) != IS_STRING) { + solr_throw_exception(solr_ce_SolrIllegalArgumentException, "Argument 1 must be an int", SOLR_ERROR_4000, SOLR_FILE_LINE_FUNC); + } + + pvalue = Z_STRVAL_P(tmp); + pvalue_len = Z_STRLEN_P(tmp); + add_result = solr_add_or_set_normal_param(getThis(), pname, pname_len, pvalue, pvalue_len, 0); if(add_result == FAILURE) @@ -774,12 +800,25 @@ PHP_METHOD(SolrDisMaxQuery, setBigramPhraseSlop) int add_result = -1; solr_char_t *pvalue = NULL; COMPAT_ARG_SIZE_T pvalue_len = 0; + zval *tmp; - if(zend_parse_parameters(ZEND_NUM_ARGS(), "s", &pvalue, &pvalue_len) == FAILURE) + if(zend_parse_parameters(ZEND_NUM_ARGS(), "z", &tmp) == FAILURE) { php_error_docref(NULL, E_WARNING, "Invalid parameters"); RETURN_NULL(); } + + if (Z_TYPE_P(tmp) == IS_LONG) { + convert_to_string(tmp); + } + + if (Z_TYPE_P(tmp) != IS_STRING) { + solr_throw_exception(solr_ce_SolrIllegalArgumentException, "Argument 1 must be an int", SOLR_ERROR_4000, SOLR_FILE_LINE_FUNC); + } + + pvalue = Z_STRVAL_P(tmp); + pvalue_len = Z_STRLEN_P(tmp); + add_result = solr_add_or_set_normal_param(getThis(), pname, pname_len, pvalue, pvalue_len, 0); if(add_result == FAILURE) @@ -883,12 +922,25 @@ PHP_METHOD(SolrDisMaxQuery, setTrigramPhraseSlop) int add_result = -1; solr_char_t *pvalue = NULL; COMPAT_ARG_SIZE_T pvalue_len = 0; + zval *tmp; - if(zend_parse_parameters(ZEND_NUM_ARGS(), "s", &pvalue, &pvalue_len) == FAILURE) + if(zend_parse_parameters(ZEND_NUM_ARGS(), "z", &tmp) == FAILURE) { php_error_docref(NULL, E_WARNING, "Invalid parameters"); RETURN_NULL(); } + + if (Z_TYPE_P(tmp) == IS_LONG) { + convert_to_string(tmp); + } + + if (Z_TYPE_P(tmp) != IS_STRING) { + solr_throw_exception(solr_ce_SolrIllegalArgumentException, "Argument 1 must be an int", SOLR_ERROR_4000, SOLR_FILE_LINE_FUNC); + } + + pvalue = Z_STRVAL_P(tmp); + pvalue_len = Z_STRLEN_P(tmp); + add_result = solr_add_or_set_normal_param(getThis(), pname, pname_len, pvalue, pvalue_len, 0); if(add_result == FAILURE) diff --git a/tests/203.solrquery_strict_types.phpt b/tests/203.solrquery_strict_types.phpt index e438612e..a72fc16b 100644 --- a/tests/203.solrquery_strict_types.phpt +++ b/tests/203.solrquery_strict_types.phpt @@ -23,9 +23,25 @@ $query->setExpandRows('1'); echo $query . "\n"; -try { $query->setStart(true); } catch (SolrIllegalArgumentException $e) { echo $e->getMessage(); } +try { $query->setStart(true); } catch (SolrIllegalArgumentException $e) { echo $e->getMessage() . "\n"; } + +$collapse = new SolrCollapseFunction(); +$collapse->setSize(1); + +echo $collapse . "\n"; + +$d = new SolrDisMaxQuery('lucene'); +$d->setPhraseSlop(2); +$d->setQueryPhraseSlop(3); +$d->setBigramPhraseSlop(4); +$d->setTrigramPhraseSlop(5); + +echo $d . "\n"; + --EXPECT-- q=lucene&start=1&rows=2&timeAllowed=300&group.offset=1&expand.rows=1 q=lucene&start=1anystring&rows=2&timeAllowed=300&group.offset=1&expand.rows=1 Argument 1 must be an int +{!collapse size=1} +q=lucene&defType=edismax&ps=2&qs=3&ps2=4&ps3=5