PHP_METHOD(ExecutionOptions, __construct) { zval* options = NULL; cassandra_execution_options* self = NULL; zval** consistency = NULL; zval** serial_consistency = NULL; zval** page_size = NULL; zval** paging_state_token = NULL; zval** timeout = NULL; zval** arguments = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &options) == FAILURE) { return; } if (!options) return; if (Z_TYPE_P(options) != IS_ARRAY) { INVALID_ARGUMENT(options, "an array"); } self = (cassandra_execution_options*) zend_object_store_get_object(getThis() TSRMLS_CC); if (zend_hash_find(Z_ARRVAL_P(options), "consistency", sizeof("consistency"), (void**)&consistency) == SUCCESS) { if (php_cassandra_get_consistency(*consistency, &self->consistency TSRMLS_CC) == FAILURE) { return; } } if (zend_hash_find(Z_ARRVAL_P(options), "serial_consistency", sizeof("serial_consistency"), (void**)&serial_consistency) == SUCCESS) { if (php_cassandra_get_serial_consistency(*serial_consistency, &self->serial_consistency TSRMLS_CC) == FAILURE) { return; } } if (zend_hash_find(Z_ARRVAL_P(options), "page_size", sizeof("page_size"), (void**)&page_size) == SUCCESS) { if (Z_TYPE_P(*page_size) != IS_LONG || Z_LVAL_P(*page_size) <= 0) { INVALID_ARGUMENT(*page_size, "greater than zero"); } self->page_size = Z_LVAL_P(*page_size); } if (zend_hash_find(Z_ARRVAL_P(options), "paging_state_token", sizeof("paging_state_token"), (void**)&paging_state_token) == SUCCESS) { if (Z_TYPE_P(*paging_state_token) != IS_STRING) { INVALID_ARGUMENT(*paging_state_token, "a string"); } self->paging_state_token = estrndup(Z_STRVAL_P(*paging_state_token), Z_STRLEN_P(*paging_state_token)); self->paging_state_token_size = Z_STRLEN_P(*paging_state_token); } if (zend_hash_find(Z_ARRVAL_P(options), "timeout", sizeof("timeout"), (void**)&timeout) == SUCCESS) { if (!(Z_TYPE_P(*timeout) == IS_LONG && Z_LVAL_P(*timeout) > 0) && !(Z_TYPE_P(*timeout) == IS_DOUBLE && Z_DVAL_P(*timeout) > 0) && !(Z_TYPE_P(*timeout) == IS_NULL)) { INVALID_ARGUMENT(*timeout, "a number of seconds greater than zero or null"); } self->timeout = *timeout; Z_ADDREF_P(self->timeout); } if (zend_hash_find(Z_ARRVAL_P(options), "arguments", sizeof("arguments"), (void**)&arguments) == SUCCESS) { if (Z_TYPE_P(*arguments) != IS_ARRAY) { INVALID_ARGUMENT(*arguments, "an array"); return; } self->arguments = *arguments; Z_ADDREF_P(self->arguments); } }
PHP_METHOD(ExecutionOptions, __construct) { zval *options = NULL; cassandra_execution_options *self = NULL; php5to7_zval *consistency = NULL; php5to7_zval *serial_consistency = NULL; php5to7_zval *page_size = NULL; php5to7_zval *paging_state_token = NULL; php5to7_zval *timeout = NULL; php5to7_zval *arguments = NULL; php5to7_zval *retry_policy = NULL; php5to7_zval *timestamp = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &options) == FAILURE) { return; } if (!options) return; if (Z_TYPE_P(options) != IS_ARRAY) { INVALID_ARGUMENT(options, "an array"); } self = PHP_CASSANDRA_GET_EXECUTION_OPTIONS(getThis()); if (PHP5TO7_ZEND_HASH_FIND(Z_ARRVAL_P(options), "consistency", sizeof("consistency"), consistency)) { if (php_cassandra_get_consistency(PHP5TO7_ZVAL_MAYBE_DEREF(consistency), &self->consistency TSRMLS_CC) == FAILURE) { return; } } if (PHP5TO7_ZEND_HASH_FIND(Z_ARRVAL_P(options), "serial_consistency", sizeof("serial_consistency"), serial_consistency)) { if (php_cassandra_get_serial_consistency(PHP5TO7_ZVAL_MAYBE_DEREF(serial_consistency), &self->serial_consistency TSRMLS_CC) == FAILURE) { return; } } if (PHP5TO7_ZEND_HASH_FIND(Z_ARRVAL_P(options), "page_size", sizeof("page_size"), page_size)) { if (Z_TYPE_P(PHP5TO7_ZVAL_MAYBE_DEREF(page_size)) != IS_LONG || Z_LVAL_P(PHP5TO7_ZVAL_MAYBE_DEREF(page_size)) <= 0) { throw_invalid_argument(PHP5TO7_ZVAL_MAYBE_DEREF(page_size), "page_size", "greater than zero" TSRMLS_CC); return; } self->page_size = Z_LVAL_P(PHP5TO7_ZVAL_MAYBE_DEREF(page_size)); } if (PHP5TO7_ZEND_HASH_FIND(Z_ARRVAL_P(options), "paging_state_token", sizeof("paging_state_token"), paging_state_token)) { if (Z_TYPE_P(PHP5TO7_ZVAL_MAYBE_DEREF(paging_state_token)) != IS_STRING) { throw_invalid_argument(PHP5TO7_ZVAL_MAYBE_DEREF(paging_state_token), "paging_state_token", "a string" TSRMLS_CC); return; } self->paging_state_token = estrndup(Z_STRVAL_P(PHP5TO7_ZVAL_MAYBE_DEREF(paging_state_token)), Z_STRLEN_P(PHP5TO7_ZVAL_MAYBE_DEREF(paging_state_token))); self->paging_state_token_size = Z_STRLEN_P(PHP5TO7_ZVAL_MAYBE_DEREF(paging_state_token)); } if (PHP5TO7_ZEND_HASH_FIND(Z_ARRVAL_P(options), "timeout", sizeof("timeout"), timeout)) { if (!(Z_TYPE_P(PHP5TO7_ZVAL_MAYBE_DEREF(timeout)) == IS_LONG && Z_LVAL_P(PHP5TO7_ZVAL_MAYBE_DEREF(timeout)) > 0) && !(Z_TYPE_P(PHP5TO7_ZVAL_MAYBE_DEREF(timeout)) == IS_DOUBLE && Z_DVAL_P(PHP5TO7_ZVAL_MAYBE_DEREF(timeout)) > 0) && !(Z_TYPE_P(PHP5TO7_ZVAL_MAYBE_DEREF(timeout)) == IS_NULL)) { throw_invalid_argument(PHP5TO7_ZVAL_MAYBE_DEREF(timeout), "timeout", "a number of seconds greater than zero or null" TSRMLS_CC); return; } PHP5TO7_ZVAL_COPY(PHP5TO7_ZVAL_MAYBE_P(self->timeout), PHP5TO7_ZVAL_MAYBE_DEREF(timeout)); } if (PHP5TO7_ZEND_HASH_FIND(Z_ARRVAL_P(options), "arguments", sizeof("arguments"), arguments)) { if (Z_TYPE_P(PHP5TO7_ZVAL_MAYBE_DEREF(arguments)) != IS_ARRAY) { throw_invalid_argument(PHP5TO7_ZVAL_MAYBE_DEREF(arguments), "arguments", "an array" TSRMLS_CC); return; } PHP5TO7_ZVAL_COPY(PHP5TO7_ZVAL_MAYBE_P(self->arguments), PHP5TO7_ZVAL_MAYBE_DEREF(arguments)); } if (PHP5TO7_ZEND_HASH_FIND(Z_ARRVAL_P(options), "retry_policy", sizeof("retry_policy"), retry_policy)) { if (Z_TYPE_P(PHP5TO7_ZVAL_MAYBE_DEREF(retry_policy)) != IS_OBJECT && !instanceof_function(Z_OBJCE_P(PHP5TO7_ZVAL_MAYBE_DEREF(retry_policy)), cassandra_retry_policy_ce TSRMLS_CC)) { throw_invalid_argument(PHP5TO7_ZVAL_MAYBE_DEREF(retry_policy), "retry_policy", "an instance of Cassandra\\RetryPolicy" TSRMLS_CC); return; } PHP5TO7_ZVAL_COPY(PHP5TO7_ZVAL_MAYBE_P(self->retry_policy), PHP5TO7_ZVAL_MAYBE_DEREF(retry_policy)); } if (PHP5TO7_ZEND_HASH_FIND(Z_ARRVAL_P(options), "timestamp", sizeof("timestamp"), timestamp)) { if (Z_TYPE_P(PHP5TO7_ZVAL_MAYBE_DEREF(timestamp)) == IS_LONG) { self->timestamp = Z_LVAL_P(PHP5TO7_ZVAL_MAYBE_DEREF(timestamp)); } else if (Z_TYPE_P(PHP5TO7_ZVAL_MAYBE_DEREF(timestamp)) == IS_STRING) { if (!php_cassandra_parse_bigint(Z_STRVAL_P(PHP5TO7_ZVAL_MAYBE_DEREF(timestamp)), Z_STRLEN_P(PHP5TO7_ZVAL_MAYBE_DEREF(timestamp)), &self->timestamp TSRMLS_CC)) { return; } } else { throw_invalid_argument(PHP5TO7_ZVAL_MAYBE_DEREF(timestamp), "timestamp", "an integer or integer string" TSRMLS_CC); return; } } }