/** * Extracts a slice from a string/array/traversable object value */ PHP_METHOD(Phalcon_Mvc_View_Engine_Volt, slice) { zend_bool _1$$5; zephir_fcall_cache_entry *_3 = NULL, *_4 = NULL, *_7 = NULL; int start, ZEPHIR_LAST_CALL_STATUS, position = 0; zval *value, *start_param = NULL, *end = NULL, *length = NULL, *slice = NULL, _10, *_0$$3 = NULL, *_2$$6 = NULL, _5$$9, _6$$11, _8$$10, _9$$12; ZEPHIR_MM_GROW(); zephir_fetch_params(1, 1, 2, &value, &start_param, &end); if (!start_param) { start = 0; } else { start = zephir_get_intval(start_param); } if (!end) { ZEPHIR_CPY_WRT(end, ZEPHIR_GLOBAL(global_null)); } else { ZEPHIR_SEPARATE_PARAM(end); } if (Z_TYPE_P(value) == IS_OBJECT) { if (Z_TYPE_P(end) == IS_NULL) { ZEPHIR_INIT_NVAR(end); ZVAL_LONG(end, (zephir_fast_count_int(value TSRMLS_CC) - 1)); } position = 0; ZEPHIR_INIT_VAR(slice); array_init(slice); ZEPHIR_CALL_METHOD(NULL, value, "rewind", NULL, 0); zephir_check_call_status(); while (1) { ZEPHIR_CALL_METHOD(&_0$$3, value, "valid", NULL, 0); zephir_check_call_status(); if (!(zephir_is_true(_0$$3))) { break; } _1$$5 = position >= start; if (_1$$5) { _1$$5 = ZEPHIR_GE_LONG(end, position); } if (_1$$5) { ZEPHIR_CALL_METHOD(&_2$$6, value, "current", &_3, 0); zephir_check_call_status(); zephir_array_append(&slice, _2$$6, PH_SEPARATE, "phalcon/mvc/view/engine/volt.zep", 231); } ZEPHIR_CALL_METHOD(NULL, value, "next", &_4, 0); zephir_check_call_status(); position++; } RETURN_CCTOR(slice); } ZEPHIR_INIT_VAR(length); if (Z_TYPE_P(end) != IS_NULL) { ZVAL_LONG(length, (((zephir_get_numberval(end) - start)) + 1)); } else { ZVAL_NULL(length); } if (Z_TYPE_P(value) == IS_ARRAY) { ZEPHIR_SINIT_VAR(_5$$9); ZVAL_LONG(&_5$$9, start); ZEPHIR_RETURN_CALL_FUNCTION("array_slice", NULL, 374, value, &_5$$9, length); zephir_check_call_status(); RETURN_MM(); } if ((zephir_function_exists_ex(SS("mb_substr") TSRMLS_CC) == SUCCESS)) { if (Z_TYPE_P(length) != IS_NULL) { ZEPHIR_SINIT_VAR(_6$$11); ZVAL_LONG(&_6$$11, start); ZEPHIR_RETURN_CALL_FUNCTION("mb_substr", &_7, 375, value, &_6$$11, length); zephir_check_call_status(); RETURN_MM(); } ZEPHIR_SINIT_VAR(_8$$10); ZVAL_LONG(&_8$$10, start); ZEPHIR_RETURN_CALL_FUNCTION("mb_substr", &_7, 375, value, &_8$$10); zephir_check_call_status(); RETURN_MM(); } if (Z_TYPE_P(length) != IS_NULL) { ZEPHIR_SINIT_VAR(_9$$12); ZVAL_LONG(&_9$$12, start); zephir_substr(return_value, value, zephir_get_intval(&_9$$12), zephir_get_intval(length), 0); RETURN_MM(); } ZEPHIR_SINIT_VAR(_10); ZVAL_LONG(&_10, start); zephir_substr(return_value, value, zephir_get_intval(&_10), 0, ZEPHIR_SUBSTR_NO_LENGTH); RETURN_MM(); }
/** * Builds a HTML TEXTAREA tag * * @param array $parameters * @return string */ PHP_METHOD(Phalcon_Tag, textArea){ zval *parameters = NULL, *params = NULL, *id = NULL, *content = NULL, *code = NULL, *avalue = NULL; zval *key = NULL, *attribute = NULL; zval *r0 = NULL, *r1 = NULL, *r2 = NULL; HashTable *ah0; HashPosition hp0; zval **hd; char *hash_index; uint hash_index_len; ulong hash_num; int hash_type; int eval_int; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", ¶meters) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } if (Z_TYPE_P(parameters) != IS_ARRAY) { PHALCON_INIT_VAR(params); array_init(params); phalcon_array_append(¶ms, parameters, PH_SEPARATE TSRMLS_CC); } else { PHALCON_CPY_WRT(params, parameters); } eval_int = phalcon_array_isset_long(params, 0); if (!eval_int) { PHALCON_ALLOC_ZVAL_MM(r0); phalcon_array_fetch_string(&r0, params, SL("id"), PH_NOISY_CC); phalcon_array_update_long(¶ms, 0, &r0, PH_COPY | PH_SEPARATE TSRMLS_CC); } PHALCON_INIT_VAR(id); phalcon_array_fetch_long(&id, params, 0, PH_NOISY_CC); eval_int = phalcon_array_isset_string(params, SL("name")+1); if (!eval_int) { phalcon_array_update_string(¶ms, SL("name"), &id, PH_COPY | PH_SEPARATE TSRMLS_CC); } else { PHALCON_ALLOC_ZVAL_MM(r1); phalcon_array_fetch_string(&r1, params, SL("name"), PH_NOISY_CC); if (!zend_is_true(r1)) { phalcon_array_update_string(¶ms, SL("name"), &id, PH_COPY | PH_SEPARATE TSRMLS_CC); } } eval_int = phalcon_array_isset_string(params, SL("id")+1); if (!eval_int) { phalcon_array_update_string(¶ms, SL("id"), &id, PH_COPY | PH_SEPARATE TSRMLS_CC); } eval_int = phalcon_array_isset_string(params, SL("value")+1); if (eval_int) { PHALCON_INIT_VAR(content); phalcon_array_fetch_string(&content, params, SL("value"), PH_NOISY_CC); PHALCON_SEPARATE(params); phalcon_array_unset_string(params, SL("value")+1); } else { PHALCON_INIT_VAR(content); PHALCON_CALL_SELF_PARAMS_1(content, this_ptr, "getvalue", id); } PHALCON_INIT_VAR(code); ZVAL_STRING(code, "<textarea ", 1); if (!phalcon_valid_foreach(params TSRMLS_CC)) { return; } ah0 = Z_ARRVAL_P(params); zend_hash_internal_pointer_reset_ex(ah0, &hp0); fes_9b93_4: if(zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) != SUCCESS){ goto fee_9b93_4; } PHALCON_INIT_VAR(key); PHALCON_GET_FOREACH_KEY(key, ah0, hp0); PHALCON_INIT_VAR(avalue); ZVAL_ZVAL(avalue, *hd, 1, 0); if (Z_TYPE_P(key) != IS_LONG) { PHALCON_INIT_VAR(attribute); PHALCON_CONCAT_VSVS(attribute, key, "=\"", avalue, "\" "); phalcon_concat_self(&code, attribute TSRMLS_CC); } zend_hash_move_forward_ex(ah0, &hp0); goto fes_9b93_4; fee_9b93_4: PHALCON_ALLOC_ZVAL_MM(r2); PHALCON_CONCAT_SVS(r2, ">", content, "</textarea>"); phalcon_concat_self(&code, r2 TSRMLS_CC); RETURN_CTOR(code); }
/** * Initialize the metadata for certain table */ PHP_METHOD(Phalcon_Mvc_Model_MetaData, _initialize) { zend_long ZEPHIR_LAST_CALL_STATUS; zval *model, *key, *table, *schema, *strategy = NULL, *className = NULL, *metaData = NULL, *data = NULL, *modelMetadata = NULL, *modelColumnMap = NULL, *dependencyInjector = NULL, *keyName = NULL, *prefixKey = NULL, *_2, *_0$$8, *_1$$8; ZEPHIR_MM_GROW(); zephir_fetch_params(1, 4, 0, &model, &key, &table, &schema); ZEPHIR_INIT_VAR(strategy); ZVAL_NULL(strategy); ZEPHIR_INIT_VAR(className); zephir_get_class(className, model, 0 TSRMLS_CC); if (Z_TYPE_P(key) != IS_NULL) { ZEPHIR_OBS_VAR(metaData); zephir_read_property_this(&metaData, this_ptr, SL("_metaData"), PH_NOISY_CC); if (!(zephir_array_isset(metaData, key))) { ZEPHIR_INIT_VAR(prefixKey); ZEPHIR_CONCAT_SV(prefixKey, "meta-", key); ZEPHIR_CALL_METHOD(&data, this_ptr, "read", NULL, 0, prefixKey); zephir_check_call_status(); if (Z_TYPE_P(data) != IS_NULL) { zephir_update_property_array(this_ptr, SL("_metaData"), key, data TSRMLS_CC); } else { if ((zephir_method_exists_ex(model, SS("metadata") TSRMLS_CC) == SUCCESS)) { ZEPHIR_CALL_METHOD(&modelMetadata, model, "metadata", NULL, 0); zephir_check_call_status(); if (Z_TYPE_P(modelMetadata) != IS_ARRAY) { ZEPHIR_INIT_VAR(_0$$8); object_init_ex(_0$$8, phalcon_mvc_model_exception_ce); ZEPHIR_INIT_VAR(_1$$8); ZEPHIR_CONCAT_SV(_1$$8, "Invalid meta-data for model ", className); ZEPHIR_CALL_METHOD(NULL, _0$$8, "__construct", NULL, 9, _1$$8); zephir_check_call_status(); zephir_throw_exception_debug(_0$$8, "phalcon/mvc/model/metadata.zep", 122 TSRMLS_CC); ZEPHIR_MM_RESTORE(); return; } } else { ZEPHIR_OBS_VAR(dependencyInjector); zephir_read_property_this(&dependencyInjector, this_ptr, SL("_dependencyInjector"), PH_NOISY_CC); ZEPHIR_CALL_METHOD(&strategy, this_ptr, "getstrategy", NULL, 0); zephir_check_call_status(); ZEPHIR_CALL_METHOD(&modelMetadata, strategy, "getmetadata", NULL, 0, model, dependencyInjector); zephir_check_call_status(); } zephir_update_property_array(this_ptr, SL("_metaData"), key, modelMetadata TSRMLS_CC); ZEPHIR_CALL_METHOD(NULL, this_ptr, "write", NULL, 0, prefixKey, modelMetadata); zephir_check_call_status(); } } } if (!(ZEPHIR_GLOBAL(orm).column_renaming)) { RETURN_MM_NULL(); } ZEPHIR_INIT_VAR(keyName); zephir_fast_strtolower(keyName, className); _2 = zephir_fetch_nproperty_this(this_ptr, SL("_columnMap"), PH_NOISY_CC); if (zephir_array_isset(_2, keyName)) { RETURN_MM_NULL(); } ZEPHIR_INIT_NVAR(prefixKey); ZEPHIR_CONCAT_SV(prefixKey, "map-", keyName); ZEPHIR_CALL_METHOD(&data, this_ptr, "read", NULL, 0, prefixKey); zephir_check_call_status(); if (Z_TYPE_P(data) != IS_NULL) { zephir_update_property_array(this_ptr, SL("_columnMap"), keyName, data TSRMLS_CC); RETURN_MM_NULL(); } if (Z_TYPE_P(strategy) != IS_OBJECT) { ZEPHIR_OBS_NVAR(dependencyInjector); zephir_read_property_this(&dependencyInjector, this_ptr, SL("_dependencyInjector"), PH_NOISY_CC); ZEPHIR_CALL_METHOD(&strategy, this_ptr, "getstrategy", NULL, 0); zephir_check_call_status(); } ZEPHIR_CALL_METHOD(&modelColumnMap, strategy, "getcolumnmaps", NULL, 0, model, dependencyInjector); zephir_check_call_status(); zephir_update_property_array(this_ptr, SL("_columnMap"), keyName, modelColumnMap TSRMLS_CC); ZEPHIR_CALL_METHOD(NULL, this_ptr, "write", NULL, 0, prefixKey, modelColumnMap); zephir_check_call_status(); ZEPHIR_MM_RESTORE(); }
/* {{{ proto void run() */ PHP_METHOD(slightphp, run) { zval *zone=NULL; zval *page=NULL; zval *entry=NULL; zval path_array; //{{{ int isPart; zval *path; if (ZEND_NUM_ARGS()>0 && zend_parse_parameters(ZEND_NUM_ARGS() , "z/", &path) != FAILURE) { if (Z_TYPE_P(path)!= IS_STRING){ RETURN_FALSE; } isPart = 1; }else{ isPart = 0; zend_is_auto_global_str(ZEND_STRL("_SERVER")); zval *server_vars; if ((server_vars = zend_hash_str_find(&EG(symbol_table), ZEND_STRL("_SERVER"))) != NULL && Z_TYPE_P(server_vars) == IS_ARRAY){ if((path= zend_hash_str_find(Z_ARRVAL_P(server_vars), ZEND_STRL("PATH_INFO")))!=NULL && Z_TYPE_P(path) == IS_STRING) { // }else if((path= zend_hash_str_find(Z_ARRVAL_P(server_vars), ZEND_STRL("REQUEST_URI")))!=NULL && Z_TYPE_P(path) == IS_STRING) { // }else{ debug("path not set in params or server.path_info, server.request_uri"); RETURN_FALSE; } } } /* Skip leading / */ int len = Z_STRLEN_P(path); int start=0; for(start=0;start<len;start++){ if(*(Z_STRVAL_P(path)+start) != '/'){ break; } } zval url; php_url *resource=NULL; resource = php_url_parse(Z_STRVAL_P(path)+start); if(resource != NULL){ if(resource->path != NULL){ ZVAL_STRING(&url,resource->path); }else{ ZVAL_STRING(&url,Z_STRVAL_P(path)); } php_url_free(resource); }else{ ZVAL_STRING(&url,Z_STRVAL_P(path)); } zend_update_static_property(slightphp_ce_ptr,"pathInfo",sizeof("pathInfo")-1,&url TSRMLS_CC); //zend_print_flat_zval_r(path); //}}} array_init(&path_array); { //{{{ zval quotedFlag; regex_t re; char *regex; regmatch_t subs[1]; int err,size; char *strp = Z_STRVAL(url); char *endp = strp + Z_STRLEN(url); zval *splitFlag = zend_read_static_property(slightphp_ce_ptr,"splitFlag",sizeof("splitFlag")-1,1 ); if(preg_quote(splitFlag,"edFlag)>0){ spprintf(®ex,0,"[%s\\/]",Z_STRVAL(quotedFlag)); }else{ spprintf(®ex,0,"[\\/]"); } err = regcomp(&re, regex, REG_ICASE); if (err) { }else{ while (!(err = regexec(&re, strp, 1, subs, 0))) { if (subs[0].rm_so == 0 && subs[0].rm_eo) { //ignore empty string strp += subs[0].rm_eo; }else if (subs[0].rm_so == 0 && subs[0].rm_eo == 0) { }else{ size = subs[0].rm_so; add_next_index_stringl(&path_array, strp, size); strp += size; } } if (!err || err == REG_NOMATCH) { size = endp - strp; if(size>0) add_next_index_stringl(&path_array, strp, size); } regfree(&re); } efree(regex); zval_dtor("edFlag); //}}} if((zone = zend_hash_index_find(Z_ARRVAL(path_array), 0)) != NULL ) { } if((page = zend_hash_index_find(Z_ARRVAL(path_array), 1)) != NULL ) { } if((entry = zend_hash_index_find(Z_ARRVAL(path_array), 2)) != NULL) { } } if(!zone){ zone = zend_read_static_property(slightphp_ce_ptr,"defaultZone",sizeof("defaultZone")-1,1 ); add_next_index_string(&path_array, Z_STRVAL_P(zone)); } if(!page){ page = zend_read_static_property(slightphp_ce_ptr,"defaultPage",sizeof("defaultPage")-1,1 ); add_next_index_string(&path_array, Z_STRVAL_P(page)); } if(!entry){ entry = zend_read_static_property(slightphp_ce_ptr,"defaultEntry",sizeof("defaultEntry")-1,1 ); add_next_index_string(&path_array, Z_STRVAL_P(entry)); } //{{{ zval *zoneAlias = zend_read_static_property(slightphp_ce_ptr,"zoneAlias",sizeof("zoneAlias")-1,1 ); if(zoneAlias && Z_TYPE_P(zoneAlias)==IS_ARRAY){ zend_ulong num_key; zend_string *string_key= NULL; HashPosition pos; zval *entry2=NULL; zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(zoneAlias), &pos); for (;; zend_hash_move_forward_ex(Z_ARRVAL_P(zoneAlias), &pos)) { if (NULL == (entry2= zend_hash_get_current_data_ex(Z_ARRVAL_P(zoneAlias), &pos))) { break; } if(strcmp(Z_STRVAL_P(entry2) ,Z_STRVAL_P(zone))==0){ switch (pos = zend_hash_get_current_key_ex(Z_ARRVAL_P(zoneAlias), &string_key, &num_key,&pos)) { case HASH_KEY_IS_STRING: ZVAL_STR_COPY(zone,string_key); break; } } } } //}}} if(!isPart){ zend_update_static_property(slightphp_ce_ptr,"zone",sizeof("zone")-1,zone ); zend_update_static_property(slightphp_ce_ptr,"page",sizeof("page")-1,page ); zend_update_static_property(slightphp_ce_ptr,"entry",sizeof("entry")-1,entry ); }else{ if( strcmp(Z_STRVAL_P(zone),Z_STRVAL_P(zend_read_static_property(slightphp_ce_ptr,"zone",sizeof("zone")-1,1 )))==0 && strcmp(Z_STRVAL_P(page),Z_STRVAL_P(zend_read_static_property(slightphp_ce_ptr,"page",sizeof("page")-1,1 )))==0 && strcmp(Z_STRVAL_P(entry),Z_STRVAL_P(zend_read_static_property(slightphp_ce_ptr,"entry",sizeof("entry")-1,1 )))==0 ){ debug("part ignored [%s]",Z_STRVAL(url)); zval_dtor(&path_array); zval_dtor(&url); return; } } zval *appDir = zend_read_static_property(slightphp_ce_ptr,"appDir",sizeof("appDir")-1,1 ); if(slightphp_load(appDir,zone,page ) == SUCCESS){ zval ret; if(slightphp_run(zone,page,entry,&ret,1,&path_array)==SUCCESS){ zval_dtor(&path_array); zval_dtor(&url); RETURN_ZVAL(&ret,0,1); }; } zval_dtor(&url); zval_dtor(&path_array); RETURN_FALSE; }
/** * Builds a HTML A tag using framework conventions * * @param array $parameters * @return string */ PHP_METHOD(Phalcon_Tag, linkTo){ zval *parameters = NULL, *text = NULL, *params = NULL, *action = NULL, *url = NULL, *internal_url = NULL; zval *code = NULL, *value = NULL, *key = NULL, *attribute = NULL; zval *r0 = NULL; HashTable *ah0; HashPosition hp0; zval **hd; char *hash_index; uint hash_index_len; ulong hash_num; int hash_type; int eval_int; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|z", ¶meters, &text) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } if (!text) { PHALCON_ALLOC_ZVAL_MM(text); ZVAL_NULL(text); } else { PHALCON_SEPARATE_PARAM(text); } if (Z_TYPE_P(parameters) != IS_ARRAY) { PHALCON_INIT_VAR(params); array_init(params); phalcon_array_append(¶ms, parameters, PH_SEPARATE TSRMLS_CC); phalcon_array_append(¶ms, text, PH_SEPARATE TSRMLS_CC); } else { PHALCON_CPY_WRT(params, parameters); } PHALCON_INIT_VAR(action); ZVAL_STRING(action, "", 1); eval_int = phalcon_array_isset_long(params, 0); if (eval_int) { PHALCON_INIT_VAR(action); phalcon_array_fetch_long(&action, params, 0, PH_NOISY_CC); } else { eval_int = phalcon_array_isset_string(params, SL("action")+1); if (eval_int) { PHALCON_INIT_VAR(action); phalcon_array_fetch_string(&action, params, SL("action"), PH_NOISY_CC); PHALCON_SEPARATE(params); phalcon_array_unset_string(params, SL("action")+1); } } PHALCON_INIT_VAR(text); ZVAL_STRING(text, "", 1); eval_int = phalcon_array_isset_long(params, 1); if (eval_int) { PHALCON_INIT_VAR(text); phalcon_array_fetch_long(&text, params, 1, PH_NOISY_CC); } else { eval_int = phalcon_array_isset_string(params, SL("text")+1); if (eval_int) { PHALCON_INIT_VAR(text); phalcon_array_fetch_string(&text, params, SL("text"), PH_NOISY_CC); PHALCON_SEPARATE(params); phalcon_array_unset_string(params, SL("text")+1); } } PHALCON_INIT_VAR(url); PHALCON_CALL_SELF(url, this_ptr, "geturlservice"); PHALCON_INIT_VAR(internal_url); PHALCON_CALL_METHOD_PARAMS_1(internal_url, url, "get", action, PH_NO_CHECK); PHALCON_INIT_VAR(code); PHALCON_CONCAT_SVS(code, "<a href=\"", internal_url, "\""); if (!phalcon_valid_foreach(params TSRMLS_CC)) { return; } ah0 = Z_ARRVAL_P(params); zend_hash_internal_pointer_reset_ex(ah0, &hp0); fes_9b93_1: if(zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) != SUCCESS){ goto fee_9b93_1; } PHALCON_INIT_VAR(key); PHALCON_GET_FOREACH_KEY(key, ah0, hp0); PHALCON_INIT_VAR(value); ZVAL_ZVAL(value, *hd, 1, 0); if (Z_TYPE_P(key) != IS_LONG) { PHALCON_INIT_VAR(attribute); PHALCON_CONCAT_SVSVS(attribute, " ", key, "=\"", value, "\""); phalcon_concat_self(&code, attribute TSRMLS_CC); } zend_hash_move_forward_ex(ah0, &hp0); goto fes_9b93_1; fee_9b93_1: PHALCON_ALLOC_ZVAL_MM(r0); PHALCON_CONCAT_SVS(r0, ">", text, "</a>"); phalcon_concat_self(&code, r0 TSRMLS_CC); RETURN_CTOR(code); }
/* {{{ proto MongoGridFS::__construct(MongoDB db [, string prefix = "fs"]) Creates a new MongoGridFS object */ PHP_METHOD(MongoGridFS, __construct) { zval *zdb, *files = NULL, *chunks = NULL, *zchunks; zval *z_w = NULL; /* chunks is deprecated */ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O|zz", &zdb, mongo_ce_DB, &files, &chunks) == FAILURE) { zval *object = getThis(); ZVAL_NULL(object); return; } if (chunks) { php_error_docref(NULL TSRMLS_CC, E_DEPRECATED, "The 'chunks' argument is deprecated and ignored"); } if (files) { zval *temp_file; char *temp; if (Z_TYPE_P(files) != IS_STRING || Z_STRLEN_P(files) == 0 ) { zend_throw_exception_ex(zend_exception_get_default(TSRMLS_C), 2 TSRMLS_CC, "MongoGridFS::__construct(): invalid prefix"); return; } MAKE_STD_ZVAL(chunks); spprintf(&temp, 0, "%s.chunks", Z_STRVAL_P(files)); ZVAL_STRING(chunks, temp, 0); MAKE_STD_ZVAL(temp_file); spprintf(&temp, 0, "%s.files", Z_STRVAL_P(files)); ZVAL_STRING(temp_file, temp, 0); files = temp_file; } else { MAKE_STD_ZVAL(files); ZVAL_STRING(files, "fs.files", 1); MAKE_STD_ZVAL(chunks); ZVAL_STRING(chunks, "fs.chunks", 1); } /* create files collection */ MONGO_METHOD2(MongoCollection, __construct, return_value, getThis(), zdb, files); /* create chunks collection */ MAKE_STD_ZVAL(zchunks); object_init_ex(zchunks, mongo_ce_Collection); MONGO_METHOD2(MongoCollection, __construct, return_value, zchunks, zdb, chunks); /* add chunks collection as a property */ zend_update_property(mongo_ce_GridFS, getThis(), "chunks", strlen("chunks"), zchunks TSRMLS_CC); zend_update_property(mongo_ce_GridFS, getThis(), "filesName", strlen("filesName"), files TSRMLS_CC); zend_update_property(mongo_ce_GridFS, getThis(), "chunksName", strlen("chunksName"), chunks TSRMLS_CC); /* GridFS is forced in our codebase to be w=1 so this property doesn't actually mean * anything, but we can't lie to the user so we have to overwrite it if the MongoDB * object that created this object was w=0. * This property is initialized in the MongoCollection (which we extend) ctor */ z_w = zend_read_property(mongo_ce_GridFS, getThis(), "w", strlen("w"), NOISY TSRMLS_CC); if (Z_TYPE_P(z_w) != IS_STRING) { convert_to_long(z_w); if (Z_LVAL_P(z_w) < 2) { zend_update_property_long(mongo_ce_GridFS, getThis(), "w", strlen("w"), 1 TSRMLS_CC); } } /* cleanup */ zval_ptr_dtor(&zchunks); zval_ptr_dtor(&files); zval_ptr_dtor(&chunks); }
void zend_optimizer_compact_literals(zend_op_array *op_array, zend_optimizer_ctx *ctx) { zend_op *opline, *end; int i, j, n, *map, cache_size; zval zv, *pos; literal_info *info; int l_null = -1; int l_false = -1; int l_true = -1; int l_empty_arr = -1; HashTable hash; zend_string *key = NULL; void *checkpoint = zend_arena_checkpoint(ctx->arena); int *const_slot, *class_slot, *func_slot, *bind_var_slot, *property_slot, *method_slot; if (op_array->last_literal) { info = (literal_info*)zend_arena_calloc(&ctx->arena, op_array->last_literal, sizeof(literal_info)); /* Mark literals of specific types */ opline = op_array->opcodes; end = opline + op_array->last; while (opline < end) { switch (opline->opcode) { case ZEND_INIT_FCALL: LITERAL_INFO(opline->op2.constant, LITERAL_FUNC, 1); break; case ZEND_INIT_FCALL_BY_NAME: LITERAL_INFO(opline->op2.constant, LITERAL_FUNC, 2); break; case ZEND_INIT_NS_FCALL_BY_NAME: LITERAL_INFO(opline->op2.constant, LITERAL_FUNC, 3); break; case ZEND_INIT_METHOD_CALL: if (opline->op1_type == IS_CONST) { LITERAL_INFO(opline->op1.constant, LITERAL_VALUE, 1); } if (opline->op2_type == IS_CONST) { LITERAL_INFO(opline->op2.constant, LITERAL_METHOD, 2); } break; case ZEND_INIT_STATIC_METHOD_CALL: if (opline->op1_type == IS_CONST) { LITERAL_INFO(opline->op1.constant, LITERAL_CLASS, 2); } if (opline->op2_type == IS_CONST) { LITERAL_INFO(opline->op2.constant, LITERAL_STATIC_METHOD, 2); } break; case ZEND_CATCH: LITERAL_INFO(opline->op1.constant, LITERAL_CLASS, 2); break; case ZEND_DEFINED: LITERAL_INFO(opline->op1.constant, LITERAL_CONST, 2); break; case ZEND_FETCH_CONSTANT: if ((opline->op1.num & (IS_CONSTANT_IN_NAMESPACE|IS_CONSTANT_UNQUALIFIED)) == (IS_CONSTANT_IN_NAMESPACE|IS_CONSTANT_UNQUALIFIED)) { LITERAL_INFO(opline->op2.constant, LITERAL_CONST, 5); } else { LITERAL_INFO(opline->op2.constant, LITERAL_CONST, 3); } break; case ZEND_FETCH_CLASS_CONSTANT: if (opline->op1_type == IS_CONST) { LITERAL_INFO(opline->op1.constant, LITERAL_CLASS, 2); } LITERAL_INFO(opline->op2.constant, LITERAL_CLASS_CONST, 1); break; case ZEND_FETCH_STATIC_PROP_R: case ZEND_FETCH_STATIC_PROP_W: case ZEND_FETCH_STATIC_PROP_RW: case ZEND_FETCH_STATIC_PROP_IS: case ZEND_FETCH_STATIC_PROP_UNSET: case ZEND_FETCH_STATIC_PROP_FUNC_ARG: case ZEND_UNSET_STATIC_PROP: case ZEND_ISSET_ISEMPTY_STATIC_PROP: if (opline->op2_type == IS_CONST) { LITERAL_INFO(opline->op2.constant, LITERAL_CLASS, 2); } if (opline->op1_type == IS_CONST) { LITERAL_INFO(opline->op1.constant, LITERAL_STATIC_PROPERTY, 1); } break; case ZEND_FETCH_CLASS: case ZEND_ADD_INTERFACE: case ZEND_ADD_TRAIT: case ZEND_INSTANCEOF: if (opline->op2_type == IS_CONST) { LITERAL_INFO(opline->op2.constant, LITERAL_CLASS, 2); } break; case ZEND_NEW: if (opline->op1_type == IS_CONST) { LITERAL_INFO(opline->op1.constant, LITERAL_CLASS, 2); } break; case ZEND_ASSIGN_OBJ: case ZEND_FETCH_OBJ_R: case ZEND_FETCH_OBJ_W: case ZEND_FETCH_OBJ_RW: case ZEND_FETCH_OBJ_IS: case ZEND_FETCH_OBJ_UNSET: case ZEND_FETCH_OBJ_FUNC_ARG: case ZEND_UNSET_OBJ: case ZEND_PRE_INC_OBJ: case ZEND_PRE_DEC_OBJ: case ZEND_POST_INC_OBJ: case ZEND_POST_DEC_OBJ: case ZEND_ISSET_ISEMPTY_PROP_OBJ: if (opline->op2_type == IS_CONST) { LITERAL_INFO(opline->op2.constant, LITERAL_PROPERTY, 1); } break; case ZEND_ASSIGN_ADD: case ZEND_ASSIGN_SUB: case ZEND_ASSIGN_MUL: case ZEND_ASSIGN_DIV: case ZEND_ASSIGN_POW: case ZEND_ASSIGN_MOD: case ZEND_ASSIGN_SL: case ZEND_ASSIGN_SR: case ZEND_ASSIGN_CONCAT: case ZEND_ASSIGN_BW_OR: case ZEND_ASSIGN_BW_AND: case ZEND_ASSIGN_BW_XOR: if (opline->op2_type == IS_CONST) { if (opline->extended_value == ZEND_ASSIGN_OBJ) { LITERAL_INFO(opline->op2.constant, LITERAL_PROPERTY, 1); } else { LITERAL_INFO(opline->op2.constant, LITERAL_VALUE, 1); } } break; case ZEND_BIND_GLOBAL: LITERAL_INFO(opline->op2.constant, LITERAL_GLOBAL, 1); break; case ZEND_RECV_INIT: LITERAL_INFO(opline->op2.constant, LITERAL_VALUE, 1); break; case ZEND_DECLARE_FUNCTION: case ZEND_DECLARE_CLASS: case ZEND_DECLARE_INHERITED_CLASS: case ZEND_DECLARE_INHERITED_CLASS_DELAYED: LITERAL_INFO(opline->op1.constant, LITERAL_VALUE, 2); break; default: if (opline->op1_type == IS_CONST) { LITERAL_INFO(opline->op1.constant, LITERAL_VALUE, 1); } if (opline->op2_type == IS_CONST) { LITERAL_INFO(opline->op2.constant, LITERAL_VALUE, 1); } break; } opline++; } #if DEBUG_COMPACT_LITERALS { int i, use_copy; fprintf(stderr, "File %s func %s\n", op_array->filename->val, op_array->function_name ? op_array->function_name->val : "main"); fprintf(stderr, "Literlas table size %d\n", op_array->last_literal); for (i = 0; i < op_array->last_literal; i++) { zval zv; ZVAL_COPY_VALUE(&zv, op_array->literals + i); use_copy = zend_make_printable_zval(op_array->literals + i, &zv); fprintf(stderr, "Literal %d, val (%d):%s\n", i, Z_STRLEN(zv), Z_STRVAL(zv)); if (use_copy) { zval_ptr_dtor_nogc(&zv); } } fflush(stderr); } #endif /* Merge equal constants */ j = 0; zend_hash_init(&hash, op_array->last_literal, NULL, NULL, 0); map = (int*)zend_arena_alloc(&ctx->arena, op_array->last_literal * sizeof(int)); memset(map, 0, op_array->last_literal * sizeof(int)); for (i = 0; i < op_array->last_literal; i++) { if (!info[i].flags) { /* unsed literal */ zval_ptr_dtor_nogc(&op_array->literals[i]); continue; } switch (Z_TYPE(op_array->literals[i])) { case IS_NULL: if (l_null < 0) { l_null = j; if (i != j) { op_array->literals[j] = op_array->literals[i]; info[j] = info[i]; } j++; } map[i] = l_null; break; case IS_FALSE: if (l_false < 0) { l_false = j; if (i != j) { op_array->literals[j] = op_array->literals[i]; info[j] = info[i]; } j++; } map[i] = l_false; break; case IS_TRUE: if (l_true < 0) { l_true = j; if (i != j) { op_array->literals[j] = op_array->literals[i]; info[j] = info[i]; } j++; } map[i] = l_true; break; case IS_LONG: if ((pos = zend_hash_index_find(&hash, Z_LVAL(op_array->literals[i]))) != NULL) { map[i] = Z_LVAL_P(pos); } else { map[i] = j; ZVAL_LONG(&zv, j); zend_hash_index_add_new(&hash, Z_LVAL(op_array->literals[i]), &zv); if (i != j) { op_array->literals[j] = op_array->literals[i]; info[j] = info[i]; } j++; } break; case IS_DOUBLE: if ((pos = zend_hash_str_find(&hash, (char*)&Z_DVAL(op_array->literals[i]), sizeof(double))) != NULL) { map[i] = Z_LVAL_P(pos); } else { map[i] = j; ZVAL_LONG(&zv, j); zend_hash_str_add(&hash, (char*)&Z_DVAL(op_array->literals[i]), sizeof(double), &zv); if (i != j) { op_array->literals[j] = op_array->literals[i]; info[j] = info[i]; } j++; } break; case IS_STRING: if (LITERAL_NUM_RELATED(info[i].flags) == 1) { key = zend_string_copy(Z_STR(op_array->literals[i])); } else { key = zend_string_init(Z_STRVAL(op_array->literals[i]), Z_STRLEN(op_array->literals[i]), 0); ZSTR_H(key) = ZSTR_HASH(Z_STR(op_array->literals[i])) + LITERAL_NUM_RELATED(info[i].flags) - 1; } pos = zend_hash_find(&hash, key); if (pos != NULL && Z_TYPE(op_array->literals[Z_LVAL_P(pos)]) == IS_STRING && LITERAL_NUM_RELATED(info[i].flags) == LITERAL_NUM_RELATED(info[Z_LVAL_P(pos)].flags) && (LITERAL_NUM_RELATED(info[i].flags) != 2 || ((info[i].flags & LITERAL_KIND_MASK) != LITERAL_VALUE && (info[Z_LVAL_P(pos)].flags & LITERAL_KIND_MASK) != LITERAL_VALUE))) { zend_string_release_ex(key, 0); map[i] = Z_LVAL_P(pos); zval_ptr_dtor_nogc(&op_array->literals[i]); n = LITERAL_NUM_RELATED(info[i].flags); while (n > 1) { i++; zval_ptr_dtor_nogc(&op_array->literals[i]); n--; } } else { map[i] = j; ZVAL_LONG(&zv, j); zend_hash_add_new(&hash, key, &zv); zend_string_release_ex(key, 0); if (i != j) { op_array->literals[j] = op_array->literals[i]; info[j] = info[i]; } j++; n = LITERAL_NUM_RELATED(info[i].flags); while (n > 1) { i++; if (i != j) op_array->literals[j] = op_array->literals[i]; j++; n--; } } break; case IS_ARRAY: if (zend_hash_num_elements(Z_ARRVAL(op_array->literals[i])) == 0) { if (l_empty_arr < 0) { l_empty_arr = j; if (i != j) { op_array->literals[j] = op_array->literals[i]; info[j] = info[i]; } j++; } else { zval_ptr_dtor_nogc(&op_array->literals[i]); } map[i] = l_empty_arr; break; } /* break missing intentionally */ default: /* don't merge other types */ map[i] = j; if (i != j) { op_array->literals[j] = op_array->literals[i]; info[j] = info[i]; } j++; break; } } zend_hash_clean(&hash); op_array->last_literal = j; const_slot = zend_arena_alloc(&ctx->arena, j * 6 * sizeof(int)); memset(const_slot, -1, j * 6 * sizeof(int)); class_slot = const_slot + j; func_slot = class_slot + j; bind_var_slot = func_slot + j; property_slot = bind_var_slot + j; method_slot = property_slot + j; /* Update opcodes to use new literals table */ cache_size = 0; opline = op_array->opcodes; end = opline + op_array->last; while (opline < end) { if (opline->op1_type == IS_CONST) { opline->op1.constant = map[opline->op1.constant]; } if (opline->op2_type == IS_CONST) { opline->op2.constant = map[opline->op2.constant]; } switch (opline->opcode) { case ZEND_RECV_INIT: if (class_name_type_hint(op_array, opline->op1.num)) { opline->extended_value = cache_size; cache_size += sizeof(void *); } break; case ZEND_RECV: case ZEND_RECV_VARIADIC: if (class_name_type_hint(op_array, opline->op1.num)) { opline->op2.num = cache_size; cache_size += sizeof(void *); } break; case ZEND_VERIFY_RETURN_TYPE: if (class_name_type_hint(op_array, 0)) { opline->op2.num = cache_size; cache_size += sizeof(void *); } break; case ZEND_ASSIGN_ADD: case ZEND_ASSIGN_SUB: case ZEND_ASSIGN_MUL: case ZEND_ASSIGN_DIV: case ZEND_ASSIGN_POW: case ZEND_ASSIGN_MOD: case ZEND_ASSIGN_SL: case ZEND_ASSIGN_SR: case ZEND_ASSIGN_CONCAT: case ZEND_ASSIGN_BW_OR: case ZEND_ASSIGN_BW_AND: case ZEND_ASSIGN_BW_XOR: if (opline->extended_value != ZEND_ASSIGN_OBJ) { break; } if (opline->op2_type == IS_CONST) { // op2 property if (opline->op1_type == IS_UNUSED && property_slot[opline->op2.constant] >= 0) { (opline+1)->extended_value = property_slot[opline->op2.constant]; } else { (opline+1)->extended_value = cache_size; cache_size += 2 * sizeof(void *); if (opline->op1_type == IS_UNUSED) { property_slot[opline->op2.constant] = (opline+1)->extended_value; } } } break; case ZEND_ASSIGN_OBJ: case ZEND_FETCH_OBJ_R: case ZEND_FETCH_OBJ_W: case ZEND_FETCH_OBJ_RW: case ZEND_FETCH_OBJ_IS: case ZEND_FETCH_OBJ_UNSET: case ZEND_FETCH_OBJ_FUNC_ARG: case ZEND_UNSET_OBJ: case ZEND_PRE_INC_OBJ: case ZEND_PRE_DEC_OBJ: case ZEND_POST_INC_OBJ: case ZEND_POST_DEC_OBJ: if (opline->op2_type == IS_CONST) { // op2 property if (opline->op1_type == IS_UNUSED && property_slot[opline->op2.constant] >= 0) { opline->extended_value = property_slot[opline->op2.constant]; } else { opline->extended_value = cache_size; cache_size += 2 * sizeof(void *); if (opline->op1_type == IS_UNUSED) { property_slot[opline->op2.constant] = opline->extended_value; } } } break; case ZEND_ISSET_ISEMPTY_PROP_OBJ: if (opline->op2_type == IS_CONST) { // op2 property if (opline->op1_type == IS_UNUSED && property_slot[opline->op2.constant] >= 0) { opline->extended_value = property_slot[opline->op2.constant] | (opline->extended_value & ZEND_ISSET); } else { opline->extended_value = cache_size | (opline->extended_value & ZEND_ISSET); cache_size += 2 * sizeof(void *); if (opline->op1_type == IS_UNUSED) { property_slot[opline->op2.constant] = opline->extended_value & ~ZEND_ISSET; } } } break; case ZEND_INIT_FCALL: case ZEND_INIT_FCALL_BY_NAME: case ZEND_INIT_NS_FCALL_BY_NAME: // op2 func if (func_slot[opline->op2.constant] >= 0) { opline->result.num = func_slot[opline->op2.constant]; } else { opline->result.num = cache_size; cache_size += sizeof(void *); func_slot[opline->op2.constant] = opline->result.num; } break; case ZEND_INIT_METHOD_CALL: if (opline->op2_type == IS_CONST) { // op2 method if (opline->op1_type == IS_UNUSED && method_slot[opline->op2.constant] >= 0) { opline->result.num = method_slot[opline->op2.constant]; } else { opline->result.num = cache_size; cache_size += 2 * sizeof(void *); if (opline->op1_type == IS_UNUSED) { method_slot[opline->op2.constant] = opline->result.num; } } } break; case ZEND_INIT_STATIC_METHOD_CALL: if (opline->op2_type == IS_CONST) { // op2 static method if (opline->op1_type == IS_CONST) { opline->result.num = add_static_slot(&hash, op_array, opline->op1.constant, opline->op2.constant, LITERAL_STATIC_METHOD, &cache_size); } else { opline->result.num = cache_size; cache_size += 2 * sizeof(void *); } } else if (opline->op1_type == IS_CONST) { // op1 class if (class_slot[opline->op1.constant] >= 0) { opline->result.num = class_slot[opline->op1.constant]; } else { opline->result.num = cache_size; cache_size += sizeof(void *); class_slot[opline->op1.constant] = opline->result.num; } } break; case ZEND_DEFINED: // op1 const if (const_slot[opline->op1.constant] >= 0) { opline->extended_value = const_slot[opline->op1.constant]; } else { opline->extended_value = cache_size; cache_size += sizeof(void *); const_slot[opline->op1.constant] = opline->extended_value; } break; case ZEND_FETCH_CONSTANT: // op2 const if (const_slot[opline->op2.constant] >= 0) { opline->extended_value = const_slot[opline->op2.constant]; } else { opline->extended_value = cache_size; cache_size += sizeof(void *); const_slot[opline->op2.constant] = opline->extended_value; } break; case ZEND_FETCH_CLASS_CONSTANT: if (opline->op1_type == IS_CONST) { // op1/op2 class_const opline->extended_value = add_static_slot(&hash, op_array, opline->op1.constant, opline->op2.constant, LITERAL_CLASS_CONST, &cache_size); } else { opline->extended_value = cache_size; cache_size += 2 * sizeof(void *); } break; case ZEND_FETCH_STATIC_PROP_R: case ZEND_FETCH_STATIC_PROP_W: case ZEND_FETCH_STATIC_PROP_RW: case ZEND_FETCH_STATIC_PROP_IS: case ZEND_FETCH_STATIC_PROP_UNSET: case ZEND_FETCH_STATIC_PROP_FUNC_ARG: case ZEND_UNSET_STATIC_PROP: if (opline->op1_type == IS_CONST) { // op1 static property if (opline->op2_type == IS_CONST) { opline->extended_value = add_static_slot(&hash, op_array, opline->op2.constant, opline->op1.constant, LITERAL_STATIC_PROPERTY, &cache_size); } else { opline->extended_value = cache_size; cache_size += 2 * sizeof(void *); } } else if (opline->op2_type == IS_CONST) { // op2 class if (class_slot[opline->op2.constant] >= 0) { opline->extended_value = class_slot[opline->op2.constant]; } else { opline->extended_value = cache_size; cache_size += sizeof(void *); class_slot[opline->op2.constant] = opline->extended_value; } } break; case ZEND_ISSET_ISEMPTY_STATIC_PROP: if (opline->op1_type == IS_CONST) { // op1 static property if (opline->op2_type == IS_CONST) { opline->extended_value = add_static_slot(&hash, op_array, opline->op2.constant, opline->op1.constant, LITERAL_STATIC_PROPERTY, &cache_size) | (opline->extended_value & ZEND_ISSET); } else { opline->extended_value = cache_size | (opline->extended_value & ZEND_ISSET); cache_size += 2 * sizeof(void *); } } else if (opline->op2_type == IS_CONST) { // op2 class if (class_slot[opline->op2.constant] >= 0) { opline->extended_value = class_slot[opline->op2.constant] | (opline->extended_value & ZEND_ISSET); } else { opline->extended_value = cache_size | (opline->extended_value & ZEND_ISSET); cache_size += sizeof(void *); class_slot[opline->op2.constant] = opline->extended_value & ~ZEND_ISSET; } } break; case ZEND_FETCH_CLASS: case ZEND_ADD_INTERFACE: case ZEND_ADD_TRAIT: case ZEND_INSTANCEOF: if (opline->op2_type == IS_CONST) { // op2 class if (class_slot[opline->op2.constant] >= 0) { opline->extended_value = class_slot[opline->op2.constant]; } else { opline->extended_value = cache_size; cache_size += sizeof(void *); class_slot[opline->op2.constant] = opline->extended_value; } } break; case ZEND_NEW: if (opline->op1_type == IS_CONST) { // op1 class if (class_slot[opline->op1.constant] >= 0) { opline->op2.num = class_slot[opline->op1.constant]; } else { opline->op2.num = cache_size; cache_size += sizeof(void *); class_slot[opline->op1.constant] = opline->op2.num; } } break; case ZEND_CATCH: if (opline->op1_type == IS_CONST) { // op1 class if (class_slot[opline->op1.constant] >= 0) { opline->extended_value = class_slot[opline->op1.constant] | (opline->extended_value & ZEND_LAST_CATCH); } else { opline->extended_value = cache_size | (opline->extended_value & ZEND_LAST_CATCH); cache_size += sizeof(void *); class_slot[opline->op1.constant] = opline->extended_value & ~ZEND_LAST_CATCH; } } break; case ZEND_BIND_GLOBAL: // op2 bind var if (bind_var_slot[opline->op2.constant] >= 0) { opline->extended_value = bind_var_slot[opline->op2.constant]; } else { opline->extended_value = cache_size; cache_size += sizeof(void *); bind_var_slot[opline->op2.constant] = opline->extended_value; } break; } opline++; } op_array->cache_size = cache_size; zend_hash_destroy(&hash); zend_arena_release(&ctx->arena, checkpoint); if (1) { opline = op_array->opcodes; while (1) { if (opline->opcode == ZEND_RECV_INIT) { zval *val = &op_array->literals[opline->op2.constant]; if (Z_TYPE_P(val) == IS_CONSTANT_AST) { uint32_t slot = ZEND_MM_ALIGNED_SIZE_EX(op_array->cache_size, 8); Z_CACHE_SLOT_P(val) = slot; op_array->cache_size += sizeof(zval); } } else if (opline->opcode != ZEND_RECV) { break; } opline++; } } #if DEBUG_COMPACT_LITERALS { int i, use_copy; fprintf(stderr, "Optimized literlas table size %d\n", op_array->last_literal); for (i = 0; i < op_array->last_literal; i++) { zval zv; ZVAL_COPY_VALUE(&zv, op_array->literals + i); use_copy = zend_make_printable_zval(op_array->literals + i, &zv); fprintf(stderr, "Literal %d, val (%d):%s\n", i, Z_STRLEN(zv), Z_STRVAL(zv)); if (use_copy) { zval_ptr_dtor_nogc(&zv); } } fflush(stderr); } #endif } }
/** * Sends SQL statements to the database server returning the success state. * Use this method only when the SQL statement sent to the server don't return any row * * //Inserting data * $success = $connection->execute("INSERT INTO robots VALUES (1, 'Astro Boy')"); * $success = $connection->execute("INSERT INTO robots VALUES (?, ?)", array(1, 'Astro Boy')); * * @param string $sqlStatement * @param array $placeholders */ PHP_METHOD(Phalcon_Db_Adapter_Pdo, execute){ zval *sql_statement = NULL, *placeholders = NULL, *events_manager = NULL; zval *pdo = NULL, *n = NULL, *statement = NULL, *value = NULL, *success = NULL, *affected_rows = NULL; zval *error_info = NULL; zval *c0 = NULL, *c1 = NULL; zval *r0 = NULL, *r1 = NULL, *r2 = NULL, *r3 = NULL, *r4 = NULL, *r5 = NULL; zval *i0 = NULL; HashTable *ah0; HashPosition hp0; zval **hd; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|z", &sql_statement, &placeholders) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } if (!placeholders) { PHALCON_INIT_VAR(placeholders); array_init(placeholders); } PHALCON_INIT_VAR(events_manager); phalcon_read_property(&events_manager, this_ptr, SL("_eventsManager"), PH_NOISY_CC); if (zend_is_true(events_manager)) { phalcon_update_property_zval(this_ptr, SL("_sqlStatement"), sql_statement TSRMLS_CC); PHALCON_INIT_VAR(c0); ZVAL_STRING(c0, "db:beforeQuery", 1); PHALCON_ALLOC_ZVAL_MM(r0); PHALCON_CALL_METHOD_PARAMS_2(r0, events_manager, "fire", c0, this_ptr, PH_NO_CHECK); if (Z_TYPE_P(r0) == IS_BOOL && !Z_BVAL_P(r0)) { PHALCON_MM_RESTORE(); RETURN_FALSE; } } PHALCON_INIT_VAR(pdo); phalcon_read_property(&pdo, this_ptr, SL("_pdo"), PH_NOISY_CC); PHALCON_ALLOC_ZVAL_MM(r1); phalcon_fast_count(r1, placeholders TSRMLS_CC); if (zend_is_true(r1)) { PHALCON_INIT_VAR(n); ZVAL_LONG(n, 1); PHALCON_INIT_VAR(statement); PHALCON_CALL_METHOD_PARAMS_1(statement, pdo, "prepare", sql_statement, PH_NO_CHECK); if (!phalcon_valid_foreach(placeholders TSRMLS_CC)) { return; } ah0 = Z_ARRVAL_P(placeholders); zend_hash_internal_pointer_reset_ex(ah0, &hp0); fes_7f5d_1: if(zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) != SUCCESS){ goto fee_7f5d_1; } PHALCON_INIT_VAR(value); ZVAL_ZVAL(value, *hd, 1, 0); PHALCON_CALL_METHOD_PARAMS_2_NORETURN(statement, "bindparam", n, value, PH_NO_CHECK); PHALCON_SEPARATE(n); increment_function(n); zend_hash_move_forward_ex(ah0, &hp0); goto fes_7f5d_1; fee_7f5d_1: if(0){} PHALCON_INIT_VAR(success); PHALCON_CALL_METHOD(success, statement, "execute", PH_NO_CHECK); PHALCON_INIT_VAR(affected_rows); PHALCON_CALL_METHOD(affected_rows, statement, "rowcount", PH_NO_CHECK); } else { PHALCON_INIT_VAR(success); ZVAL_BOOL(success, 1); PHALCON_INIT_VAR(affected_rows); PHALCON_CALL_METHOD_PARAMS_1(affected_rows, pdo, "exec", sql_statement, PH_NO_CHECK); } if (zend_is_true(success)) { if (Z_TYPE_P(affected_rows) == IS_LONG) { phalcon_update_property_zval(this_ptr, SL("_affectedRows"), affected_rows TSRMLS_CC); if (zend_is_true(events_manager)) { PHALCON_INIT_VAR(c1); ZVAL_STRING(c1, "db:afterQuery", 1); PHALCON_ALLOC_ZVAL_MM(r2); PHALCON_CALL_METHOD_PARAMS_2(r2, events_manager, "fire", c1, this_ptr, PH_NO_CHECK); if (Z_TYPE_P(r2) == IS_BOOL && !Z_BVAL_P(r2)) { PHALCON_MM_RESTORE(); RETURN_FALSE; } } PHALCON_MM_RESTORE(); RETURN_TRUE; } } PHALCON_INIT_VAR(error_info); PHALCON_CALL_METHOD(error_info, pdo, "errorinfo", PH_NO_CHECK); PHALCON_ALLOC_ZVAL_MM(i0); object_init_ex(i0, phalcon_db_exception_ce); PHALCON_ALLOC_ZVAL_MM(r3); phalcon_array_fetch_long(&r3, error_info, 2, PH_NOISY_CC); PHALCON_ALLOC_ZVAL_MM(r4); PHALCON_CONCAT_VSV(r4, r3, " when executing ", sql_statement); PHALCON_ALLOC_ZVAL_MM(r5); phalcon_array_fetch_long(&r5, error_info, 1, PH_NOISY_CC); PHALCON_CALL_METHOD_PARAMS_2_NORETURN(i0, "__construct", r4, r5, PH_CHECK); phalcon_throw_exception(i0 TSRMLS_CC); return; }
/** * Bind params to SQL select * * @param string $sqlSelect * @param array $params */ PHP_METHOD(Phalcon_Db_Adapter_Pdo, bindParams){ zval *sql_select = NULL, *params = NULL, *select = NULL, *pdo = NULL, *bind_value = NULL; zval *index = NULL, *value = NULL; zval *r0 = NULL, *r1 = NULL, *r2 = NULL, *r3 = NULL, *r4 = NULL, *r5 = NULL; HashTable *ah0; HashPosition hp0; zval **hd; char *hash_index; uint hash_index_len; ulong hash_num; int hash_type; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz", &sql_select, ¶ms) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } PHALCON_ALLOC_ZVAL_MM(r0); phalcon_fast_count(r0, params TSRMLS_CC); if (zend_is_true(r0)) { PHALCON_CPY_WRT(select, sql_select); PHALCON_INIT_VAR(pdo); phalcon_read_property(&pdo, this_ptr, SL("_pdo"), PH_NOISY_CC); if (!phalcon_valid_foreach(params TSRMLS_CC)) { return; } ah0 = Z_ARRVAL_P(params); zend_hash_internal_pointer_reset_ex(ah0, &hp0); fes_7f5d_2: if(zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) != SUCCESS){ goto fee_7f5d_2; } PHALCON_INIT_VAR(index); PHALCON_GET_FOREACH_KEY(index, ah0, hp0); PHALCON_INIT_VAR(bind_value); ZVAL_ZVAL(bind_value, *hd, 1, 0); PHALCON_INIT_VAR(r1); PHALCON_CALL_FUNC_PARAMS_1(r1, "is_numeric", bind_value); if (zend_is_true(r1)) { PHALCON_CPY_WRT(value, bind_value); } else { PHALCON_INIT_VAR(value); PHALCON_CALL_METHOD_PARAMS_1(value, pdo, "quote", bind_value, PH_NO_CHECK); } if (Z_TYPE_P(index) == IS_LONG) { PHALCON_INIT_VAR(r2); PHALCON_CONCAT_SV(r2, "?", index); PHALCON_INIT_VAR(r3); phalcon_fast_str_replace(r3, r2, value, select TSRMLS_CC); PHALCON_CPY_WRT(select, r3); } else { if (Z_TYPE_P(index) == IS_STRING) { PHALCON_INIT_VAR(r4); PHALCON_CONCAT_SVS(r4, ":", index, ":"); PHALCON_INIT_VAR(r5); phalcon_fast_str_replace(r5, r4, value, select TSRMLS_CC); PHALCON_CPY_WRT(select, r5); } else { PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Invalid bind parameter"); return; } } zend_hash_move_forward_ex(ah0, &hp0); goto fes_7f5d_2; fee_7f5d_2: if(0){} RETURN_CCTOR(select); } RETURN_CCTOR(sql_select); }
ZEND_METHOD(afk_app, run){/*{{{*/ zval **uri; char *c=NULL, *a=NULL; zval *arr = PG(http_globals)[TRACK_VARS_GET]; //从http_globals中寻找get参数,确认Controller和action的值。 if(arr && Z_TYPE_P(arr) == IS_ARRAY){ if(zend_hash_find(HASH_OF(arr), HTTP_CONTRONLLER_PARAM, strlen(HTTP_CONTRONLLER_PARAM)+1, (void **)&uri) == SUCCESS){ c = Z_STRVAL_PP(uri); }else{ c = "index"; } if(zend_hash_find(HASH_OF(arr), HTTP_ACTION_PARAM, strlen(HTTP_ACTION_PARAM)+1, (void **)&uri) == SUCCESS){ a = Z_STRVAL_PP(uri); }else{ a = "index"; } } //寻找对应的Controller和action方法所在的文件。 char *controller_path; spprintf(&controller_path, 0, "%s/controller/%s.php", APP_DIR, c); FILE *fp; //php_printf("%s\n", controller_path); //文件存在则引入该文件。不存在则报错。 if( (fp = fopen(controller_path, "r")) != NULL){ fclose(fp); int dummy = 1; zend_file_handle file_handle; zend_op_array *op_array; file_handle.filename = controller_path; file_handle.free_filename = 0; file_handle.type = ZEND_HANDLE_FILENAME; file_handle.opened_path = NULL; file_handle.handle.fp = NULL; op_array = zend_compile_file(&file_handle, ZEND_INCLUDE TSRMLS_CC); if (op_array && file_handle.handle.stream.handle) { int dummy = 1; if (!file_handle.opened_path) { file_handle.opened_path = controller_path; } php_printf("opened_path: %s\n", file_handle.opened_path); zend_hash_add(&EG(included_files), file_handle.opened_path, strlen(file_handle.opened_path)+1, (void *)&dummy, sizeof(int), NULL); } zend_destroy_file_handle(&file_handle TSRMLS_CC); if(op_array){ php_printf("execute op_array \n"); //保存旧的环境变量 zval ** __old_return_value_pp = EG(return_value_ptr_ptr); zend_op ** __old_opline_ptr = EG(opline_ptr); zend_op_array * __old_op_array = EG(active_op_array); zend_function_state * __old_func_state = EG(function_state_ptr); //执行op_array zval *result = NULL; EG(return_value_ptr_ptr) = &result; EG(active_op_array) = op_array; zend_execute(op_array TSRMLS_CC); destroy_op_array(op_array TSRMLS_CC); efree(op_array); //恢复旧的环境变量 EG(return_value_ptr_ptr) = __old_return_value_pp; EG(opline_ptr) = __old_opline_ptr; EG(active_op_array) = __old_op_array; EG(function_state_ptr) = __old_func_state; } }else{ char *error; spprintf(&error, 0, "cann't find file %s", controller_path); zend_error(1, error); } //dispatcher 调用分发的请求。 /** *在EG(class_table)查找相应的类,然后调用它的方法。 */ zend_class_entry **class = NULL; char *class_name = emalloc(strlen(c)+strlen("Controller")+1); class_name = strcpy(class_name, c); class_name = strcat(class_name, zend_str_tolower_dup("Controller", strlen("Controller")+1)); //Notice: class name need tolower. if(zend_hash_find(EG(class_table), class_name, strlen(class_name)+1, (void *)&class) != SUCCESS){ char *error; spprintf(&error, 0, "cann't find the controller class: %s ", class_name); php_printf("%s", class_name); efree(class_name); efree(class); zend_error(1, error); } efree(class_name); zval *obj, *function_name, *retval; MAKE_STD_ZVAL(obj); MAKE_STD_ZVAL(function_name); MAKE_STD_ZVAL(retval); object_init_ex(obj, *class); //php_var_dump(&obj, 1 TSRMLS_CC); ZVAL_STRINGL(function_name, "indexaction", strlen("indexaction"), 1); call_user_function(&((*class)->function_table), &obj, function_name, retval, 0, NULL TSRMLS_CC); zval_ptr_dtor(&obj); zval_ptr_dtor(&function_name); zval_ptr_dtor(&retval); //efree(class); RETURN_BOOL(1); }/*}}}*/
/** * Sends SQL statements to the database server returning the success state. * Use this method only when the SQL statement sent to the server return rows * * //Querying data * $resultset = $connection->query("SELECT * FROM robots WHERE type='mechanical'"); * $resultset = $connection->query("SELECT * FROM robots WHERE type=?", array("mechanical")); * * @param string $sqlStatement * @return Phalcon\Db\Result\Pdo */ PHP_METHOD(Phalcon_Db_Adapter_Pdo, query){ zval *sql_statement = NULL, *events_manager = NULL, *pdo = NULL, *result = NULL; zval *error_info = NULL; zval *c0 = NULL, *c1 = NULL; zval *r0 = NULL, *r1 = NULL, *r2 = NULL, *r3 = NULL, *r4 = NULL; zval *i0 = NULL, *i1 = NULL; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &sql_statement) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } PHALCON_INIT_VAR(events_manager); phalcon_read_property(&events_manager, this_ptr, SL("_eventsManager"), PH_NOISY_CC); if (zend_is_true(events_manager)) { phalcon_update_property_zval(this_ptr, SL("_sqlStatement"), sql_statement TSRMLS_CC); PHALCON_INIT_VAR(c0); ZVAL_STRING(c0, "db:beforeQuery", 1); PHALCON_ALLOC_ZVAL_MM(r0); PHALCON_CALL_METHOD_PARAMS_2(r0, events_manager, "fire", c0, this_ptr, PH_NO_CHECK); if (Z_TYPE_P(r0) == IS_BOOL && !Z_BVAL_P(r0)) { PHALCON_MM_RESTORE(); RETURN_FALSE; } } PHALCON_INIT_VAR(pdo); phalcon_read_property(&pdo, this_ptr, SL("_pdo"), PH_NOISY_CC); PHALCON_INIT_VAR(result); PHALCON_CALL_METHOD_PARAMS_1(result, pdo, "query", sql_statement, PH_NO_CHECK); if (Z_TYPE_P(result) == IS_OBJECT) { if (zend_is_true(events_manager)) { PHALCON_INIT_VAR(c1); ZVAL_STRING(c1, "db:afterQuery", 1); PHALCON_ALLOC_ZVAL_MM(r1); PHALCON_CALL_METHOD_PARAMS_2(r1, events_manager, "fire", c1, this_ptr, PH_NO_CHECK); if (Z_TYPE_P(r1) == IS_BOOL && !Z_BVAL_P(r1)) { PHALCON_MM_RESTORE(); RETURN_FALSE; } } PHALCON_ALLOC_ZVAL_MM(i0); object_init_ex(i0, phalcon_db_result_pdo_ce); PHALCON_CALL_METHOD_PARAMS_1_NORETURN(i0, "__construct", result, PH_CHECK); RETURN_CTOR(i0); } PHALCON_INIT_VAR(error_info); PHALCON_CALL_METHOD(error_info, pdo, "errorinfo", PH_NO_CHECK); PHALCON_ALLOC_ZVAL_MM(i1); object_init_ex(i1, phalcon_db_exception_ce); PHALCON_ALLOC_ZVAL_MM(r2); phalcon_array_fetch_long(&r2, error_info, 2, PH_NOISY_CC); PHALCON_ALLOC_ZVAL_MM(r3); PHALCON_CONCAT_VSV(r3, r2, " when executing ", sql_statement); PHALCON_ALLOC_ZVAL_MM(r4); phalcon_array_fetch_long(&r4, error_info, 1, PH_NOISY_CC); PHALCON_CALL_METHOD_PARAMS_2_NORETURN(i1, "__construct", r3, r4, PH_CHECK); phalcon_throw_exception(i1 TSRMLS_CC); return; }
static void php_couchbase_get_callback(lcb_t instance, const void *cookie, lcb_error_t error, const lcb_get_resp_t *resp) { zval *retval; php_couchbase_ctx *ctx = (php_couchbase_ctx *)cookie; const void *key; size_t nkey; const void *bytes; size_t nbytes; uint32_t flags; uint64_t cas; TSRMLS_FETCH(); if (--ctx->res->seqno == 0) { pcbc_stop_loop(ctx->res); } if (resp->version != 0) { ctx->res->rc = LCB_ERROR; return; } key = resp->v.v0.key; nkey = resp->v.v0.nkey; bytes = resp->v.v0.bytes; nbytes = resp->v.v0.nbytes; flags = resp->v.v0.flags; cas = resp->v.v0.cas; ctx->res->rc = error; if (LCB_SUCCESS != error && LCB_KEY_ENOENT != error) { pcbc_stop_loop(ctx->res); return; } if (ctx->res->async) { /* get_delayed */ zval *k, *v; MAKE_STD_ZVAL(v); if (!php_couchbase_zval_from_payload(v, (char *)bytes, nbytes, flags, ctx->res->serializer, ctx->res->ignoreflags TSRMLS_CC)) { ctx->res->rc = LCB_ERROR; efree(v); return; } if (ctx->res->prefix_key_len && nkey) { if (!strncmp(key, ctx->res->prefix_key, ctx->res->prefix_key_len)) { nkey -= (ctx->res->prefix_key_len + 1); /* '_' */ key = estrndup(((const char *)key) + ctx->res->prefix_key_len + 1, nkey); } } MAKE_STD_ZVAL(retval); array_init(retval); zend_hash_next_index_insert(Z_ARRVAL_P(ctx->rv), (void **)&retval, sizeof(zval *), NULL); MAKE_STD_ZVAL(k); ZVAL_STRINGL(k, (char *)key, nkey, 1); zend_hash_add(Z_ARRVAL_P(retval), "key", sizeof("key"), (void **)&k, sizeof(zval *), NULL); zend_hash_add(Z_ARRVAL_P(retval), "value", sizeof("value"), (void **)&v, sizeof(zval *), NULL); if (ctx->flags) { zval *c; MAKE_STD_ZVAL(c); Z_TYPE_P(c) = IS_STRING; Z_STRLEN_P(c) = spprintf(&(Z_STRVAL_P(c)), 0, "%llu", cas); zend_hash_add(Z_ARRVAL_P(retval), "cas", sizeof("cas"), (void **)&c, sizeof(zval *), NULL); } if (ctx->res->prefix_key_len && nkey) { efree((void *)key); } } else { if (LCB_KEY_ENOENT == error) { return; } if (IS_ARRAY == Z_TYPE_P(ctx->rv)) { /* multi get */ zval *v; char *key_string = NULL; MAKE_STD_ZVAL(v); if (!php_couchbase_zval_from_payload(v, (char *)bytes, nbytes, flags, ctx->res->serializer, ctx->res->ignoreflags TSRMLS_CC)) { ctx->res->rc = LCB_ERROR; efree(v); return; } if (ctx->res->prefix_key_len && nkey) { if (!strncmp(key, ctx->res->prefix_key, ctx->res->prefix_key_len)) { nkey -= (ctx->res->prefix_key_len + 1); key_string = estrndup(((const char *)key) + ctx->res->prefix_key_len + 1, nkey); } } else { key_string = emalloc(nkey + 1); memcpy(key_string, key, nkey); key_string[nkey] = '\0'; } zend_hash_update((Z_ARRVAL_P(ctx->rv)), (char *)key_string, nkey + 1, (void **)&v, sizeof(zval *), NULL); if (ctx->cas) { zval *c; MAKE_STD_ZVAL(c); Z_TYPE_P(c) = IS_STRING; Z_STRLEN_P(c) = spprintf(&(Z_STRVAL_P(c)), 0, "%llu", cas); zend_hash_add(Z_ARRVAL_P(ctx->cas), (char *)key_string, nkey + 1, (void **)&c, sizeof(zval *), NULL); } efree(key_string); } else { if (ctx->res->prefix_key_len && nkey) { if (!strncmp(key, ctx->res->prefix_key, ctx->res->prefix_key_len)) { nkey -= (ctx->res->prefix_key_len + 1); key = estrndup(((const char *)key) + ctx->res->prefix_key_len + 1, nkey); } } if (!php_couchbase_zval_from_payload(ctx->rv, (char *)bytes, nbytes, flags, ctx->res->serializer, ctx->res->ignoreflags TSRMLS_CC)) { if (ctx->res->prefix_key_len && nkey) { efree((void *)key); } ctx->res->rc = LCB_ERROR; return; } if (ctx->res->prefix_key_len && nkey) { efree((void *)key); } if (ctx->cas) { Z_TYPE_P(ctx->cas) = IS_STRING; Z_STRLEN_P(ctx->cas) = spprintf(&(Z_STRVAL_P(ctx->cas)), 0, "%llu", cas); } } } }
PHP_COUCHBASE_LOCAL void php_couchbase_get_impl(INTERNAL_FUNCTION_PARAMETERS, int multi, int oo, int lock, int touch, int replica) { char *key, **keys; long *klens, klen = 0; int nkey = 0; long flag = 0; lcb_time_t exp = {0}; long expiry = 0; zval *res, *cas_token = NULL; int argflags; lcb_error_t retval; php_couchbase_res *couchbase_res; php_couchbase_ctx *ctx; zend_fcall_info fci = {0}; zend_fcall_info_cache fci_cache; argflags = oo ? PHP_COUCHBASE_ARG_F_OO : PHP_COUCHBASE_ARG_F_FUNCTIONAL; if (multi) { zval *akeys; zval **ppzval; zend_bool preserve_order; int i; if (lock) { PHP_COUCHBASE_GET_PARAMS_WITH_ZV(res, couchbase_res, argflags, "az|ll", &akeys, &cas_token, &flag, &expiry); } else if (touch) { PHP_COUCHBASE_GET_PARAMS_WITH_ZV(res, couchbase_res, argflags, "al|z", &akeys, &expiry, &cas_token); } else { PHP_COUCHBASE_GET_PARAMS_WITH_ZV(res, couchbase_res, argflags, "a|zl", &akeys, &cas_token, &flag); } if (pcbc_check_expiry(INTERNAL_FUNCTION_PARAM_PASSTHRU, oo, expiry, &exp) == -1) { return ; } nkey = zend_hash_num_elements(Z_ARRVAL_P(akeys)); keys = ecalloc(nkey, sizeof(char *)); klens = ecalloc(nkey, sizeof(long)); preserve_order = (flag & COUCHBASE_GET_PRESERVE_ORDER); array_init(return_value); for (i = 0, zend_hash_internal_pointer_reset(Z_ARRVAL_P(akeys)); zend_hash_has_more_elements(Z_ARRVAL_P(akeys)) == SUCCESS; zend_hash_move_forward(Z_ARRVAL_P(akeys)), i++) { if (zend_hash_get_current_data(Z_ARRVAL_P(akeys), (void **)&ppzval) == FAILURE) { nkey--; continue; } if (IS_ARRAY != Z_TYPE_PP(ppzval)) { convert_to_string_ex(ppzval); } if (!Z_STRLEN_PP(ppzval)) { nkey--; continue; } if (couchbase_res->prefix_key_len) { klens[i] = spprintf(&(keys[i]), 0, "%s_%s", couchbase_res->prefix_key, Z_STRVAL_PP(ppzval)); } else { keys[i] = Z_STRVAL_PP(ppzval); klens[i] = Z_STRLEN_PP(ppzval); } if (preserve_order) { add_assoc_null_ex(return_value, keys[i], klens[i] + 1); } } if (!nkey) { efree(keys); efree(klens); return; } if (cas_token && IS_ARRAY != Z_TYPE_P(cas_token)) { zval_dtor(cas_token); array_init(cas_token); } } else { if (lock) { PHP_COUCHBASE_GET_PARAMS_WITH_ZV(res, couchbase_res, argflags, "sz|l", &key, &klen, &cas_token, &expiry); } else if (touch) { PHP_COUCHBASE_GET_PARAMS_WITH_ZV(res, couchbase_res, argflags, "sl|z", &key, &klen, &expiry, &cas_token); } else { PHP_COUCHBASE_GET_PARAMS_WITH_ZV(res, couchbase_res, argflags, "s|f!z", &key, &klen, &fci, &fci_cache, &cas_token); } if (pcbc_check_expiry(INTERNAL_FUNCTION_PARAM_PASSTHRU, oo, expiry, &exp) == -1) { return ; } if (!klen) { return; } nkey = 1; if (couchbase_res->prefix_key_len) { klen = spprintf(&key, 0, "%s_%s", couchbase_res->prefix_key, key); } keys = &key; klens = &klen; if (cas_token) { zval_dtor(cas_token); ZVAL_NULL(cas_token); } } if (replica) { lcb_get_replica_cmd_t **commands = ecalloc(nkey, sizeof(lcb_get_replica_cmd_t *)); int ii; for (ii = 0; ii < nkey; ++ii) { lcb_get_replica_cmd_t *cmd = ecalloc(1, sizeof(lcb_get_replica_cmd_t)); commands[ii] = cmd; cmd->v.v0.key = keys[ii]; cmd->v.v0.nkey = klens[ii]; } ctx = ecalloc(1, sizeof(php_couchbase_ctx)); ctx->res = couchbase_res; ctx->rv = return_value; ctx->cas = cas_token; retval = lcb_get_replica(couchbase_res->handle, ctx, nkey, (const lcb_get_replica_cmd_t * const *)commands); for (ii = 0; ii < nkey; ++ii) { efree(commands[ii]); } efree(commands); } else { lcb_get_cmd_t **commands = ecalloc(nkey, sizeof(lcb_get_cmd_t *)); int ii; for (ii = 0; ii < nkey; ++ii) { lcb_get_cmd_t *cmd = ecalloc(1, sizeof(lcb_get_cmd_t)); commands[ii] = cmd; cmd->v.v0.key = keys[ii]; cmd->v.v0.nkey = klens[ii]; cmd->v.v0.lock = (int)lock; cmd->v.v0.exptime = exp; /* NB: this assumes sizeof(lcb_time_t) == sizeof(long) */ } ctx = ecalloc(1, sizeof(php_couchbase_ctx)); ctx->res = couchbase_res; ctx->rv = return_value; ctx->cas = cas_token; retval = lcb_get(couchbase_res->handle, ctx, nkey, (const lcb_get_cmd_t * const *)commands); for (ii = 0; ii < nkey; ++ii) { efree(commands[ii]); } efree(commands); } if (LCB_SUCCESS != retval) { if (couchbase_res->prefix_key_len) { int i; for (i = 0; i < nkey; i++) { efree(keys[i]); } } if (multi) { efree(keys); efree(klens); zval_dtor(return_value); } efree(ctx); couchbase_report_error(INTERNAL_FUNCTION_PARAM_PASSTHRU, oo, cb_lcb_exception, "Failed to schedule get request: %s", lcb_strerror(couchbase_res->handle, retval)); return; } couchbase_res->seqno += nkey; pcbc_start_loop(couchbase_res); if (ctx->res->rc != LCB_SUCCESS) { if (!multi) { RETVAL_FALSE; } if (ctx->res->rc == LCB_KEY_ENOENT) { if (fci.size) { zval *result; zval *zkey; zval *retval_ptr = NULL; zval **params[3]; int cbret; MAKE_STD_ZVAL(result); MAKE_STD_ZVAL(zkey); ZVAL_NULL(result); ZVAL_STRINGL(zkey, key, klen, 1); params[0] = &res; params[1] = &zkey; params[2] = &result; fci.retval_ptr_ptr = &retval_ptr; fci.param_count = 3; fci.params = params; cbret = zend_call_function(&fci, &fci_cache TSRMLS_CC); if (cbret == SUCCESS && fci.retval_ptr_ptr && *fci.retval_ptr_ptr) { if (Z_TYPE_P(retval_ptr) == IS_BOOL && Z_BVAL_P(retval_ptr)) { zval_ptr_dtor(fci.retval_ptr_ptr); zval_ptr_dtor(&zkey); efree(ctx); if (multi) { zval_dtor(return_value); } RETURN_ZVAL(result, 1, 1); } zval_ptr_dtor(fci.retval_ptr_ptr); } zval_ptr_dtor(&zkey); zval_ptr_dtor(&result); } } else { couchbase_report_error(INTERNAL_FUNCTION_PARAM_PASSTHRU, oo, cb_lcb_exception, "Failed to get a value from server: %s", lcb_strerror(couchbase_res->handle, ctx->res->rc)); } } efree(ctx); if (couchbase_res->prefix_key_len) { int i; for (i = 0; i < nkey; i++) { efree(keys[i]); } } if (multi) { efree(keys); efree(klens); } }
/** * Sets a cookie to be sent at the end of the request * This method overrides any cookie set before with the same name */ PHP_METHOD(Phalcon_Http_Response_Cookies, set) { zval *_3; zend_bool secure, httpOnly; int expire, ZEPHIR_LAST_CALL_STATUS; zval *name_param = NULL, *value = NULL, *expire_param = NULL, *path_param = NULL, *secure_param = NULL, *domain_param = NULL, *httpOnly_param = NULL, *cookie = NULL, *encryption, *dependencyInjector, *response = NULL, *_0, *_1, *_2 = NULL, *_4 = NULL, *_5; zval *name = NULL, *path = NULL, *domain = NULL; ZEPHIR_MM_GROW(); zephir_fetch_params(1, 1, 6, &name_param, &value, &expire_param, &path_param, &secure_param, &domain_param, &httpOnly_param); if (unlikely(Z_TYPE_P(name_param) != IS_STRING && Z_TYPE_P(name_param) != IS_NULL)) { zephir_throw_exception_string(spl_ce_InvalidArgumentException, SL("Parameter 'name' must be a string") TSRMLS_CC); RETURN_MM_NULL(); } if (likely(Z_TYPE_P(name_param) == IS_STRING)) { zephir_get_strval(name, name_param); } else { ZEPHIR_INIT_VAR(name); ZVAL_EMPTY_STRING(name); } if (!value) { value = ZEPHIR_GLOBAL(global_null); } if (!expire_param) { expire = 0; } else { expire = zephir_get_intval(expire_param); } if (!path_param) { ZEPHIR_INIT_VAR(path); ZVAL_STRING(path, "/", 1); } else { zephir_get_strval(path, path_param); } if (!secure_param) { secure = 0; } else { secure = zephir_get_boolval(secure_param); } if (!domain_param) { ZEPHIR_INIT_VAR(domain); ZVAL_EMPTY_STRING(domain); } else { if (unlikely(Z_TYPE_P(domain_param) != IS_STRING && Z_TYPE_P(domain_param) != IS_NULL)) { zephir_throw_exception_string(spl_ce_InvalidArgumentException, SL("Parameter 'domain' must be a string") TSRMLS_CC); RETURN_MM_NULL(); } if (likely(Z_TYPE_P(domain_param) == IS_STRING)) { zephir_get_strval(domain, domain_param); } else { ZEPHIR_INIT_VAR(domain); ZVAL_EMPTY_STRING(domain); } } if (!httpOnly_param) { httpOnly = 0; } else { httpOnly = zephir_get_boolval(httpOnly_param); } ZEPHIR_OBS_VAR(encryption); zephir_read_property_this(&encryption, this_ptr, SL("_useEncryption"), PH_NOISY_CC); ZEPHIR_OBS_VAR(cookie); _0 = zephir_fetch_nproperty_this(this_ptr, SL("_cookies"), PH_NOISY_CC); if (!(zephir_array_isset_fetch(&cookie, _0, name, 0 TSRMLS_CC))) { _1 = zephir_fetch_nproperty_this(this_ptr, SL("_dependencyInjector"), PH_NOISY_CC); ZEPHIR_INIT_VAR(_3); zephir_create_array(_3, 7, 0 TSRMLS_CC); zephir_array_fast_append(_3, name); zephir_array_fast_append(_3, value); ZEPHIR_INIT_VAR(_4); ZVAL_LONG(_4, expire); zephir_array_fast_append(_3, _4); zephir_array_fast_append(_3, path); ZEPHIR_INIT_NVAR(_4); ZVAL_BOOL(_4, secure); zephir_array_fast_append(_3, _4); zephir_array_fast_append(_3, domain); ZEPHIR_INIT_NVAR(_4); ZVAL_BOOL(_4, httpOnly); zephir_array_fast_append(_3, _4); ZEPHIR_INIT_NVAR(_4); ZVAL_STRING(_4, "Phalcon\\Http\\Cookie", ZEPHIR_TEMP_PARAM_COPY); ZEPHIR_CALL_METHOD(&_2, _1, "get", NULL, 0, _4, _3); zephir_check_temp_parameter(_4); zephir_check_call_status(); ZEPHIR_CPY_WRT(cookie, _2); _5 = zephir_fetch_nproperty_this(this_ptr, SL("_dependencyInjector"), PH_NOISY_CC); ZEPHIR_CALL_METHOD(NULL, cookie, "setdi", NULL, 0, _5); zephir_check_call_status(); if (zephir_is_true(encryption)) { ZEPHIR_CALL_METHOD(NULL, cookie, "useencryption", NULL, 0, encryption); zephir_check_call_status(); } zephir_update_property_array(this_ptr, SL("_cookies"), name, cookie TSRMLS_CC); } else { ZEPHIR_CALL_METHOD(NULL, cookie, "setvalue", NULL, 0, value); zephir_check_call_status(); ZEPHIR_INIT_NVAR(_4); ZVAL_LONG(_4, expire); ZEPHIR_CALL_METHOD(NULL, cookie, "setexpiration", NULL, 0, _4); zephir_check_call_status(); ZEPHIR_CALL_METHOD(NULL, cookie, "setpath", NULL, 0, path); zephir_check_call_status(); ZEPHIR_CALL_METHOD(NULL, cookie, "setsecure", NULL, 0, (secure ? ZEPHIR_GLOBAL(global_true) : ZEPHIR_GLOBAL(global_false))); zephir_check_call_status(); ZEPHIR_CALL_METHOD(NULL, cookie, "setdomain", NULL, 0, domain); zephir_check_call_status(); ZEPHIR_CALL_METHOD(NULL, cookie, "sethttponly", NULL, 0, (httpOnly ? ZEPHIR_GLOBAL(global_true) : ZEPHIR_GLOBAL(global_false))); zephir_check_call_status(); } _1 = zephir_fetch_nproperty_this(this_ptr, SL("_registered"), PH_NOISY_CC); if (ZEPHIR_IS_FALSE_IDENTICAL(_1)) { ZEPHIR_OBS_VAR(dependencyInjector); zephir_read_property_this(&dependencyInjector, this_ptr, SL("_dependencyInjector"), PH_NOISY_CC); if (Z_TYPE_P(dependencyInjector) != IS_OBJECT) { ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_http_cookie_exception_ce, "A dependency injection object is required to access the 'response' service", "phalcon/http/response/cookies.zep", 130); return; } ZEPHIR_INIT_NVAR(_4); ZVAL_STRING(_4, "response", ZEPHIR_TEMP_PARAM_COPY); ZEPHIR_CALL_METHOD(&response, dependencyInjector, "getshared", NULL, 0, _4); zephir_check_temp_parameter(_4); zephir_check_call_status(); ZEPHIR_CALL_METHOD(NULL, response, "setcookies", NULL, 0, this_ptr); zephir_check_call_status(); } RETURN_THIS(); }
/** * Produces a recursive representation of an array * * @param array $argument * @return string */ PHP_METHOD(Phalcon_Debug, _getArrayDump) { zval *argument, *n = NULL, *number_arguments, *dump; zval *v = NULL, *var_dump = NULL, *escaped_string = NULL, *next = NULL, *array_dump = NULL; zval *class_name = NULL, *joined_dump; zend_string *str_key; ulong idx; PHALCON_MM_GROW(); phalcon_fetch_params(0, 1, 1, &argument, &n); if (!n) { PHALCON_INIT_VAR(n); ZVAL_LONG(n, 0); } PHALCON_INIT_VAR(number_arguments); phalcon_fast_count(number_arguments, argument); if (PHALCON_LT_LONG(n, 3)) { if (PHALCON_GT_LONG(number_arguments, 0)) { if (PHALCON_LT_LONG(number_arguments, 10)) { PHALCON_INIT_VAR(dump); array_init(dump); ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(argument), idx, str_key, v) { zval tmp; if (str_key) { ZVAL_STR(&tmp, str_key); } else { ZVAL_LONG(&tmp, idx); } if (PHALCON_IS_SCALAR(v)) { if (PHALCON_IS_STRING(v, "")) { PHALCON_INIT_NVAR(var_dump); PHALCON_CONCAT_SVS(var_dump, "[", &tmp, "] => (empty string)"); } else { PHALCON_CALL_METHOD(&escaped_string, getThis(), "_escapestring", v); PHALCON_INIT_NVAR(var_dump); PHALCON_CONCAT_SVSV(var_dump, "[", &tmp, "] => ", escaped_string); } phalcon_array_append(dump, var_dump, PH_COPY); } else { if (Z_TYPE_P(v) == IS_ARRAY) { PHALCON_INIT_NVAR(next); phalcon_add_function(next, n, &PHALCON_GLOBAL(z_one)); PHALCON_CALL_METHOD(&array_dump, getThis(), "_getarraydump", v, next); PHALCON_INIT_NVAR(var_dump); PHALCON_CONCAT_SVSVS(var_dump, "[", &tmp, "] => Array(", array_dump, ")"); phalcon_array_append(dump, var_dump, PH_COPY); continue; } if (Z_TYPE_P(v) == IS_OBJECT) { zend_class_entry *ce = Z_OBJCE_P(v); PHALCON_INIT_NVAR(class_name); ZVAL_NEW_STR(class_name, ce->name); PHALCON_INIT_NVAR(var_dump); PHALCON_CONCAT_SVSVS(var_dump, "[", &tmp, "] => Object(", class_name, ")"); phalcon_array_append(dump, var_dump, PH_COPY); continue; } if (Z_TYPE_P(v) == IS_NULL) { PHALCON_INIT_NVAR(var_dump); PHALCON_CONCAT_SVS(var_dump, "[", &tmp, "] => null"); phalcon_array_append(dump, var_dump, PH_COPY); continue; } PHALCON_INIT_NVAR(var_dump); PHALCON_CONCAT_SVSV(var_dump, "[", &tmp, "] => ", v); phalcon_array_append(dump, var_dump, PH_COPY); } } ZEND_HASH_FOREACH_END(); PHALCON_INIT_VAR(joined_dump); phalcon_fast_join_str(joined_dump, SL(", "), dump); RETURN_CTOR(joined_dump); } RETURN_NCTOR(number_arguments); }
/** * Executes the validation */ PHP_METHOD(Phalcon_Validation_Validator_Date, validate) { zend_long ZEPHIR_LAST_CALL_STATUS; zval *field = NULL; zval *validation, *field_param = NULL, *value = NULL, *format = NULL, *label = NULL, *message = NULL, *replacePairs = NULL, *code = NULL, *_0, *_2 = NULL, *_1$$3, *_3$$5 = NULL, *_4$$5 = NULL, *_5$$5; ZEPHIR_MM_GROW(); zephir_fetch_params(1, 2, 0, &validation, &field_param); if (UNEXPECTED(Z_TYPE_P(field_param) != IS_STRING && Z_TYPE_P(field_param) != IS_NULL)) { zephir_throw_exception_string(spl_ce_InvalidArgumentException, SL("Parameter 'field' must be a string") TSRMLS_CC); RETURN_MM_NULL(); } if (EXPECTED(Z_TYPE_P(field_param) == IS_STRING)) { zephir_get_strval(field, field_param); } else { ZEPHIR_INIT_VAR(field); ZVAL_EMPTY_STRING(field); } ZEPHIR_CALL_METHOD(&value, validation, "getvalue", NULL, 0, field); zephir_check_call_status(); ZEPHIR_INIT_VAR(_0); ZVAL_STRING(_0, "format", ZEPHIR_TEMP_PARAM_COPY); ZEPHIR_CALL_METHOD(&format, this_ptr, "getoption", NULL, 0, _0); zephir_check_temp_parameter(_0); zephir_check_call_status(); if (Z_TYPE_P(format) == IS_ARRAY) { zephir_array_fetch(&_1$$3, format, field, PH_NOISY | PH_READONLY, "phalcon/validation/validator/date.zep", 80 TSRMLS_CC); ZEPHIR_CPY_WRT(format, _1$$3); } if (ZEPHIR_IS_EMPTY(format)) { ZEPHIR_INIT_NVAR(format); ZVAL_STRING(format, "Y-m-d", 1); } ZEPHIR_CALL_METHOD(&_2, this_ptr, "checkdate", NULL, 476, value, format); zephir_check_call_status(); if (!(zephir_is_true(_2))) { ZEPHIR_CALL_METHOD(&label, this_ptr, "preparelabel", NULL, 0, validation, field); zephir_check_call_status(); ZEPHIR_INIT_VAR(_3$$5); ZVAL_STRING(_3$$5, "Date", ZEPHIR_TEMP_PARAM_COPY); ZEPHIR_CALL_METHOD(&message, this_ptr, "preparemessage", NULL, 0, validation, field, _3$$5); zephir_check_temp_parameter(_3$$5); zephir_check_call_status(); ZEPHIR_CALL_METHOD(&code, this_ptr, "preparecode", NULL, 0, field); zephir_check_call_status(); ZEPHIR_INIT_VAR(replacePairs); zephir_create_array(replacePairs, 1, 0 TSRMLS_CC); zephir_array_update_string(&replacePairs, SL(":field"), &label, PH_COPY | PH_SEPARATE); ZEPHIR_INIT_NVAR(_3$$5); object_init_ex(_3$$5, phalcon_validation_message_ce); ZEPHIR_CALL_FUNCTION(&_4$$5, "strtr", NULL, 27, message, replacePairs); zephir_check_call_status(); ZEPHIR_INIT_VAR(_5$$5); ZVAL_STRING(_5$$5, "Date", ZEPHIR_TEMP_PARAM_COPY); ZEPHIR_CALL_METHOD(NULL, _3$$5, "__construct", NULL, 470, _4$$5, field, _5$$5, code); zephir_check_temp_parameter(_5$$5); zephir_check_call_status(); ZEPHIR_CALL_METHOD(NULL, validation, "appendmessage", NULL, 0, _3$$5); zephir_check_call_status(); RETURN_MM_BOOL(0); } RETURN_MM_BOOL(1); }
/** * Constructor for Phalcon\Session\Adapter\Memcache * * @param array $options */ PHP_METHOD(Phalcon_Session_Adapter_Memcache, __construct){ zval *options; zval *host, *port, *lifetime, *persistent, *prefix; zval *frontend_data, *memcache, *option; zval *callable_open , *callable_close , *callable_read , *callable_write , *callable_destroy , *callable_gc; PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 0, &options); if (Z_TYPE_P(options) != IS_ARRAY) { PHALCON_THROW_EXCEPTION_STR(phalcon_session_exception_ce, "The options must be an array"); return; } if (!phalcon_array_isset_string_fetch(&host, options, SS("host"))) { PHALCON_THROW_EXCEPTION_STR(phalcon_session_exception_ce, "No session host given in options"); return; } if (!phalcon_array_isset_string_fetch(&port, options, SS("port"))) { PHALCON_INIT_VAR(port); ZVAL_LONG(port, 11211); } if (!phalcon_array_isset_string_fetch(&lifetime, options, SS("lifetime"))) { PHALCON_INIT_VAR(lifetime); ZVAL_LONG(lifetime, 8600); } phalcon_update_property_this(this_ptr, SL("_lifetime"), lifetime TSRMLS_CC); if (!phalcon_array_isset_string_fetch(&persistent, options, SS("persistent"))) { PHALCON_INIT_VAR(persistent); ZVAL_FALSE(persistent); } if (!phalcon_array_isset_string_fetch(&prefix, options, SS("prefix"))) { PHALCON_INIT_VAR(prefix); ZVAL_EMPTY_STRING(prefix); } /* create memcache instance */ PHALCON_INIT_VAR(option); array_init_size(option, 1); phalcon_array_update_string(&option, SL("lifetime"), lifetime, PH_COPY); PHALCON_INIT_VAR(frontend_data); object_init_ex(frontend_data, phalcon_cache_frontend_data_ce); PHALCON_CALL_METHOD(NULL, frontend_data, "__construct", option); PHALCON_INIT_NVAR(option); array_init_size(option, 3); phalcon_array_update_string(&option, SL("host"), host, PH_COPY); phalcon_array_update_string(&option, SL("port"), port, PH_COPY); phalcon_array_update_string(&option, SL("persistent"), persistent, PH_COPY); phalcon_array_update_string(&option, SL("prefix"), prefix, PH_COPY); PHALCON_INIT_VAR(memcache); object_init_ex(memcache, phalcon_cache_backend_memcache_ce); PHALCON_CALL_METHOD(NULL, memcache, "__construct", frontend_data, option); phalcon_update_property_this(this_ptr, SL("_memcache"), memcache TSRMLS_CC); /* open callback */ PHALCON_INIT_VAR(callable_open); array_init_size(callable_open, 2); phalcon_array_append(&callable_open, this_ptr, PH_COPY); phalcon_array_append_string(&callable_open, SL("open"), 0); /* close callback */ PHALCON_INIT_VAR(callable_close); array_init_size(callable_close, 2); phalcon_array_append(&callable_close, this_ptr, PH_COPY); phalcon_array_append_string(&callable_close, SL("close"), 0); /* read callback */ PHALCON_INIT_VAR(callable_read); array_init_size(callable_read, 2); phalcon_array_append(&callable_read, this_ptr, PH_COPY); phalcon_array_append_string(&callable_read, SL("read"), 0); /* write callback */ PHALCON_INIT_VAR(callable_write); array_init_size(callable_write, 2); phalcon_array_append(&callable_write, this_ptr, PH_COPY); phalcon_array_append_string(&callable_write, SL("write"), 0); /* destroy callback */ PHALCON_INIT_VAR(callable_destroy); array_init_size(callable_destroy, 2); phalcon_array_append(&callable_destroy, this_ptr, PH_COPY); phalcon_array_append_string(&callable_destroy, SL("destroy"), 0); /* gc callback */ PHALCON_INIT_VAR(callable_gc); array_init_size(callable_gc, 2); phalcon_array_append(&callable_gc, this_ptr, PH_COPY); phalcon_array_append_string(&callable_gc, SL("gc"), 0); PHALCON_CALL_FUNCTION(NULL, "session_set_save_handler", callable_open, callable_close, callable_read, callable_write, callable_destroy, callable_gc); PHALCON_CALL_PARENT(NULL, phalcon_session_adapter_memcache_ce, this_ptr, "__construct", options); PHALCON_MM_RESTORE(); }
/** * Inserts data into a table using custom RBDM SQL syntax * * * * @param string $table * @param array $values * @param array $fields * @param boolean $automaticQuotes * @return boolean */ PHP_METHOD(Phalcon_Db, insert){ zval *table = NULL, *values = NULL, *fields = NULL, *automatic_quotes = NULL; zval *value = NULL, *key = NULL, *joined_values = NULL, *insert_sql = NULL; zval *r0 = NULL, *r1 = NULL, *r2 = NULL, *r3 = NULL, *r4 = NULL, *r5 = NULL, *r6 = NULL; zval *r7 = NULL, *r8 = NULL, *r9 = NULL, *r10 = NULL; zval *i0 = NULL; zval *c0 = NULL, *c1 = NULL; HashTable *ah0; HashPosition hp0; zval **hd; char *hash_index; uint hash_index_len; ulong hash_num; int hash_type; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz|zz", &table, &values, &fields, &automatic_quotes) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } PHALCON_SEPARATE_PARAM(values); if (!fields) { PHALCON_INIT_VAR(fields); ZVAL_NULL(fields); } if (!automatic_quotes) { PHALCON_INIT_VAR(automatic_quotes); ZVAL_BOOL(automatic_quotes, 0); } if (Z_TYPE_P(values) == IS_ARRAY) { PHALCON_ALLOC_ZVAL_MM(r0); phalcon_fast_count(r0, values TSRMLS_CC); if (!zend_is_true(r0)) { PHALCON_ALLOC_ZVAL_MM(i0); object_init_ex(i0, phalcon_db_exception_ce); PHALCON_ALLOC_ZVAL_MM(r1); PHALCON_CONCAT_SVS(r1, "Unable to insert into ", table, " without data"); PHALCON_CALL_METHOD_PARAMS_1_NORETURN(i0, "__construct", r1, PHALCON_CHECK); phalcon_throw_exception(i0 TSRMLS_CC); return; } else { if (zend_is_true(automatic_quotes)) { if (phalcon_valid_foreach(values TSRMLS_CC)) { ALLOC_HASHTABLE(ah0); zend_hash_init(ah0, 0, NULL, NULL, 0); zend_hash_copy(ah0, Z_ARRVAL_P(values), NULL, NULL, sizeof(zval*)); zend_hash_internal_pointer_reset_ex(ah0, &hp0); fes_e7f0_1: if(zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) != SUCCESS){ goto fee_e7f0_1; } else { PHALCON_INIT_VAR(key); PHALCON_GET_FOREACH_KEY(key, ah0, hp0); } PHALCON_INIT_VAR(value); ZVAL_ZVAL(value, *hd, 1, 0); if (Z_TYPE_P(value) == IS_OBJECT) { PHALCON_INIT_VAR(r2); phalcon_instance_of(r2, value, phalcon_db_rawvalue_ce TSRMLS_CC); if (zend_is_true(r2)) { PHALCON_INIT_VAR(r3); PHALCON_CALL_METHOD_PARAMS_1(r3, this_ptr, "escapestring", value, PHALCON_NO_CHECK); phalcon_array_update(&values, key, &r3, PHALCON_SEPARATE_PLZ, PHALCON_COPY, PHALCON_NO_CTOR TSRMLS_CC); goto fes_e7f0_1; } } PHALCON_INIT_VAR(r4); PHALCON_INIT_VAR(r5); PHALCON_CALL_METHOD_PARAMS_1(r5, this_ptr, "escapestring", value, PHALCON_NO_CHECK); PHALCON_CONCAT_SVS(r4, "'", r5, "'"); phalcon_array_update(&values, key, &r4, PHALCON_SEPARATE_PLZ, PHALCON_COPY, PHALCON_NO_CTOR TSRMLS_CC); zend_hash_move_forward_ex(ah0, &hp0); goto fes_e7f0_1; fee_e7f0_1: zend_hash_destroy(ah0); efree(ah0); } else { return; } } } PHALCON_INIT_VAR(c0); ZVAL_STRING(c0, ", ", 1); PHALCON_ALLOC_ZVAL_MM(r6); phalcon_fast_join(r6, c0, values TSRMLS_CC); PHALCON_CPY_WRT(joined_values, r6); if (Z_TYPE_P(fields) == IS_ARRAY) { PHALCON_ALLOC_ZVAL_MM(r7); PHALCON_INIT_VAR(c1); ZVAL_STRING(c1, ", ", 1); PHALCON_ALLOC_ZVAL_MM(r8); phalcon_fast_join(r8, c1, fields TSRMLS_CC); PHALCON_CONCAT_SVSVSVS(r7, "INSERT INTO ", table, " (", r8, ") VALUES (", joined_values, ")"); PHALCON_CPY_WRT(insert_sql, r7); } else { PHALCON_ALLOC_ZVAL_MM(r9); PHALCON_CONCAT_SVSVS(r9, "INSERT INTO ", table, " VALUES (", joined_values, ")"); PHALCON_CPY_WRT(insert_sql, r9); } PHALCON_ALLOC_ZVAL_MM(r10); PHALCON_CALL_METHOD_PARAMS_1(r10, this_ptr, "query", insert_sql, PHALCON_NO_CHECK); PHALCON_RETURN_DZVAL(r10); } else { PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "The second parameter for insert isn't an Array"); return; } PHALCON_MM_RESTORE(); }
static zend_always_inline zval *_zend_hash_add_or_update_i(HashTable *ht, zend_string *key, zval *pData, uint32_t flag ZEND_FILE_LINE_DC) { zend_ulong h; uint32_t nIndex; uint32_t idx; Bucket *p; #ifdef ZEND_SIGNALS TSRMLS_FETCH(); #endif IS_CONSISTENT(ht); if (UNEXPECTED(ht->nTableMask == 0)) { CHECK_INIT(ht, 0); goto add_to_hash; } else if (ht->u.flags & HASH_FLAG_PACKED) { zend_hash_packed_to_hash(ht); } else if ((flag & HASH_ADD_NEW) == 0) { p = zend_hash_find_bucket(ht, key); if (p) { zval *data; if (flag & HASH_ADD) { return NULL; } ZEND_ASSERT(&p->val != pData); data = &p->val; if ((flag & HASH_UPDATE_INDIRECT) && Z_TYPE_P(data) == IS_INDIRECT) { data = Z_INDIRECT_P(data); } HANDLE_BLOCK_INTERRUPTIONS(); if (ht->pDestructor) { ht->pDestructor(data); } ZVAL_COPY_VALUE(data, pData); HANDLE_UNBLOCK_INTERRUPTIONS(); return data; } } ZEND_HASH_IF_FULL_DO_RESIZE(ht); /* If the Hash table is full, resize it */ add_to_hash: HANDLE_BLOCK_INTERRUPTIONS(); idx = ht->nNumUsed++; ht->nNumOfElements++; if (ht->nInternalPointer == INVALID_IDX) { ht->nInternalPointer = idx; } p = ht->arData + idx; p->h = h = zend_string_hash_val(key); p->key = key; zend_string_addref(key); ZVAL_COPY_VALUE(&p->val, pData); nIndex = h & ht->nTableMask; Z_NEXT(p->val) = ht->arHash[nIndex]; ht->arHash[nIndex] = idx; HANDLE_UNBLOCK_INTERRUPTIONS(); return &p->val; }
/** * Updates data on a table using custom RBDM SQL syntax * * * * @param string $table * @param array $fields * @param array $values * @param string $whereCondition * @param boolean $automaticQuotes * @return boolean */ PHP_METHOD(Phalcon_Db, update){ zval *table = NULL, *fields = NULL, *values = NULL, *where_condition = NULL; zval *automatic_quotes = NULL, *i = NULL, *update_values = NULL, *update_sql = NULL; zval *field = NULL; zval *r0 = NULL, *r1 = NULL, *r2 = NULL, *r3 = NULL, *r4 = NULL, *r5 = NULL, *r6 = NULL; zval *r7 = NULL, *r8 = NULL, *r9 = NULL, *r10 = NULL, *r11 = NULL, *r12 = NULL, *r13 = NULL; zval *r14 = NULL, *r15 = NULL, *r16 = NULL, *r17 = NULL, *r18 = NULL; zval *a0 = NULL; zval *c0 = NULL; zval *t0 = NULL; HashTable *ah0; HashPosition hp0; zval **hd; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zzz|zz", &table, &fields, &values, &where_condition, &automatic_quotes) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } PHALCON_SEPARATE_PARAM(values); if (!where_condition) { PHALCON_INIT_VAR(where_condition); ZVAL_NULL(where_condition); } if (!automatic_quotes) { PHALCON_INIT_VAR(automatic_quotes); ZVAL_BOOL(automatic_quotes, 0); } PHALCON_ALLOC_ZVAL_MM(r0); phalcon_fast_count(r0, fields TSRMLS_CC); PHALCON_ALLOC_ZVAL_MM(r1); phalcon_fast_count(r1, values TSRMLS_CC); PHALCON_INIT_VAR(r2); is_not_equal_function(r2, r0, r1 TSRMLS_CC); if (zend_is_true(r2)) { PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "The number of values to update is not the same as fields"); return; } PHALCON_INIT_VAR(i); ZVAL_LONG(i, 0); PHALCON_INIT_VAR(a0); array_init(a0); PHALCON_CPY_WRT(update_values, a0); PHALCON_ALLOC_ZVAL_MM(r3); PHALCON_CONCAT_SVS(r3, "UPDATE ", table, " SET "); PHALCON_CPY_WRT(update_sql, r3); if (phalcon_valid_foreach(fields TSRMLS_CC)) { ah0 = Z_ARRVAL_P(fields); zend_hash_internal_pointer_reset_ex(ah0, &hp0); fes_e7f0_2: if(zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) != SUCCESS){ goto fee_e7f0_2; } PHALCON_INIT_VAR(field); ZVAL_ZVAL(field, *hd, 1, 0); if (zend_is_true(automatic_quotes)) { PHALCON_INIT_VAR(r4); phalcon_array_fetch(&r4, values, i, PHALCON_NOISY TSRMLS_CC); if (Z_TYPE_P(r4) == IS_OBJECT) { PHALCON_INIT_VAR(r5); phalcon_array_fetch(&r5, values, i, PHALCON_NOISY TSRMLS_CC); PHALCON_INIT_VAR(r6); phalcon_instance_of(r6, r5, phalcon_db_rawvalue_ce TSRMLS_CC); if (zend_is_true(r6)) { PHALCON_INIT_VAR(r7); PHALCON_INIT_VAR(r8); PHALCON_INIT_VAR(r9); phalcon_array_fetch(&r9, values, i, PHALCON_NOISY TSRMLS_CC); PHALCON_CALL_METHOD(r8, r9, "getvalue", PHALCON_NO_CHECK); PHALCON_CALL_METHOD_PARAMS_1(r7, this_ptr, "escapestring", r8, PHALCON_NO_CHECK); phalcon_array_update(&values, i, &r7, PHALCON_SEPARATE_PLZ, PHALCON_COPY, PHALCON_NO_CTOR TSRMLS_CC); goto fes_e7f0_2; } } PHALCON_INIT_VAR(r10); PHALCON_INIT_VAR(r11); PHALCON_INIT_VAR(r12); phalcon_array_fetch(&r12, values, i, PHALCON_NOISY TSRMLS_CC); PHALCON_CALL_METHOD_PARAMS_1(r11, this_ptr, "escapestring", r12, PHALCON_NO_CHECK); PHALCON_CONCAT_SVS(r10, "'", r11, "'"); phalcon_array_update(&values, i, &r10, PHALCON_SEPARATE_PLZ, PHALCON_COPY, PHALCON_NO_CTOR TSRMLS_CC); } PHALCON_INIT_VAR(r13); PHALCON_INIT_VAR(r14); phalcon_array_fetch(&r14, values, i, PHALCON_NOISY TSRMLS_CC); PHALCON_CONCAT_VSV(r13, field, " = ", r14); phalcon_array_append(&update_values, r13, PHALCON_SEPARATE_PLZ TSRMLS_CC); PHALCON_SEPARATE(i); increment_function(i); zend_hash_move_forward_ex(ah0, &hp0); goto fes_e7f0_2; fee_e7f0_2: if(0){} } else { return; } PHALCON_INIT_VAR(c0); ZVAL_STRING(c0, ", ", 1); PHALCON_ALLOC_ZVAL_MM(r15); phalcon_fast_join(r15, c0, update_values TSRMLS_CC); phalcon_concat_self(&update_sql, r15 TSRMLS_CC); PHALCON_INIT_VAR(t0); ZVAL_NULL(t0); PHALCON_INIT_VAR(r16); is_not_equal_function(r16, where_condition, t0 TSRMLS_CC); if (zend_is_true(r16)) { PHALCON_ALLOC_ZVAL_MM(r17); PHALCON_CONCAT_SV(r17, " WHERE ", where_condition); phalcon_concat_self(&update_sql, r17 TSRMLS_CC); } PHALCON_ALLOC_ZVAL_MM(r18); PHALCON_CALL_METHOD_PARAMS_1(r18, this_ptr, "query", update_sql, PHALCON_NO_CHECK); PHALCON_RETURN_DZVAL(r18); }
static int phalcon_cache_shmemory_add_impl(zend_string *prefix, zend_string *key, zval *value, int ttl, int add) /* {{{ */ { int ret = 0, flag = Z_TYPE_P(value); char *msg; time_t tv; zend_string *prefix_key; if ((ZSTR_LEN(key) + prefix->len) > PHALCON_CACHE_SHMEMORY_STORAGE_MAX_KEY_LEN) { php_error_docref(NULL, E_WARNING, "Key%s can not be longer than %d bytes", prefix->len? "(include prefix)" : "", PHALCON_CACHE_SHMEMORY_STORAGE_MAX_KEY_LEN); return ret; } if (prefix->len) { prefix_key = strpprintf(PHALCON_CACHE_SHMEMORY_STORAGE_MAX_KEY_LEN, "%s%s", ZSTR_VAL(prefix), ZSTR_VAL(key)); key = prefix_key; } tv = time(NULL); switch (Z_TYPE_P(value)) { case IS_NULL: case IS_TRUE: case IS_FALSE: ret = phalcon_cache_shmemory_storage_update(ZSTR_VAL(key), ZSTR_LEN(key), (char *)&flag, sizeof(int), flag, ttl, add, tv); break; case IS_LONG: ret = phalcon_cache_shmemory_storage_update(ZSTR_VAL(key), ZSTR_LEN(key), (char *)&Z_LVAL_P(value), sizeof(long), flag, ttl, add, tv); break; case IS_DOUBLE: ret = phalcon_cache_shmemory_storage_update(ZSTR_VAL(key), ZSTR_LEN(key), (char *)&Z_DVAL_P(value), sizeof(double), flag, ttl, add, tv); break; case IS_STRING: case IS_CONSTANT: { if (Z_STRLEN_P(value) > PHALCON_CACHE_SHMEMORY_STORAGE_MAX_ENTRY_LEN) { php_error_docref(NULL, E_WARNING, "Value is too long(%d bytes) to be stored", Z_STRLEN_P(value)); if (prefix->len) { zend_string_release(prefix_key); } return ret; } else { ret = phalcon_cache_shmemory_storage_update(ZSTR_VAL(key), ZSTR_LEN(key), Z_STRVAL_P(value), Z_STRLEN_P(value), flag, ttl, add, tv); } } break; case IS_ARRAY: case IS_OBJECT: { smart_str buf = {0}; if (phalcon_cache_shmemory_serializer_php_pack(value, &buf, &msg)) { if (buf.s->len > PHALCON_CACHE_SHMEMORY_STORAGE_MAX_ENTRY_LEN) { php_error_docref(NULL, E_WARNING, "Value is too big to be stored"); if (prefix->len) { zend_string_release(prefix_key); } return ret; } else { ret = phalcon_cache_shmemory_storage_update(ZSTR_VAL(key), ZSTR_LEN(key), ZSTR_VAL(buf.s), ZSTR_LEN(buf.s), flag, ttl, add, tv); } smart_str_free(&buf); } else { php_error_docref(NULL, E_WARNING, "Serialization failed"); smart_str_free(&buf); } } break; case IS_RESOURCE: php_error_docref(NULL, E_WARNING, "Type 'IS_RESOURCE' cannot be stored"); break; default: php_error_docref(NULL, E_WARNING, "Unsupported valued type to be stored '%d'", flag); break; } if (prefix->len) { zend_string_release(prefix_key); } return ret; }
/** * Returns a MongoDb collection based on the backend parameters * * @return MongoCollection */ PHP_METHOD(Phalcon_Cache_Backend_Mongo, _getCollection){ zval *mongo_collection, *mongo_database = NULL; zend_class_entry *ce0; PHALCON_MM_GROW(); mongo_collection = phalcon_fetch_nproperty_this(this_ptr, SL("_collection"), PH_NOISY TSRMLS_CC); if (Z_TYPE_P(mongo_collection) != IS_OBJECT) { zval *options, *mongo; zval *server = NULL, *database = NULL, *collection = NULL; options = phalcon_fetch_nproperty_this(this_ptr, SL("_options"), PH_NOISY TSRMLS_CC); /** * If mongo is defined a valid Mongo object must be passed */ if (phalcon_array_isset_string_fetch(&mongo, options, SS("mongo"))) { if (Z_TYPE_P(mongo) != IS_OBJECT) { PHALCON_THROW_EXCEPTION_STR(phalcon_cache_exception_ce, "The 'mongo' parameter must be a valid Mongo instance"); return; } } else { /** * Server must be defined otherwise */ phalcon_array_isset_string_fetch(&server, options, SS("server")); if (!server || Z_TYPE_P(server) != IS_STRING) { PHALCON_THROW_EXCEPTION_STR(phalcon_cache_exception_ce, "The backend requires a valid MongoDB connection string"); return; } ce0 = zend_fetch_class(SL("Mongo"), ZEND_FETCH_CLASS_AUTO TSRMLS_CC); PHALCON_INIT_VAR(mongo); object_init_ex(mongo, ce0); assert(phalcon_has_constructor(mongo TSRMLS_CC)); PHALCON_CALL_METHOD(NULL, mongo, "__construct", server); } /** * Check if the database name is a string */ phalcon_array_isset_string_fetch(&database, options, SS("db")); if (!database || Z_TYPE_P(database) != IS_STRING) { PHALCON_THROW_EXCEPTION_STR(phalcon_cache_exception_ce, "The backend requires a valid MongoDB db"); return; } /** * Retrieve the connection name */ phalcon_array_isset_string_fetch(&collection, options, SS("collection")); if (!collection || Z_TYPE_P(collection) != IS_STRING) { PHALCON_THROW_EXCEPTION_STR(phalcon_cache_exception_ce, "The backend requires a valid MongoDB collection"); return; } /** * Make the connection and get the collection */ PHALCON_CALL_METHOD(&mongo_database, mongo, "selectdb", database); PHALCON_RETURN_CALL_METHOD(mongo_database, "selectcollection", collection); } else { RETVAL_ZVAL(mongo_collection, 1, 0); } PHALCON_MM_RESTORE(); }
/** * Builds HTML IMG tags * * @param array $parameters * @return string */ PHP_METHOD(Phalcon_Tag, image){ zval *parameters = NULL, *params = NULL, *first_param = NULL, *url = NULL, *src = NULL; zval *code = NULL, *value = NULL, *key = NULL, *attribute = NULL; zval *r0 = NULL; zval *t0 = NULL; HashTable *ah0; HashPosition hp0; zval **hd; char *hash_index; uint hash_index_len; ulong hash_num; int hash_type; int eval_int; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|z", ¶meters) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } if (!parameters) { PHALCON_ALLOC_ZVAL_MM(parameters); ZVAL_NULL(parameters); } if (Z_TYPE_P(parameters) != IS_ARRAY) { PHALCON_INIT_VAR(params); array_init(params); phalcon_array_append(¶ms, parameters, PH_SEPARATE TSRMLS_CC); } else { PHALCON_CPY_WRT(params, parameters); } eval_int = phalcon_array_isset_string(params, SL("src")+1); if (!eval_int) { eval_int = phalcon_array_isset_long(params, 0); if (eval_int) { PHALCON_INIT_VAR(first_param); phalcon_array_fetch_long(&first_param, params, 0, PH_NOISY_CC); phalcon_array_update_string(¶ms, SL("src"), &first_param, PH_COPY | PH_SEPARATE TSRMLS_CC); } else { phalcon_array_update_string_string(¶ms, SL("src"), SL(""), PH_SEPARATE TSRMLS_CC); } } PHALCON_INIT_VAR(url); PHALCON_CALL_SELF(url, this_ptr, "geturlservice"); PHALCON_ALLOC_ZVAL_MM(r0); phalcon_array_fetch_string(&r0, params, SL("src"), PH_NOISY_CC); PHALCON_INIT_VAR(src); PHALCON_CALL_METHOD_PARAMS_1(src, url, "get", r0, PH_NO_CHECK); phalcon_array_update_string(¶ms, SL("src"), &src, PH_COPY | PH_SEPARATE TSRMLS_CC); PHALCON_INIT_VAR(code); ZVAL_STRING(code, "<img", 1); if (!phalcon_valid_foreach(params TSRMLS_CC)) { return; } ah0 = Z_ARRVAL_P(params); zend_hash_internal_pointer_reset_ex(ah0, &hp0); fes_9b93_8: if(zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) != SUCCESS){ goto fee_9b93_8; } PHALCON_INIT_VAR(key); PHALCON_GET_FOREACH_KEY(key, ah0, hp0); PHALCON_INIT_VAR(value); ZVAL_ZVAL(value, *hd, 1, 0); if (Z_TYPE_P(key) != IS_LONG) { PHALCON_INIT_VAR(attribute); PHALCON_CONCAT_SVSVS(attribute, " ", key, "=\"", value, "\""); phalcon_concat_self(&code, attribute TSRMLS_CC); } zend_hash_move_forward_ex(ah0, &hp0); goto fes_9b93_8; fee_9b93_8: PHALCON_INIT_VAR(t0); ZVAL_STRING(t0, "/>", 1); phalcon_concat_self(&code, t0 TSRMLS_CC); RETURN_CTOR(code); }
/** * Stores cached content into the Mongo backend and stops the frontend * * @param int|string $keyName * @param string $content * @param long $lifetime * @param boolean $stopBuffer */ PHP_METHOD(Phalcon_Cache_Backend_Mongo, save){ zval *key_name = NULL, *content = NULL, *lifetime = NULL, *stop_buffer = NULL; zval *last_key, *frontend, *cached_content = NULL; zval *prepared_content = NULL, *ttl = NULL, *collection = NULL, *timestamp; zval *conditions, *document = NULL, *data, *is_buffering = NULL; PHALCON_MM_GROW(); phalcon_fetch_params(1, 0, 4, &key_name, &content, &lifetime, &stop_buffer); if (!key_name || Z_TYPE_P(key_name) == IS_NULL) { last_key = phalcon_fetch_nproperty_this(this_ptr, SL("_lastKey"), PH_NOISY TSRMLS_CC); } else { zval *prefix = phalcon_fetch_nproperty_this(this_ptr, SL("_prefix"), PH_NOISY TSRMLS_CC); PHALCON_INIT_VAR(last_key); PHALCON_CONCAT_VV(last_key, prefix, key_name); } if (!zend_is_true(last_key)) { PHALCON_THROW_EXCEPTION_STR(phalcon_cache_exception_ce, "The cache must be started first"); return; } frontend = phalcon_fetch_nproperty_this(this_ptr, SL("_frontend"), PH_NOISY TSRMLS_CC); if (!content || Z_TYPE_P(content) == IS_NULL) { PHALCON_CALL_METHOD(&cached_content, frontend, "getcontent"); } else { cached_content = content; } if (!phalcon_is_numeric(cached_content)) { PHALCON_CALL_METHOD(&prepared_content, frontend, "beforestore", cached_content); } if (!lifetime || Z_TYPE_P(lifetime) == IS_NULL) { zval *tmp = phalcon_fetch_nproperty_this(this_ptr, SL("_lastLifetime"), PH_NOISY TSRMLS_CC); if (Z_TYPE_P(tmp) == IS_NULL) { PHALCON_CALL_METHOD(&ttl, frontend, "getlifetime"); } else { ttl = tmp; } } else { ttl = lifetime; } PHALCON_CALL_METHOD(&collection, this_ptr, "_getcollection"); PHALCON_INIT_VAR(timestamp); ZVAL_LONG(timestamp, (long) time(NULL) + phalcon_get_intval(ttl)); PHALCON_INIT_VAR(conditions); array_init_size(conditions, 1); phalcon_array_update_string(&conditions, SL("key"), last_key, PH_COPY); PHALCON_CALL_METHOD(&document, collection, "findone", conditions); if (Z_TYPE_P(document) == IS_ARRAY) { phalcon_array_update_string(&document, SL("time"), timestamp, PH_COPY); if (prepared_content) { phalcon_array_update_string(&document, SL("data"), prepared_content, PH_COPY); } else { phalcon_array_update_string(&document, SL("data"), cached_content, PH_COPY); } PHALCON_CALL_METHOD(NULL, collection, "save", document); } else { PHALCON_INIT_VAR(data); array_init_size(data, 3); phalcon_array_update_string(&data, SL("key"), last_key, PH_COPY); phalcon_array_update_string(&data, SL("time"), timestamp, PH_COPY); if (prepared_content) { phalcon_array_update_string(&data, SL("data"), prepared_content, PH_COPY); } else { phalcon_array_update_string(&data, SL("data"), cached_content, PH_COPY); } PHALCON_CALL_METHOD(NULL, collection, "save", data); } PHALCON_CALL_METHOD(&is_buffering, frontend, "isbuffering"); if (!stop_buffer || PHALCON_IS_TRUE(stop_buffer)) { PHALCON_CALL_METHOD(NULL, frontend, "stop"); } if (PHALCON_IS_TRUE(is_buffering)) { zend_print_zval(cached_content, 0); } phalcon_update_property_bool(this_ptr, SL("_started"), 0 TSRMLS_CC); PHALCON_MM_RESTORE(); }
/** * Builds a HTML input[type="submit"] tag * * @param array $params * @return string */ PHP_METHOD(Phalcon_Tag, submitButton){ zval *parameters = NULL, *params = NULL, *value = NULL, *code = NULL, *avalue = NULL; zval *key = NULL, *attribute = NULL; zval *t0 = NULL; HashTable *ah0; HashPosition hp0; zval **hd; char *hash_index; uint hash_index_len; ulong hash_num; int hash_type; int eval_int; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", ¶meters) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } if (Z_TYPE_P(parameters) != IS_ARRAY) { PHALCON_INIT_VAR(params); array_init(params); phalcon_array_append(¶ms, parameters, PH_SEPARATE TSRMLS_CC); } else { PHALCON_CPY_WRT(params, parameters); } eval_int = phalcon_array_isset_string(params, SL("value")+1); if (eval_int) { PHALCON_INIT_VAR(value); phalcon_array_fetch_string(&value, params, SL("value"), PH_NOISY_CC); PHALCON_SEPARATE(params); phalcon_array_unset_string(params, SL("value")+1); } else { eval_int = phalcon_array_isset_long(params, 0); if (eval_int) { PHALCON_INIT_VAR(value); phalcon_array_fetch_long(&value, params, 0, PH_NOISY_CC); } else { PHALCON_INIT_VAR(value); ZVAL_STRING(value, "", 1); } } PHALCON_INIT_VAR(code); PHALCON_CONCAT_SVS(code, "<input type=\"submit\" value=\"", value, "\" "); if (!phalcon_valid_foreach(params TSRMLS_CC)) { return; } ah0 = Z_ARRVAL_P(params); zend_hash_internal_pointer_reset_ex(ah0, &hp0); fes_9b93_3: if(zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) != SUCCESS){ goto fee_9b93_3; } PHALCON_INIT_VAR(key); PHALCON_GET_FOREACH_KEY(key, ah0, hp0); PHALCON_INIT_VAR(avalue); ZVAL_ZVAL(avalue, *hd, 1, 0); if (Z_TYPE_P(key) != IS_LONG) { PHALCON_INIT_VAR(attribute); PHALCON_CONCAT_VSVS(attribute, key, "=\"", avalue, "\" "); phalcon_concat_self(&code, attribute TSRMLS_CC); } zend_hash_move_forward_ex(ah0, &hp0); goto fes_9b93_3; fee_9b93_3: PHALCON_INIT_VAR(t0); ZVAL_STRING(t0, " />", 1); phalcon_concat_self(&code, t0 TSRMLS_CC); RETURN_CTOR(code); }
/** * Gets variable from $_GET superglobal applying filters if needed * If no parameters are given the $_GET superglobal is returned * *<code> * //Returns value from $_GET["id"] without sanitizing * $id = $request->getQuery("id"); * * //Returns value from $_GET["id"] with sanitizing * $id = $request->getQuery("id", "int"); * * //Returns value from $_GET["id"] with a default value * $id = $request->getQuery("id", null, 150); *</code> * * @param string $name * @param string|array $filters * @param mixed $defaultValue * @return mixed */ PHP_METHOD(Phalcon_Http_Request, getQuery){ zval *name = NULL, *filters = NULL, *default_value = NULL, *get = NULL, *_GET; zval *value, *filter = NULL, *dependency_injector, *service; PHALCON_MM_GROW(); phalcon_fetch_params(1, 0, 3, &name, &filters, &default_value); if (!name) { PHALCON_INIT_VAR(name); } if (!filters) { PHALCON_INIT_VAR(filters); } if (!default_value) { PHALCON_INIT_VAR(default_value); } phalcon_get_global(&_GET, SS("_GET") TSRMLS_CC); PHALCON_CPY_WRT(get, _GET); if (Z_TYPE_P(name) != IS_NULL) { if (phalcon_array_isset(get, name)) { PHALCON_OBS_VAR(value); phalcon_array_fetch(&value, get, name, PH_NOISY); if (Z_TYPE_P(filters) != IS_NULL) { PHALCON_OBS_VAR(filter); phalcon_read_property_this(&filter, this_ptr, SL("_filter"), PH_NOISY_CC); if (Z_TYPE_P(filter) != IS_OBJECT) { PHALCON_OBS_VAR(dependency_injector); phalcon_read_property_this(&dependency_injector, this_ptr, SL("_dependencyInjector"), PH_NOISY_CC); if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { PHALCON_THROW_EXCEPTION_STR(phalcon_http_request_exception_ce, "A dependency injection object is required to access the 'filter' service"); return; } PHALCON_INIT_VAR(service); ZVAL_STRING(service, "filter", 1); PHALCON_INIT_NVAR(filter); phalcon_call_method_p1(filter, dependency_injector, "getshared", service); phalcon_update_property_this(this_ptr, SL("_filter"), filter TSRMLS_CC); } phalcon_call_method_p2(return_value, filter, "sanitize", value, filters); RETURN_MM(); } else { RETURN_CCTOR(value); } } RETURN_CCTOR(default_value); } RETURN_CCTOR(get); }
/** * Builds a HTML FORM tag * * @param array $parameters * @return string */ PHP_METHOD(Phalcon_Tag, form){ zval *parameters = NULL, *params = NULL, *dispatcher = NULL, *dispatch_params = NULL; zval *action_parameters = NULL, *action = NULL, *controller_name = NULL; zval *action_name = NULL, *url = NULL, *form_action = NULL, *code = NULL, *avalue = NULL; zval *key = NULL, *attribute = NULL; zval *c0 = NULL; zval *r0 = NULL, *r1 = NULL, *r2 = NULL, *r3 = NULL; HashTable *ah0; HashPosition hp0; zval **hd; char *hash_index; uint hash_index_len; ulong hash_num; int hash_type; int eval_int; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|z", ¶meters) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } if (!parameters) { PHALCON_ALLOC_ZVAL_MM(parameters); ZVAL_NULL(parameters); } if (Z_TYPE_P(parameters) != IS_ARRAY) { PHALCON_INIT_VAR(params); array_init(params); phalcon_array_append(¶ms, parameters, PH_SEPARATE TSRMLS_CC); } else { PHALCON_CPY_WRT(params, parameters); } PHALCON_INIT_VAR(dispatcher); PHALCON_CALL_SELF(dispatcher, this_ptr, "getdispatcherservice"); PHALCON_INIT_VAR(dispatch_params); PHALCON_CALL_METHOD(dispatch_params, dispatcher, "getparams", PH_NO_CHECK); PHALCON_INIT_VAR(c0); ZVAL_STRING(c0, "/", 1); PHALCON_INIT_VAR(action_parameters); phalcon_fast_join(action_parameters, c0, dispatch_params TSRMLS_CC); eval_int = phalcon_array_isset_long(params, 0); if (!eval_int) { eval_int = phalcon_array_isset_string(params, SL("action")+1); if (eval_int) { PHALCON_INIT_VAR(action); phalcon_array_fetch_string(&action, params, SL("action"), PH_NOISY_CC); } else { PHALCON_INIT_VAR(controller_name); PHALCON_CALL_METHOD(controller_name, dispatcher, "getcontrollername", PH_NO_CHECK); PHALCON_INIT_VAR(action_name); PHALCON_CALL_METHOD(action_name, dispatcher, "getactionname", PH_NO_CHECK); PHALCON_INIT_VAR(action); PHALCON_CONCAT_VSV(action, controller_name, "/", action_name); } } else { PHALCON_INIT_VAR(action); phalcon_array_fetch_long(&action, params, 0, PH_NOISY_CC); } eval_int = phalcon_array_isset_string(params, SL("method")+1); if (!eval_int) { phalcon_array_update_string_string(¶ms, SL("method"), SL("post"), PH_SEPARATE TSRMLS_CC); } PHALCON_INIT_VAR(url); PHALCON_CALL_SELF(url, this_ptr, "geturlservice"); if (zend_is_true(action_parameters)) { PHALCON_ALLOC_ZVAL_MM(r0); PHALCON_CALL_METHOD_PARAMS_1(r0, url, "get", action, PH_NO_CHECK); PHALCON_CPY_WRT(action, r0); } else { PHALCON_INIT_VAR(form_action); PHALCON_CONCAT_VSV(form_action, action, "/", action_parameters); PHALCON_INIT_VAR(action); PHALCON_CALL_METHOD_PARAMS_1(action, url, "get", form_action, PH_NO_CHECK); } eval_int = phalcon_array_isset_string(params, SL("parameters")+1); if (eval_int) { PHALCON_ALLOC_ZVAL_MM(r1); phalcon_array_fetch_string(&r1, params, SL("parameters"), PH_NOISY_CC); PHALCON_ALLOC_ZVAL_MM(r2); PHALCON_CONCAT_SV(r2, "?", r1); phalcon_concat_self(&action, r2 TSRMLS_CC); } PHALCON_INIT_VAR(code); PHALCON_CONCAT_SVS(code, "<form action=\"", action, "\" "); if (!phalcon_valid_foreach(params TSRMLS_CC)) { return; } ah0 = Z_ARRVAL_P(params); zend_hash_internal_pointer_reset_ex(ah0, &hp0); fes_9b93_5: if(zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) != SUCCESS){ goto fee_9b93_5; } PHALCON_INIT_VAR(key); PHALCON_GET_FOREACH_KEY(key, ah0, hp0); PHALCON_INIT_VAR(avalue); ZVAL_ZVAL(avalue, *hd, 1, 0); if (Z_TYPE_P(key) != IS_LONG) { PHALCON_INIT_VAR(attribute); PHALCON_CONCAT_VSVS(attribute, key, "= \"", avalue, "\" "); phalcon_concat_self(&code, attribute TSRMLS_CC); } zend_hash_move_forward_ex(ah0, &hp0); goto fes_9b93_5; fee_9b93_5: PHALCON_ALLOC_ZVAL_MM(r3); PHALCON_CONCAT_VS(r3, code, ">"); RETURN_CTOR(r3); }
int msgpack_unserialize_map_item( msgpack_unserialize_data *unpack, zval **container, zval *key, zval *val) { long deps; TSRMLS_FETCH(); if (MSGPACK_G(php_only)) { zend_class_entry *ce; if (Z_TYPE_P(key) == IS_NULL) { unpack->type = MSGPACK_SERIALIZE_TYPE_NONE; if (Z_TYPE_P(val) == IS_LONG) { switch (Z_LVAL_P(val)) { case MSGPACK_SERIALIZE_TYPE_REFERENCE: Z_SET_ISREF_PP(container); break; case MSGPACK_SERIALIZE_TYPE_RECURSIVE: unpack->type = MSGPACK_SERIALIZE_TYPE_RECURSIVE; break; case MSGPACK_SERIALIZE_TYPE_CUSTOM_OBJECT: unpack->type = MSGPACK_SERIALIZE_TYPE_CUSTOM_OBJECT; break; case MSGPACK_SERIALIZE_TYPE_OBJECT_REFERENCE: unpack->type = MSGPACK_SERIALIZE_TYPE_OBJECT_REFERENCE; break; case MSGPACK_SERIALIZE_TYPE_OBJECT: unpack->type = MSGPACK_SERIALIZE_TYPE_OBJECT; break; default: break; } } else if (Z_TYPE_P(val) == IS_STRING) { ce = msgpack_unserialize_class( container, Z_STRVAL_P(val), Z_STRLEN_P(val)); if (ce == NULL) { MSGPACK_UNSERIALIZE_FINISH_MAP_ITEM(unpack, key, val); return 0; } } MSGPACK_UNSERIALIZE_FINISH_MAP_ITEM(unpack, key, val); return 0; } else { switch (unpack->type) { case MSGPACK_SERIALIZE_TYPE_CUSTOM_OBJECT: unpack->type = MSGPACK_SERIALIZE_TYPE_NONE; ce = msgpack_unserialize_class( container, Z_STRVAL_P(key), Z_STRLEN_P(key)); if (ce == NULL) { MSGPACK_UNSERIALIZE_FINISH_MAP_ITEM(unpack, key, val); return 0; } #if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION > 0) /* implementing Serializable */ if (ce->unserialize == NULL) { MSGPACK_WARNING( "[msgpack] (%s) Class %s has no unserializer", __FUNCTION__, ce->name); MSGPACK_UNSERIALIZE_FINISH_MAP_ITEM(unpack, key, val); return 0; } ce->unserialize( container, ce, (const unsigned char *)Z_STRVAL_P(val), Z_STRLEN_P(val) + 1, NULL TSRMLS_CC); #endif MSGPACK_UNSERIALIZE_FINISH_MAP_ITEM(unpack, key, val); return 0; case MSGPACK_SERIALIZE_TYPE_RECURSIVE: case MSGPACK_SERIALIZE_TYPE_OBJECT: case MSGPACK_SERIALIZE_TYPE_OBJECT_REFERENCE: { zval **rval; int type = unpack->type; unpack->type = MSGPACK_SERIALIZE_TYPE_NONE; if (msgpack_var_access( unpack->var_hash, Z_LVAL_P(val) - 1, &rval) != SUCCESS) { MSGPACK_WARNING( "[msgpack] (%s) Invalid references value: %ld", __FUNCTION__, Z_LVAL_P(val) - 1); MSGPACK_UNSERIALIZE_FINISH_MAP_ITEM(unpack, key, val); return 0; } if (container != NULL) { zval_ptr_dtor(container); } *container = *rval; Z_ADDREF_PP(container); if (type == MSGPACK_SERIALIZE_TYPE_OBJECT) { Z_UNSET_ISREF_PP(container); } else if (type == MSGPACK_SERIALIZE_TYPE_OBJECT_REFERENCE) { Z_SET_ISREF_PP(container); } MSGPACK_UNSERIALIZE_FINISH_MAP_ITEM(unpack, key, val); return 0; } } } } if (Z_TYPE_PP(container) != IS_ARRAY && Z_TYPE_PP(container) != IS_OBJECT) { array_init(*container); } switch (Z_TYPE_P(key)) { case IS_LONG: if (zend_hash_index_update( HASH_OF(*container), Z_LVAL_P(key), &val, sizeof(val), NULL) == FAILURE) { zval_ptr_dtor(&val); MSGPACK_WARNING( "[msgpack] (%s) illegal offset type, skip this decoding", __FUNCTION__); } break; case IS_STRING: if (zend_symtable_update( HASH_OF(*container), Z_STRVAL_P(key), Z_STRLEN_P(key) + 1, &val, sizeof(val), NULL) == FAILURE) { zval_ptr_dtor(&val); MSGPACK_WARNING( "[msgpack] (%s) illegal offset type, skip this decoding", __FUNCTION__); } break; default: zval_ptr_dtor(&val); MSGPACK_WARNING( "[msgpack] (%s) illegal offset type, skip this decoding", __FUNCTION__); break; } zval_ptr_dtor(&key); msgpack_stack_pop(unpack->var_hash, 2); deps = unpack->deps - 1; unpack->stack[deps]--; if (unpack->stack[deps] == 0) { unpack->deps--; /* wakeup */ if (MSGPACK_G(php_only) && Z_TYPE_PP(container) == IS_OBJECT && Z_OBJCE_PP(container) != PHP_IC_ENTRY && zend_hash_exists( &Z_OBJCE_PP(container)->function_table, "__wakeup", sizeof("__wakeup"))) { zval f, *h = NULL; INIT_PZVAL(&f); ZVAL_STRINGL(&f, "__wakeup", sizeof("__wakeup") - 1, 0); call_user_function_ex( CG(function_table), container, &f, &h, 0, 0, 1, NULL TSRMLS_CC); if (h) { zval_ptr_dtor(&h); } } } return 0; }
/** * Stores cached content into the XCache backend and stops the frontend * * @param string $keyName * @param string $content * @param long $lifetime * @param boolean $stopBuffer */ PHP_METHOD(Phalcon_Cache_Backend_Xcache, save){ zval *key_name = NULL, *content = NULL, *lifetime = NULL, *stop_buffer = NULL; zval *last_key = NULL, *prefix, *frontend, *cached_content = NULL; zval *prepared_content, *ttl = NULL, *success, *is_buffering; zval *options, *special_key, *keys = NULL, *zero; PHALCON_MM_GROW(); phalcon_fetch_params(1, 0, 4, &key_name, &content, &lifetime, &stop_buffer); if (!key_name) { PHALCON_INIT_VAR(key_name); } if (!content) { PHALCON_INIT_VAR(content); } if (!lifetime) { PHALCON_INIT_VAR(lifetime); } if (!stop_buffer) { PHALCON_INIT_VAR(stop_buffer); ZVAL_BOOL(stop_buffer, 1); } if (Z_TYPE_P(key_name) == IS_NULL) { PHALCON_OBS_VAR(last_key); phalcon_read_property_this(&last_key, this_ptr, SL("_lastKey"), PH_NOISY_CC); } else { PHALCON_OBS_VAR(prefix); phalcon_read_property_this(&prefix, this_ptr, SL("_prefix"), PH_NOISY_CC); PHALCON_INIT_NVAR(last_key); PHALCON_CONCAT_SVV(last_key, "_PHCX", prefix, key_name); } if (!zend_is_true(last_key)) { PHALCON_THROW_EXCEPTION_STR(phalcon_cache_exception_ce, "The cache must be started first"); return; } PHALCON_OBS_VAR(frontend); phalcon_read_property_this(&frontend, this_ptr, SL("_frontend"), PH_NOISY_CC); if (Z_TYPE_P(content) == IS_NULL) { PHALCON_INIT_VAR(cached_content); phalcon_call_method(cached_content, frontend, "getcontent"); } else { PHALCON_CPY_WRT(cached_content, content); } PHALCON_INIT_VAR(prepared_content); phalcon_call_method_p1(prepared_content, frontend, "beforestore", cached_content); /** * Take the lifetime from the frontend or read it from the set in start() */ if (Z_TYPE_P(lifetime) == IS_NULL) { PHALCON_OBS_NVAR(ttl); phalcon_read_property_this(&ttl, this_ptr, SL("_lastLifetime"), PH_NOISY_CC); if (Z_TYPE_P(ttl) == IS_NULL) { PHALCON_INIT_NVAR(ttl); phalcon_call_method(ttl, frontend, "getlifetime"); } } else { PHALCON_CPY_WRT(ttl, lifetime); } /** * Call xcache_set in the PHP userland since most of the time it isn't available at * compile time */ PHALCON_INIT_VAR(success); phalcon_call_func_p3(success, "xcache_set", last_key, prepared_content, ttl); PHALCON_INIT_VAR(is_buffering); phalcon_call_method(is_buffering, frontend, "isbuffering"); if (PHALCON_IS_TRUE(stop_buffer)) { phalcon_call_method_noret(frontend, "stop"); } if (PHALCON_IS_TRUE(is_buffering)) { zend_print_zval(cached_content, 0); } phalcon_update_property_bool(this_ptr, SL("_started"), 0 TSRMLS_CC); /** * xcache_set() could fail because of Out of Memory condition. I don't think it is * appropriate to throw an exception here (like * Phalcon\Cache\Backend\Memcache::save() does): first, to be consistent with * Phalcon\Cache\Backend\Apc::save(), second, because xCache is usually given much * less RAM than memcached */ if (zend_is_true(success)) { PHALCON_OBS_VAR(options); phalcon_read_property_this(&options, this_ptr, SL("_options"), PH_NOISY_CC); PHALCON_OBS_VAR(special_key); phalcon_array_fetch_string(&special_key, options, SL("statsKey"), PH_NOISY); /** * xcache_list() is available only to the administrator (unless XCache was * patched). We have to update the list of the stored keys. */ PHALCON_INIT_VAR(keys); phalcon_call_func_p1(keys, "xcache_get", special_key); if (Z_TYPE_P(keys) != IS_ARRAY) { PHALCON_INIT_NVAR(keys); array_init(keys); } phalcon_array_update_zval(&keys, last_key, &ttl, PH_COPY | PH_SEPARATE); PHALCON_INIT_VAR(zero); ZVAL_LONG(zero, 0); phalcon_call_func_p3_noret("xcache_set", special_key, keys, zero); } PHALCON_MM_RESTORE(); }
/** * Performs a string conversion */ PHP_METHOD(Phalcon_Mvc_View_Engine_Volt, convertEncoding) { zend_bool _0, _1; int ZEPHIR_LAST_CALL_STATUS; zval *text_param = NULL, *from_param = NULL, *to_param = NULL; zval *text = NULL, *from = NULL, *to = NULL; ZEPHIR_MM_GROW(); zephir_fetch_params(1, 3, 0, &text_param, &from_param, &to_param); zephir_get_strval(text, text_param); if (unlikely(Z_TYPE_P(from_param) != IS_STRING && Z_TYPE_P(from_param) != IS_NULL)) { zephir_throw_exception_string(spl_ce_InvalidArgumentException, SL("Parameter 'from' must be a string") TSRMLS_CC); RETURN_MM_NULL(); } if (likely(Z_TYPE_P(from_param) == IS_STRING)) { zephir_get_strval(from, from_param); } else { ZEPHIR_INIT_VAR(from); ZVAL_EMPTY_STRING(from); } if (unlikely(Z_TYPE_P(to_param) != IS_STRING && Z_TYPE_P(to_param) != IS_NULL)) { zephir_throw_exception_string(spl_ce_InvalidArgumentException, SL("Parameter 'to' must be a string") TSRMLS_CC); RETURN_MM_NULL(); } if (likely(Z_TYPE_P(to_param) == IS_STRING)) { zephir_get_strval(to, to_param); } else { ZEPHIR_INIT_VAR(to); ZVAL_EMPTY_STRING(to); } _0 = ZEPHIR_IS_STRING(from, "latin1"); if (!(_0)) { _0 = ZEPHIR_IS_STRING(to, "utf8"); } if (_0) { ZEPHIR_RETURN_CALL_FUNCTION("utf8_encode", NULL, 371, text); zephir_check_call_status(); RETURN_MM(); } _1 = ZEPHIR_IS_STRING(to, "latin1"); if (!(_1)) { _1 = ZEPHIR_IS_STRING(from, "utf8"); } if (_1) { ZEPHIR_RETURN_CALL_FUNCTION("utf8_decode", NULL, 372, text); zephir_check_call_status(); RETURN_MM(); } if ((zephir_function_exists_ex(SS("mb_convert_encoding") TSRMLS_CC) == SUCCESS)) { ZEPHIR_RETURN_CALL_FUNCTION("mb_convert_encoding", NULL, 179, text, from, to); zephir_check_call_status(); RETURN_MM(); } if ((zephir_function_exists_ex(SS("iconv") TSRMLS_CC) == SUCCESS)) { ZEPHIR_RETURN_CALL_FUNCTION("iconv", NULL, 373, from, to, text); zephir_check_call_status(); RETURN_MM(); } ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_mvc_view_exception_ce, "Any of 'mbstring' or 'iconv' is required to perform the charset conversion", "phalcon/mvc/view/engine/volt.zep", 205); return; }