static void _php_intlrbbi_constructor_body(INTERNAL_FUNCTION_PARAMETERS) { zval *object = getThis(); char *rules; size_t rules_len; zend_bool compiled = 0; UErrorCode status = U_ZERO_ERROR; intl_error_reset(NULL); if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|b", &rules, &rules_len, &compiled) == FAILURE) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "rbbi_create_instance: bad arguments", 0); Z_OBJ_P(return_value) = NULL; return; } // instantiation of ICU object RuleBasedBreakIterator *rbbi; if (!compiled) { UnicodeString rulesStr; UParseError parseError = UParseError(); if (intl_stringFromChar(rulesStr, rules, rules_len, &status) == FAILURE) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "rbbi_create_instance: rules were not a valid UTF-8 string", 0); RETURN_NULL(); } rbbi = new RuleBasedBreakIterator(rulesStr, parseError, status); intl_error_set_code(NULL, status); if (U_FAILURE(status)) { char *msg; smart_str parse_error_str; parse_error_str = intl_parse_error_to_string(&parseError); spprintf(&msg, 0, "rbbi_create_instance: unable to create " "RuleBasedBreakIterator from rules (%s)", parse_error_str.s? parse_error_str.s->val : ""); smart_str_free(&parse_error_str); intl_error_set_custom_msg(NULL, msg, 1); efree(msg); delete rbbi; Z_OBJ_P(return_value) = NULL; return; } } else { // compiled #if U_ICU_VERSION_MAJOR_NUM * 10 + U_ICU_VERSION_MINOR_NUM >= 48 rbbi = new RuleBasedBreakIterator((uint8_t*)rules, rules_len, status); if (U_FAILURE(status)) { intl_error_set(NULL, status, "rbbi_create_instance: unable to " "create instance from compiled rules", 0); Z_OBJ_P(return_value) = NULL; return; } #else intl_error_set(NULL, U_UNSUPPORTED_ERROR, "rbbi_create_instance: " "compiled rules require ICU >= 4.8", 0); Z_OBJ_P(return_value) = NULL; return; #endif } breakiterator_object_create(return_value, rbbi, 0); }
/** * Gets the endian * * @return int */ PHP_METHOD(Phalcon_Binary_Writer, getEndian){ RETURN_MEMBER(getThis(), "_endian"); }
/** * Gets the current postion * * @return int */ PHP_METHOD(Phalcon_Binary_Writer, getPosition){ RETURN_MEMBER(getThis(), "_position"); }
/** * Returns the options * * @brief int Phalcon\Crypt::getOptions() * @return int */ PHP_METHOD(Phalcon_Crypt, getOptions) { RETURN_MEMBER(getThis(), "_options"); }
PHP_METHOD(MongoDB, __toString) { mongo_db *db = (mongo_db*)zend_object_store_get_object(getThis() TSRMLS_CC); MONGO_CHECK_INITIALIZED_STRING(db->name, MongoDB); RETURN_ZVAL(db->name, 1, 0); }
static void php_mongo_enumerate_collections(INTERNAL_FUNCTION_PARAMETERS, int full_collection) { zend_bool system_col = 0; zval *nss, *collection, *cursor, *list, *next; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &system_col) == FAILURE) { return; } /* select db.system.namespaces collection */ MAKE_STD_ZVAL(nss); ZVAL_STRING(nss, "system.namespaces", 1); MAKE_STD_ZVAL(collection); MONGO_METHOD1(MongoDB, selectCollection, collection, getThis(), nss); /* list to return */ MAKE_STD_ZVAL(list); array_init(list); /* do find */ MAKE_STD_ZVAL(cursor); MONGO_METHOD(MongoCollection, find, cursor, collection); /* populate list */ MAKE_STD_ZVAL(next); MONGO_METHOD(MongoCursor, getNext, next, cursor); while (!IS_SCALAR_P(next)) { zval *c, *zname; zval **collection; char *name, *first_dot, *system; /* check that the ns is valid and not an index (contains $) */ if ( zend_hash_find(HASH_P(next), "name", 5, (void**)&collection) == FAILURE || ( Z_TYPE_PP(collection) == IS_STRING && strchr(Z_STRVAL_PP(collection), '$') ) ) { zval_ptr_dtor(&next); MAKE_STD_ZVAL(next); ZVAL_NULL(next); MONGO_METHOD(MongoCursor, getNext, next, cursor); continue; } /* check that this isn't a system ns */ first_dot = strchr(Z_STRVAL_PP(collection), '.'); system = strstr(Z_STRVAL_PP(collection), ".system."); if ( (!system_col && (system && first_dot == system)) || (name = strchr(Z_STRVAL_PP(collection), '.')) == 0) { zval_ptr_dtor(&next); MAKE_STD_ZVAL(next); ZVAL_NULL(next); MONGO_METHOD(MongoCursor, getNext, next, cursor); continue; } /* take a substring after the first "." */ name++; /* "foo." was allowed in earlier versions */ if (name == '\0') { zval_ptr_dtor(&next); MAKE_STD_ZVAL(next); ZVAL_NULL(next); MONGO_METHOD(MongoCursor, getNext, next, cursor); continue; } if (full_collection) { MAKE_STD_ZVAL(c); ZVAL_NULL(c); MAKE_STD_ZVAL(zname); ZVAL_NULL(zname); /* name must be copied because it is a substring of a string that * will be garbage collected in a sec */ ZVAL_STRING(zname, name, 1); MONGO_METHOD1(MongoDB, selectCollection, c, getThis(), zname); add_next_index_zval(list, c); zval_ptr_dtor(&zname); } else { add_next_index_string(list, name, 1); } zval_ptr_dtor(&next); MAKE_STD_ZVAL(next); MONGO_METHOD(MongoCursor, getNext, next, cursor); } zval_ptr_dtor(&next); zval_ptr_dtor(&nss); zval_ptr_dtor(&cursor); zval_ptr_dtor(&collection); RETURN_ZVAL(list, 0, 1); }
/** * Returns the current cipher method * * @return string */ PHP_METHOD(Phalcon_Crypt, getMethod){ RETURN_MEMBER(getThis(), "_method"); }
/* {{{ MongoCursor->__construct */ PHP_METHOD(MongoCursor, __construct) { zval *zlink = 0, *zns = 0, *zquery = 0, *zfields = 0, *empty, *q, *slave_okay; zval **data; mongo_cursor *cursor; mongo_link *link; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz|zz", &zlink, &zns, &zquery, &zfields) == FAILURE) { return; } // if query or fields weren't passed, make them default to an empty array MAKE_STD_ZVAL(empty); object_init(empty); // these are both initialized to the same zval, but that's okay because // there's no way to change them without creating a new cursor if (!zquery) { zquery = empty; } if (!zfields) { zfields = empty; } cursor = (mongo_cursor*)zend_object_store_get_object(getThis() TSRMLS_CC); // db connection cursor->resource = zlink; zval_add_ref(&zlink); // db connection resource ZEND_FETCH_RESOURCE2(link, mongo_link*, &zlink, -1, PHP_CONNECTION_RES_NAME, le_connection, le_pconnection); cursor->link = link; // change ['x', 'y', 'z'] into {'x' : 1, 'y' : 1, 'z' : 1} if (Z_TYPE_P(zfields) == IS_ARRAY) { HashPosition pointer; zval *fields; MAKE_STD_ZVAL(fields); object_init(fields); // fields to return for(zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(zfields), &pointer); zend_hash_get_current_data_ex(Z_ARRVAL_P(zfields), (void**) &data, &pointer) == SUCCESS; zend_hash_move_forward_ex(Z_ARRVAL_P(zfields), &pointer)) { int key_type, key_len; ulong index; char *key; key_type = zend_hash_get_current_key_ex(Z_ARRVAL_P(zfields), &key, (uint*)&key_len, &index, NO_DUP, &pointer); if (key_type == HASH_KEY_IS_LONG && Z_TYPE_PP(data) == IS_STRING) { add_property_long(fields, Z_STRVAL_PP(data), 1); } else { add_property_long(fields, key, 1); } } cursor->fields = fields; } // if it's already an object, we don't have to worry else { cursor->fields = zfields; zval_add_ref(&zfields); } // ns convert_to_string(zns); cursor->ns = estrdup(Z_STRVAL_P(zns)); // query MAKE_STD_ZVAL(q); array_init(q); add_assoc_zval(q, "query", zquery); zval_add_ref(&zquery); cursor->query = q; // reset iteration pointer, just in case MONGO_METHOD(MongoCursor, reset)(INTERNAL_FUNCTION_PARAM_PASSTHRU); cursor->at = 0; cursor->num = 0; slave_okay = zend_read_static_property(mongo_ce_Cursor, "slaveOkay", strlen("slaveOkay"), NOISY TSRMLS_CC); cursor->opts = Z_BVAL_P(slave_okay) ? (1 << 2) : 0; // get rid of extra ref zval_ptr_dtor(&empty); }
/* {{{ MongoCursor->valid */ PHP_METHOD(MongoCursor, valid) { mongo_cursor *cursor = (mongo_cursor*)zend_object_store_get_object(getThis() TSRMLS_CC); MONGO_CHECK_INITIALIZED(cursor->link, MongoCursor); RETURN_BOOL(cursor->current); }
/* {{{ MongoCursor::dead */ PHP_METHOD(MongoCursor, dead) { mongo_cursor *cursor = (mongo_cursor*)zend_object_store_get_object(getThis() TSRMLS_CC); MONGO_CHECK_INITIALIZED(cursor->link, MongoCursor); RETURN_BOOL(cursor->started_iterating && cursor->cursor_id == 0); }
/* {{{ MongoCursor::slaveOkay */ PHP_METHOD(MongoCursor, slaveOkay) { preiteration_setup; default_to_true(2); RETURN_ZVAL(getThis(), 1, 0); }
/* {{{ MongoCursor::tailable */ PHP_METHOD(MongoCursor, tailable) { preiteration_setup; default_to_true(1); RETURN_ZVAL(getThis(), 1, 0); }
PHP_METHOD(DefaultCluster, connect) { CassFuture *future = NULL; char *hash_key; php5to7_size hash_key_len = 0; char *keyspace = NULL; php5to7_size keyspace_len; zval *timeout = NULL; cassandra_psession *psession; cassandra_cluster *cluster = NULL; cassandra_session *session = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|sz", &keyspace, &keyspace_len, &timeout) == FAILURE) { return; } cluster = PHP_CASSANDRA_GET_CLUSTER(getThis()); object_init_ex(return_value, cassandra_default_session_ce); session = PHP_CASSANDRA_GET_SESSION(return_value); session->default_consistency = cluster->default_consistency; session->default_page_size = cluster->default_page_size; session->persist = cluster->persist; if (!PHP5TO7_ZVAL_IS_UNDEF(session->default_timeout)) { PHP5TO7_ZVAL_COPY(PHP5TO7_ZVAL_MAYBE_P(session->default_timeout), PHP5TO7_ZVAL_MAYBE_P(cluster->default_timeout)); } if (session->persist) { php5to7_zend_resource_le *le; hash_key_len = spprintf(&hash_key, 0, "%s:session:%s", cluster->hash_key, SAFE_STR(keyspace)); if (PHP5TO7_ZEND_HASH_FIND(&EG(persistent_list), hash_key, hash_key_len + 1, le) && Z_RES_P(le)->type == php_le_cassandra_session()) { psession = (cassandra_psession *) Z_RES_P(le)->ptr; session->session = psession->session; future = psession->future; } } if (future == NULL) { php5to7_zend_resource_le resource; session->session = cass_session_new(); if (keyspace) { future = cass_session_connect_keyspace(session->session, cluster->cluster, keyspace); } else { future = cass_session_connect(session->session, cluster->cluster); } if (session->persist) { psession = (cassandra_psession *) pecalloc(1, sizeof(cassandra_psession), 1); psession->session = session->session; psession->future = future; #if PHP_MAJOR_VERSION >= 7 ZVAL_NEW_PERSISTENT_RES(&resource, 0, psession, php_le_cassandra_session()); PHP5TO7_ZEND_HASH_UPDATE(&EG(persistent_list), hash_key, hash_key_len + 1, &resource, sizeof(php5to7_zend_resource_le)); CASSANDRA_G(persistent_sessions)++; #else resource.type = php_le_cassandra_session(); resource.ptr = psession; PHP5TO7_ZEND_HASH_UPDATE(&EG(persistent_list), hash_key, hash_key_len + 1, resource, sizeof(php5to7_zend_resource_le)); CASSANDRA_G(persistent_sessions)++; #endif } } if (php_cassandra_future_wait_timed(future, timeout TSRMLS_CC) == FAILURE) { if (session->persist) { efree(hash_key); } else { cass_future_free(future); } return; } if (php_cassandra_future_is_error(future TSRMLS_CC) == FAILURE) { if (session->persist) { if (PHP5TO7_ZEND_HASH_DEL(&EG(persistent_list), hash_key, hash_key_len + 1)) { session->session = NULL; } efree(hash_key); } else { cass_future_free(future); } return; } if (session->persist) efree(hash_key); }
PHP_METHOD(DefaultCluster, connectAsync) { char *hash_key; php5to7_size hash_key_len = 0; char *keyspace = NULL; php5to7_size keyspace_len; cassandra_cluster *cluster = NULL; cassandra_future_session *future = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &keyspace, &keyspace_len) == FAILURE) { return; } cluster = PHP_CASSANDRA_GET_CLUSTER(getThis()); object_init_ex(return_value, cassandra_future_session_ce); future = PHP_CASSANDRA_GET_FUTURE_SESSION(return_value); future->persist = cluster->persist; if (cluster->persist) { php5to7_zend_resource_le *le; hash_key_len = spprintf(&hash_key, 0, "%s:session:%s", cluster->hash_key, SAFE_STR(keyspace)); future->hash_key = hash_key; future->hash_key_len = hash_key_len; if (PHP5TO7_ZEND_HASH_FIND(&EG(persistent_list), hash_key, hash_key_len + 1, le)) { if (Z_TYPE_P(le) == php_le_cassandra_session()) { cassandra_psession *psession = (cassandra_psession *) Z_RES_P(le)->ptr; future->session = psession->session; future->future = psession->future; return; } } } future->session = cass_session_new(); if (keyspace) { future->future = cass_session_connect_keyspace(future->session, cluster->cluster, keyspace); } else { future->future = cass_session_connect(future->session, cluster->cluster); } if (cluster->persist) { php5to7_zend_resource_le resource; cassandra_psession *psession = (cassandra_psession *) pecalloc(1, sizeof(cassandra_psession), 1); psession->session = future->session; psession->future = future->future; #if PHP_MAJOR_VERSION >= 7 ZVAL_NEW_PERSISTENT_RES(&resource, 0, psession, php_le_cassandra_session()); PHP5TO7_ZEND_HASH_UPDATE(&EG(persistent_list), hash_key, hash_key_len + 1, &resource, sizeof(php5to7_zend_resource_le)); CASSANDRA_G(persistent_sessions)++; #else resource.type = php_le_cassandra_session(); resource.ptr = psession; PHP5TO7_ZEND_HASH_UPDATE(&EG(persistent_list), hash_key, hash_key_len + 1, resource, sizeof(php5to7_zend_resource_le)); CASSANDRA_G(persistent_sessions)++; #endif } }
/** * Magic __toString method returns verbose message * * @return string */ PHP_METHOD(Phalcon_Validation_Message, __toString){ RETURN_MEMBER(getThis(), "_message"); }
PHP_METHOD(MongoCursor, count) { zval *response, *data, *db; zval **n; mongo_cursor *cursor; mongo_db *db_struct; cursor = (mongo_cursor*)zend_object_store_get_object(getThis() TSRMLS_CC); MONGO_CHECK_INITIALIZED(cursor->link, MongoCursor); // fake a MongoDB object MAKE_STD_ZVAL(db); object_init_ex(db, mongo_ce_DB); db_struct = (mongo_db*)zend_object_store_get_object(db TSRMLS_CC); db_struct->link = cursor->resource; zval_add_ref(&cursor->resource); MAKE_STD_ZVAL(db_struct->name); ZVAL_STRING(db_struct->name, estrndup(cursor->ns, strchr(cursor->ns, '.') - cursor->ns), 0); // create query MAKE_STD_ZVAL(data); object_init(data); // "count" => "collectionName" add_property_string(data, "count", strchr(cursor->ns, '.')+1, 1); if (cursor->query) { zval **inner_query; if (zend_hash_find(HASH_P(cursor->query), "query", strlen("query")+1, (void**)&inner_query) == SUCCESS) { add_property_zval(data, "query", *inner_query); zval_add_ref(inner_query); } } if (cursor->fields) { add_property_zval(data, "fields", cursor->fields); zval_add_ref(&cursor->fields); } MAKE_STD_ZVAL(response); PUSH_PARAM(data); PUSH_PARAM((void*)1); PUSH_EO_PARAM(); MONGO_METHOD(MongoDB, command)(1, response, &response, db, return_value_used TSRMLS_CC); POP_EO_PARAM(); POP_PARAM(); POP_PARAM(); zval_ptr_dtor(&data); // prep results if (zend_hash_find(HASH_P(response), "n", 2, (void**)&n) == SUCCESS) { // don't allow count to return more than cursor->limit if (cursor->limit > 0 && Z_DVAL_PP(n) > cursor->limit) { RETVAL_LONG(cursor->limit); } else { convert_to_long(*n); RETVAL_ZVAL(*n, 1, 0); } zval_ptr_dtor(&response); } else { RETURN_ZVAL(response, 0, 0); } zend_objects_store_del_ref(db TSRMLS_CC); zval_ptr_dtor(&db); }
PHP_METHOD(MongoDB, getSlaveOkay) { mongo_db *db; PHP_MONGO_GET_DB(getThis()); RETURN_BOOL(db->read_pref.type != MONGO_RP_PRIMARY); }
/* {{{ proto object ffmpeg_movie(string filename) Constructor for ffmpeg_movie objects */ FFMPEG_PHP_CONSTRUCTOR(ffmpeg_movie, __construct) { int hashkey_length = 0, filename_len; char *filename = NULL, *fullpath = NULL, *hashkey = NULL; zend_bool persistent = 0; ff_movie_context *ffmovie_ctx = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|b", &filename, &filename_len, &persistent) != SUCCESS) { return; } if (persistent && !INI_BOOL("ffmpeg.allow_persistent")) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Persistent movies have been disabled in php.ini"); RETURN_FALSE; } if (persistent) { zend_rsrc_list_entry *le; /* resolve the fully-qualified path name to use as the hash key */ fullpath = expand_filepath(filename, NULL TSRMLS_CC); hashkey_length = sizeof("ffmpeg-php_")-1 + filename_len; hashkey = (char *) emalloc(hashkey_length+1); snprintf(hashkey, hashkey_length, "ffmpeg-php_%s", filename); /* do we have an existing persistent movie? */ if (SUCCESS == zend_hash_find(&EG(persistent_list), hashkey, hashkey_length+1, (void**)&le)) { int type; if (Z_TYPE_P(le) != le_ffmpeg_pmovie) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to retrieve persistent resource"); efree(hashkey); RETURN_FALSE; } ffmovie_ctx = (ff_movie_context*)le->ptr; /* sanity check to ensure that the resource is still a valid * regular resource number */ if (zend_list_find(ffmovie_ctx->rsrc_id, &type) == ffmovie_ctx) { /* add a reference to the persistent movie */ zend_list_addref(ffmovie_ctx->rsrc_id); } else { //php_error_docref(NULL TSRMLS_CC, E_ERROR, //"Not a valid persistent movie resource"); ffmovie_ctx->rsrc_id = ZEND_REGISTER_RESOURCE(NULL, ffmovie_ctx, le_ffmpeg_pmovie); } } else { /* no existing persistant movie, create one */ zend_rsrc_list_entry new_le; ffmovie_ctx = _php_alloc_ffmovie_ctx(1); if (_php_open_movie_file(ffmovie_ctx, filename)) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Can't open movie file %s", filename); ZVAL_BOOL(getThis(), 0); RETURN_FALSE; } Z_TYPE(new_le) = le_ffmpeg_pmovie; new_le.ptr = ffmovie_ctx; if (FAILURE == zend_hash_update(&EG(persistent_list), hashkey, hashkey_length+1, (void *)&new_le, sizeof(zend_rsrc_list_entry), NULL)) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to register persistent resource"); RETURN_FALSE; } ffmovie_ctx->rsrc_id = ZEND_REGISTER_RESOURCE(NULL, ffmovie_ctx, le_ffmpeg_pmovie); } } else { ffmovie_ctx = _php_alloc_ffmovie_ctx(0); if (_php_open_movie_file(ffmovie_ctx, filename)) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Can't open movie file %s", filename); ZVAL_BOOL(getThis(), 0); RETURN_FALSE; } /* pass NULL for resource result since we're not returning the resource directly, but adding it to the returned object. */ ffmovie_ctx->rsrc_id = ZEND_REGISTER_RESOURCE(NULL, ffmovie_ctx, le_ffmpeg_movie); } object_init_ex(getThis(), ffmpeg_movie_class_entry_ptr); add_property_resource(getThis(), "ffmpeg_movie", ffmovie_ctx->rsrc_id); if (fullpath) { efree(fullpath); } if (hashkey) { efree(hashkey); } }
PHP_METHOD(MongoDB, command) { zval limit, *temp, *cmd, *cursor, *ns, *options = 0; mongo_db *db; mongoclient *link; char *cmd_ns; mongo_cursor *cursor_tmp; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|a", &cmd, &options) == FAILURE) { return; } MUST_BE_ARRAY_OR_OBJECT(1, cmd); PHP_MONGO_GET_DB(getThis()); /* create db.$cmd */ MAKE_STD_ZVAL(ns); cmd_ns = get_cmd_ns(Z_STRVAL_P(db->name), Z_STRLEN_P(db->name)); ZVAL_STRING(ns, cmd_ns, 0); /* create cursor, with RP inherited from us */ MAKE_STD_ZVAL(cursor); object_init_ex(cursor, mongo_ce_Cursor); cursor_tmp = (mongo_cursor*)zend_object_store_get_object(cursor TSRMLS_CC); mongo_read_preference_replace(&db->read_pref, &cursor_tmp->read_pref); MAKE_STD_ZVAL(temp); ZVAL_NULL(temp); MONGO_METHOD3(MongoCursor, __construct, temp, cursor, db->link, ns, cmd); zval_ptr_dtor(&ns); zval_ptr_dtor(&temp); MAKE_STD_ZVAL(temp); ZVAL_NULL(temp); // limit Z_TYPE(limit) = IS_LONG; Z_LVAL(limit) = -1; MONGO_METHOD1(MongoCursor, limit, temp, cursor, &limit); zval_ptr_dtor(&temp); if (options) { zval **timeout; if (zend_hash_find(HASH_P(options), "timeout", strlen("timeout") + 1, (void**)&timeout) == SUCCESS) { MAKE_STD_ZVAL(temp); ZVAL_NULL(temp); MONGO_METHOD1(MongoCursor, timeout, temp, cursor, *timeout); zval_ptr_dtor(&temp); } } /* Make sure commands aren't be sent to slaves */ /* TODO: The read preferences spec has a list of commands that *can* be send * to slave */ /* This should be refactored alongside with the getLastError redirection in * collection.c/append_getlasterror. The Cursor creation should be done * through an init method. */ PHP_MONGO_GET_LINK(db->link); if (php_mongo_command_supports_rp(cmd)) { mongo_manager_log(link->manager, MLOG_CON, MLOG_INFO, "command supports Read Preferences"); } else { mongo_manager_log(link->manager, MLOG_CON, MLOG_INFO, "forcing primary for command"); php_mongo_connection_force_primary(cursor_tmp); } /* query */ MONGO_METHOD(MongoCursor, getNext, return_value, cursor); clear_exception(return_value TSRMLS_CC); zend_objects_store_del_ref(cursor TSRMLS_CC); zval_ptr_dtor(&cursor); }
PHP_METHOD(Phalcon_Logger_Formatter_Firephp, labelsEnabled) { RETURN_MEMBER(getThis(), "_enableLabels"); }
/** * Returns the encryption key * * @return string */ PHP_METHOD(Phalcon_Crypt, getKey){ RETURN_MEMBER(getThis(), "_key"); }
/** * Applies a format to a message before sending it to the log * * @param string $message * @param int $type * @param int $timestamp * @param array $context * @return string */ PHP_METHOD(Phalcon_Logger_Formatter_Firephp, format) { zval *message, *type, *type_str = NULL, *timestamp, *context, *interpolated = NULL; zval *payload, *body, *backtrace = NULL, *meta, *encoded; zval *show_backtrace, *enable_labels; int i_show_backtrace, i_enable_labels; smart_str result = { NULL, 0, 0 }; uint i; Bucket *p; phalcon_fetch_params(0, 4, 0, &message, &type, ×tamp, &context); /* * We intentionally do not use Phalcon's MM for better performance. * All variables allocated with ALLOC_INIT_ZVAL() will have * their reference count set to 1 and therefore they can be nicely * put into the result array; when that array will be destroyed, * all inserted variables will be automatically destroyed, too * and we will just save some time by not using Z_ADDREF_P and Z_DELREF_P */ if (Z_TYPE_P(context) == IS_ARRAY) { PHALCON_CALL_METHODW(&interpolated, this_ptr, "interpolate", message, context); } else { interpolated = message; Z_ADDREF_P(interpolated); } { zval *params[] = { type }; if (FAILURE == phalcon_call_method(&type_str, this_ptr, "gettypestring", 1, params TSRMLS_CC)) { zval_ptr_dtor(&interpolated); return; } } show_backtrace = phalcon_fetch_nproperty_this(getThis(), SL("_showBacktrace"), PH_NOISY TSRMLS_CC); enable_labels = phalcon_fetch_nproperty_this(getThis(), SL("_enableLabels"), PH_NOISY TSRMLS_CC); i_show_backtrace = zend_is_true(show_backtrace); i_enable_labels = zend_is_true(enable_labels); /* * Get the backtrace. This differs for different PHP versions. * 5.3.6+ allows us to skip the function arguments which will save some memory * For 5.4+ there is an extra argument. */ if (i_show_backtrace) { ALLOC_INIT_ZVAL(backtrace); #if PHP_VERSION_ID < 50306 zend_fetch_debug_backtrace(backtrace, 1, 0 TSRMLS_CC); #elif PHP_VERSION_ID < 50400 zend_fetch_debug_backtrace(backtrace, 1, DEBUG_BACKTRACE_IGNORE_ARGS TSRMLS_CC); #else zend_fetch_debug_backtrace(backtrace, 1, DEBUG_BACKTRACE_IGNORE_ARGS, 0 TSRMLS_CC); #endif if (Z_TYPE_P(backtrace) == IS_ARRAY) { HashPosition pos; HashTable *ht = Z_ARRVAL_P(backtrace); zval **ppzval; int found = 0; ulong idx; char *key; uint key_len; /* * At this point we know that the backtrace is the array. * Again, we intentionally do not use Phalcon's API because we know * that we are working with the array / hash table and thus we can * save some time by omitting Z_TYPE_P(x) == IS_ARRAY checks */ for ( zend_hash_internal_pointer_reset_ex(ht, &pos); zend_hash_has_more_elements_ex(ht, &pos) == SUCCESS; ) { zend_hash_get_current_data_ex(ht, (void**)&ppzval, &pos); zend_hash_get_current_key_ex(ht, &key, &key_len, &idx, 0, &pos); zend_hash_move_forward_ex(ht, &pos); if (Z_TYPE_PP(ppzval) == IS_ARRAY) { /* * Here we need to skip the latest calls into Phalcon's core. * Calls to Zend internal functions will have "file" index not set. * We remove these entries from the array. */ if (!found && !zend_hash_quick_exists(Z_ARRVAL_PP(ppzval), SS("file"), zend_inline_hash_func(SS("file")))) { zend_hash_index_del(ht, idx); } else { /* * Remove args and object indices. They usually give * too much information; this is not suitable to send * in the HTTP headers */ zend_hash_quick_del(Z_ARRVAL_PP(ppzval), "args", sizeof("args"), zend_inline_hash_func(SS("args"))); zend_hash_quick_del(Z_ARRVAL_PP(ppzval), "object", sizeof("object"), zend_inline_hash_func(SS("object"))); found = 1; } } } /* * Now we need to renumber the hash table because we removed several * heading elements. If we don't do this, json_encode() will convert * this array to a JavaScript object which is an unwanted side effect */ p = ht->pListHead; i = 0; while (p != NULL) { p->nKeyLength = 0; p->h = i++; p = p->pListNext; } ht->nNextFreeElement = i; zend_hash_rehash(ht); } } /* * The result will looks like this: * * array( * array('Type' => 'message type', 'Label' => 'message'), * array('backtrace' => array(backtrace goes here) * ) */ MAKE_STD_ZVAL(payload); array_init_size(payload, 2); MAKE_STD_ZVAL(meta); array_init_size(meta, 4); add_assoc_zval_ex(meta, SS("Type"), type_str); if (i_show_backtrace && Z_TYPE_P(backtrace) == IS_ARRAY) { zval **ppzval; if (likely(SUCCESS == zend_hash_index_find(Z_ARRVAL_P(backtrace), 0, (void**)&ppzval)) && likely(Z_TYPE_PP(ppzval) == IS_ARRAY)) { zval **file = NULL, **line = NULL; zend_hash_quick_find(Z_ARRVAL_PP(ppzval), SS("file"), zend_inline_hash_func(SS("file")), (void**)&file); zend_hash_quick_find(Z_ARRVAL_PP(ppzval), SS("line"), zend_inline_hash_func(SS("line")), (void**)&line); if (likely(file != NULL)) { Z_ADDREF_PP(file); add_assoc_zval_ex(meta, SS("File"), *file); } if (likely(line != NULL)) { Z_ADDREF_PP(line); add_assoc_zval_ex(meta, SS("Line"), *line); } } } if (i_enable_labels) { add_assoc_zval_ex(meta, SS("Label"), interpolated); } if (!i_enable_labels && !i_show_backtrace) { body = interpolated; } else if (i_enable_labels && !i_show_backtrace) { MAKE_STD_ZVAL(body); ZVAL_EMPTY_STRING(body); } else { MAKE_STD_ZVAL(body); array_init_size(body, 2); if (i_show_backtrace) { add_assoc_zval_ex(body, SS("backtrace"), backtrace); } if (!i_enable_labels) { add_assoc_zval_ex(body, SS("message"), interpolated); } } add_next_index_zval(payload, meta); add_next_index_zval(payload, body); /* Convert everything to JSON */ ALLOC_INIT_ZVAL(encoded); if (FAILURE == phalcon_json_encode(encoded, payload, 0 TSRMLS_CC)) { zval_ptr_dtor(&payload); zval_ptr_dtor(&encoded); return; } /* As promised, kill the payload and all associated elements */ zval_ptr_dtor(&payload); /* * We don't want to use Phalcon's concatenation API because it * requires the memory manager. Therefore we fall back to using smart strings. * smart_str_alloc4() will allocate all required memory amount (plus some more) * in one go and this allows us to avoid performance penalties due to * memory reallocations. */ if (Z_TYPE_P(encoded) == IS_STRING && Z_STRVAL_P(encoded) != NULL) { smart_str_alloc4(&result, (uint)(Z_STRLEN_P(encoded) + 2 + 5), 0, i); /* * The format is: * * <size>|[meta,body]| * * Meta and body are contained in encoded inside the array, as required * by the protocol specification * @see http://www.firephp.org/Wiki/Reference/Protocol */ smart_str_append_long(&result, Z_STRLEN_P(encoded)); smart_str_appendc(&result, '|'); smart_str_appendl(&result, Z_STRVAL_P(encoded), Z_STRLEN_P(encoded)); smart_str_appendc(&result, '|'); smart_str_0(&result); } /* We don't need the JSON message anymore */ zval_ptr_dtor(&encoded); /* Do not free the smart string because we steal its data for zval */ RETURN_STRINGL(result.c, result.len, 0); }
/** * Decrypts an encrypted text * *<code> * echo $crypt->decrypt($encrypted, "decrypt password"); *</code> * * @param string $text * @param string $key * @param int $options * @return string */ PHP_METHOD(Phalcon_Crypt, decrypt){ zval *source, *key = NULL, *options = NULL, handler = {}, arguments = {}, value = {}, text = {}, encrypt_key = {}, encrypt_options = {}; zval method = {}, iv_size = {}, iv = {}, text_to_decipher = {}; phalcon_fetch_params(0, 1, 2, &source, &key, &options); if (phalcon_function_exists_ex(SL("openssl_encrypt")) == FAILURE) { PHALCON_THROW_EXCEPTION_STRW(phalcon_crypt_exception_ce, "openssl extension is required"); return; } phalcon_read_property(&handler, getThis(), SL("_beforeDecrypt"), PH_NOISY); if (phalcon_is_callable(&handler)) { PHALCON_SEPARATE_PARAM(source); array_init_size(&arguments, 1); phalcon_array_append(&arguments, source, PH_COPY); PHALCON_CALL_USER_FUNC_ARRAYW(&value, &handler, &arguments); source = &value; } /* Do not use make_printable_zval() here: we need the conversion with type juggling */ if (Z_TYPE_P(source) != IS_STRING) { phalcon_cast(&text, source, IS_STRING); } else { PHALCON_CPY_WRT_CTOR(&text, source); } if (!key || Z_TYPE_P(key) == IS_NULL) { phalcon_return_property(&encrypt_key, getThis(), SL("_key")); } else { PHALCON_CPY_WRT_CTOR(&encrypt_key, key); if (Z_TYPE(encrypt_key) != IS_STRING) { convert_to_string(&encrypt_key); } } if (!options || Z_TYPE_P(options) == IS_NULL) { phalcon_return_property(&encrypt_options, getThis(), SL("_options")); } else { PHALCON_CPY_WRT_CTOR(&encrypt_options, options); } phalcon_read_property(&method, getThis(), SL("_method"), PH_NOISY); PHALCON_CALL_FUNCTIONW(&iv_size, "openssl_cipher_iv_length", &method); if (Z_LVAL(iv_size) <= 0) { ZVAL_NULL(&iv); PHALCON_CPY_WRT_CTOR(&text_to_decipher, &text); } else { phalcon_substr(&iv, &text, 0, Z_LVAL(iv_size)); phalcon_substr(&text_to_decipher, &text, Z_LVAL(iv_size), 0); } PHALCON_CALL_FUNCTIONW(return_value, "openssl_decrypt", &text_to_decipher, &method, &encrypt_key, &encrypt_options, &iv); if (unlikely(Z_TYPE_P(return_value) != IS_STRING)) { convert_to_string(return_value); } phalcon_read_property(&handler, getThis(), SL("_afterDecrypt"), PH_NOISY); if (phalcon_is_callable(&handler)) { array_init_size(&arguments, 1); phalcon_array_append(&arguments, return_value, PH_COPY); PHALCON_CALL_USER_FUNC_ARRAYW(&value, &handler, &arguments); RETURN_CTORW(&value); } }
PHP_METHOD(Phalcon_Logger_Formatter_Firephp, getShowBacktrace) { RETURN_MEMBER(getThis(), "_showBacktrace"); }
/** * Set an specific argument */ PHP_METHOD(Phalcon_Cli_Console, setArgument) { HashTable *_2; HashPosition _1; zephir_fcall_cache_entry *_7 = NULL, *_26 = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; zend_bool str, shift, _0; zval *arguments_param = NULL, *str_param = NULL, *shift_param = NULL, *arg = NULL, *pos = NULL, *args = NULL, *opts = NULL, *handleArgs = NULL, **_3, _4$$5 = zval_used_for_init, _5$$5 = zval_used_for_init, *_6$$5 = NULL, _8$$6 = zval_used_for_init, *_9$$7 = NULL, _10$$7 = zval_used_for_init, *_11$$7 = NULL, *_12$$7 = NULL, _13$$7 = zval_used_for_init, _14$$7 = zval_used_for_init, *_15$$7 = NULL, *_16$$8 = NULL, _17$$8 = zval_used_for_init, *_18$$8 = NULL, _19$$9 = zval_used_for_init, _20$$9 = zval_used_for_init, *_21$$9 = NULL, _22$$10 = zval_used_for_init, *_23$$10 = NULL, *_24$$13, *_25$$13 = NULL, *_27$$15 = NULL, *_28$$16 = NULL, *_29$$17; zval *arguments = NULL; ZEPHIR_MM_GROW(); zephir_fetch_params(1, 0, 3, &arguments_param, &str_param, &shift_param); if (!arguments_param) { ZEPHIR_INIT_VAR(arguments); array_init(arguments); } else { arguments = arguments_param; } if (!str_param) { str = 1; } else { if (UNEXPECTED(Z_TYPE_P(str_param) != IS_BOOL)) { zephir_throw_exception_string(spl_ce_InvalidArgumentException, SL("Parameter 'str' must be a bool") TSRMLS_CC); RETURN_MM_NULL(); } str = Z_BVAL_P(str_param); } if (!shift_param) { shift = 1; } else { if (UNEXPECTED(Z_TYPE_P(shift_param) != IS_BOOL)) { zephir_throw_exception_string(spl_ce_InvalidArgumentException, SL("Parameter 'shift' must be a bool") TSRMLS_CC); RETURN_MM_NULL(); } shift = Z_BVAL_P(shift_param); } ZEPHIR_INIT_VAR(args); array_init(args); ZEPHIR_INIT_VAR(opts); array_init(opts); ZEPHIR_INIT_VAR(handleArgs); array_init(handleArgs); _0 = shift; if (_0) { _0 = ((zephir_fast_count_int(arguments TSRMLS_CC)) ? 1 : 0); } if (_0) { ZEPHIR_MAKE_REF(arguments); ZEPHIR_CALL_FUNCTION(NULL, "array_shift", NULL, 19, arguments); ZEPHIR_UNREF(arguments); zephir_check_call_status(); } zephir_is_iterable(arguments, &_2, &_1, 0, 0, "phalcon/cli/console.zep", 201); for ( ; zend_hash_get_current_data_ex(_2, (void**) &_3, &_1) == SUCCESS ; zend_hash_move_forward_ex(_2, &_1) ) { ZEPHIR_GET_HVALUE(arg, _3); if (Z_TYPE_P(arg) == IS_STRING) { ZEPHIR_SINIT_NVAR(_4$$5); ZVAL_STRING(&_4$$5, "--", 0); ZEPHIR_SINIT_NVAR(_5$$5); ZVAL_LONG(&_5$$5, 2); ZEPHIR_CALL_FUNCTION(&_6$$5, "strncmp", &_7, 137, arg, &_4$$5, &_5$$5); zephir_check_call_status(); if (ZEPHIR_IS_LONG(_6$$5, 0)) { ZEPHIR_SINIT_NVAR(_8$$6); ZVAL_STRING(&_8$$6, "=", 0); ZEPHIR_INIT_NVAR(pos); zephir_fast_strpos(pos, arg, &_8$$6, 0 ); if (zephir_is_true(pos)) { ZEPHIR_INIT_NVAR(_9$$7); ZEPHIR_SINIT_NVAR(_10$$7); ZVAL_LONG(&_10$$7, (zephir_get_numberval(pos) + 1)); ZEPHIR_INIT_NVAR(_11$$7); zephir_substr(_11$$7, arg, zephir_get_intval(&_10$$7), 0, ZEPHIR_SUBSTR_NO_LENGTH); zephir_fast_trim(_9$$7, _11$$7, NULL , ZEPHIR_TRIM_BOTH TSRMLS_CC); ZEPHIR_INIT_NVAR(_12$$7); ZEPHIR_SINIT_NVAR(_13$$7); ZVAL_LONG(&_13$$7, 2); ZEPHIR_SINIT_NVAR(_14$$7); ZVAL_LONG(&_14$$7, (zephir_get_numberval(pos) - 2)); ZEPHIR_INIT_NVAR(_15$$7); zephir_substr(_15$$7, arg, 2 , zephir_get_intval(&_14$$7), 0); zephir_fast_trim(_12$$7, _15$$7, NULL , ZEPHIR_TRIM_BOTH TSRMLS_CC); zephir_array_update_zval(&opts, _12$$7, &_9$$7, PH_COPY | PH_SEPARATE); } else { ZEPHIR_INIT_NVAR(_16$$8); ZEPHIR_SINIT_NVAR(_17$$8); ZVAL_LONG(&_17$$8, 2); ZEPHIR_INIT_NVAR(_18$$8); zephir_substr(_18$$8, arg, 2 , 0, ZEPHIR_SUBSTR_NO_LENGTH); zephir_fast_trim(_16$$8, _18$$8, NULL , ZEPHIR_TRIM_BOTH TSRMLS_CC); zephir_array_update_zval(&opts, _16$$8, &ZEPHIR_GLOBAL(global_true), PH_COPY | PH_SEPARATE); } } else { ZEPHIR_SINIT_NVAR(_19$$9); ZVAL_STRING(&_19$$9, "-", 0); ZEPHIR_SINIT_NVAR(_20$$9); ZVAL_LONG(&_20$$9, 1); ZEPHIR_CALL_FUNCTION(&_21$$9, "strncmp", &_7, 137, arg, &_19$$9, &_20$$9); zephir_check_call_status(); if (ZEPHIR_IS_LONG(_21$$9, 0)) { ZEPHIR_SINIT_NVAR(_22$$10); ZVAL_LONG(&_22$$10, 1); ZEPHIR_INIT_NVAR(_23$$10); zephir_substr(_23$$10, arg, 1 , 0, ZEPHIR_SUBSTR_NO_LENGTH); zephir_array_update_zval(&opts, _23$$10, &ZEPHIR_GLOBAL(global_true), PH_COPY | PH_SEPARATE); } else { zephir_array_append(&args, arg, PH_SEPARATE, "phalcon/cli/console.zep", 193); } } } else { zephir_array_append(&args, arg, PH_SEPARATE, "phalcon/cli/console.zep", 197); } } if (str) { ZEPHIR_INIT_VAR(_24$$13); ZEPHIR_CALL_CE_STATIC(&_25$$13, phalcon_cli_router_route_ce, "getdelimiter", &_26, 138); zephir_check_call_status(); zephir_fast_join(_24$$13, _25$$13, args TSRMLS_CC); zephir_update_property_this(getThis(), SL("_arguments"), _24$$13 TSRMLS_CC); } else { if (zephir_fast_count_int(args TSRMLS_CC)) { ZEPHIR_MAKE_REF(args); ZEPHIR_CALL_FUNCTION(&_27$$15, "array_shift", NULL, 19, args); ZEPHIR_UNREF(args); zephir_check_call_status(); zephir_array_update_string(&handleArgs, SL("task"), &_27$$15, PH_COPY | PH_SEPARATE); } if (zephir_fast_count_int(args TSRMLS_CC)) { ZEPHIR_MAKE_REF(args); ZEPHIR_CALL_FUNCTION(&_28$$16, "array_shift", NULL, 19, args); ZEPHIR_UNREF(args); zephir_check_call_status(); zephir_array_update_string(&handleArgs, SL("action"), &_28$$16, PH_COPY | PH_SEPARATE); } if (zephir_fast_count_int(args TSRMLS_CC)) { ZEPHIR_INIT_VAR(_29$$17); zephir_fast_array_merge(_29$$17, &(handleArgs), &(args) TSRMLS_CC); ZEPHIR_CPY_WRT(handleArgs, _29$$17); } zephir_update_property_this(getThis(), SL("_arguments"), handleArgs TSRMLS_CC); } zephir_update_property_this(getThis(), SL("_options"), opts TSRMLS_CC); RETURN_THIS(); }
/** * Returns verbose message * * @return string */ PHP_METHOD(Phalcon_Validation_Message, getMessage){ RETURN_MEMBER(getThis(), "_message"); }
/** * Gets the ouput * * @return int */ PHP_METHOD(Phalcon_Binary_Writer, getOutput){ RETURN_MEMBER(getThis(), "_output"); }
/** * Returns field name related to message * * @return string */ PHP_METHOD(Phalcon_Validation_Message, getField){ RETURN_MEMBER(getThis(), "_field"); }
ZEND_METHOD(YConsistent,consistent_init){ zval *object = getThis(); conhash *con = conhash_init(); int res_id = ZEND_REGISTER_RESOURCE(NULL,con,le_conhash); add_property_resource(object,"conhash",res_id); }
PHP_METHOD(SpotifyArtist, __toString) { spotifyartist_object *p = (spotifyartist_object*)zend_object_store_get_object(getThis() TSRMLS_CC); RETURN_STRING(sp_artist_name(p->artist), 1); }