/** * Returns a cached content * * @param string $keyName * @return mixed */ PHP_METHOD(Phalcon_Cache_Backend_File, get){ zval *key_name = NULL, *backend = NULL, *front_end = NULL, *sanitize_key = NULL; zval *cache_file = NULL, *time = NULL, *lifetime = NULL, *cached_content = NULL; zval *t0 = NULL, *t1 = NULL; zval *r0 = NULL, *r1 = NULL, *r2 = NULL, *r3 = NULL, *r4 = NULL, *r5 = NULL, *r6 = NULL; zval *r7 = NULL, *r8 = NULL, *r9 = NULL; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &key_name) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } PHALCON_ALLOC_ZVAL_MM(t0); phalcon_read_property(&t0, this_ptr, "_backendOptions", sizeof("_backendOptions")-1, PHALCON_NOISY TSRMLS_CC); PHALCON_CPY_WRT(backend, t0); PHALCON_ALLOC_ZVAL_MM(t1); phalcon_read_property(&t1, this_ptr, "_frontendObject", sizeof("_frontendObject")-1, PHALCON_NOISY TSRMLS_CC); PHALCON_CPY_WRT(front_end, t1); PHALCON_ALLOC_ZVAL_MM(r0); phalcon_filter_alphanum(r0, key_name); PHALCON_CPY_WRT(sanitize_key, r0); phalcon_update_property_zval(this_ptr, "_lastKey", strlen("_lastKey"), sanitize_key TSRMLS_CC); PHALCON_ALLOC_ZVAL_MM(r1); phalcon_array_fetch_string(&r1, backend, "cacheDir", strlen("cacheDir"), PHALCON_NOISY TSRMLS_CC); PHALCON_ALLOC_ZVAL_MM(r2); concat_function(r2, r1, sanitize_key TSRMLS_CC); PHALCON_CPY_WRT(cache_file, r2); if (phalcon_file_exists(cache_file TSRMLS_CC) == SUCCESS) { PHALCON_ALLOC_ZVAL_MM(r3); PHALCON_CALL_FUNC(r3, "time", 0x018); PHALCON_CPY_WRT(time, r3); PHALCON_ALLOC_ZVAL_MM(r4); PHALCON_CALL_METHOD(r4, front_end, "getlifetime", PHALCON_NO_CHECK); PHALCON_CPY_WRT(lifetime, r4); PHALCON_ALLOC_ZVAL_MM(r5); sub_function(r5, time, lifetime TSRMLS_CC); PHALCON_ALLOC_ZVAL_MM(r6); PHALCON_CALL_FUNC_PARAMS_1(r6, "filemtime", cache_file, 0x019); PHALCON_INIT_VAR(r7); is_smaller_function(r7, r5, r6 TSRMLS_CC); if (zend_is_true(r7)) { PHALCON_ALLOC_ZVAL_MM(r8); PHALCON_CALL_FUNC_PARAMS_1(r8, "file_get_contents", cache_file, 0x01A); PHALCON_CPY_WRT(cached_content, r8); PHALCON_ALLOC_ZVAL_MM(r9); PHALCON_CALL_METHOD_PARAMS_1(r9, front_end, "afterretrieve", cached_content, PHALCON_NO_CHECK); PHALCON_RETURN_DZVAL(r9); } } PHALCON_MM_RESTORE(); RETURN_NULL(); }
/** * Generates a URL * * @param string|array $uri * @return string */ PHP_METHOD(Phalcon_Mvc_Url, get){ zval *uri = NULL, *base_uri = NULL, *dependency_injector = NULL, *service = NULL; zval *router = NULL, *route_name = NULL, *route = NULL, *exception_message = NULL; zval *exception = NULL, *pattern = NULL, *replaced_pattern = NULL; zval *controller_name = NULL, *wildcard = NULL, *action_name = NULL; zval *have_bracket = NULL, *matches = NULL, *match_position = NULL; zval *set_order = NULL, *names_pattern = NULL, *have_variables = NULL; zval *match = NULL, *match_zero = NULL, *match_one = NULL, *value = NULL, *new_pcre_pattern = NULL; zval *final_uri = NULL; zval *r0 = NULL, *r1 = NULL, *r2 = NULL; zval *t0 = NULL; zval *p0[] = { NULL, NULL, NULL, NULL }; HashTable *ah0; HashPosition hp0; zval **hd; int eval_int; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|z", &uri) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } if (!uri) { PHALCON_ALLOC_ZVAL_MM(uri); ZVAL_NULL(uri); } PHALCON_INIT_VAR(base_uri); PHALCON_CALL_METHOD(base_uri, this_ptr, "getbaseuri", PH_NO_CHECK); if (Z_TYPE_P(uri) == IS_ARRAY) { eval_int = phalcon_array_isset_string(uri, SL("for")+1); if (!eval_int) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_url_exception_ce, "It's necessary to define the route name with the parameter \"for\""); return; } PHALCON_INIT_VAR(dependency_injector); phalcon_read_property(&dependency_injector, this_ptr, SL("_dependencyInjector"), PH_NOISY_CC); if (!zend_is_true(dependency_injector)) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_url_exception_ce, "A dependency injector container is required to obtain the \"url\" service"); return; } PHALCON_INIT_VAR(service); ZVAL_STRING(service, "router", 1); PHALCON_INIT_VAR(router); PHALCON_CALL_METHOD_PARAMS_1(router, dependency_injector, "getshared", service, PH_NO_CHECK); PHALCON_INIT_VAR(route_name); phalcon_array_fetch_string(&route_name, uri, SL("for"), PH_NOISY_CC); PHALCON_INIT_VAR(route); PHALCON_CALL_METHOD_PARAMS_1(route, router, "getroutebyname", route_name, PH_NO_CHECK); if (Z_TYPE_P(route) != IS_OBJECT) { PHALCON_INIT_VAR(exception_message); PHALCON_CONCAT_SVS(exception_message, "Cannot obtain a route using the name \"", route_name, "\""); PHALCON_INIT_VAR(exception); object_init_ex(exception, phalcon_mvc_url_exception_ce); PHALCON_CALL_METHOD_PARAMS_1_NORETURN(exception, "__construct", exception_message, PH_CHECK); phalcon_throw_exception(exception TSRMLS_CC); return; } PHALCON_INIT_VAR(pattern); PHALCON_CALL_METHOD(pattern, route, "getpattern", PH_NO_CHECK); PHALCON_CPY_WRT(replaced_pattern, pattern); eval_int = phalcon_array_isset_string(uri, SL("controller")+1); if (eval_int) { PHALCON_INIT_VAR(controller_name); phalcon_array_fetch_string(&controller_name, uri, SL("controller"), PH_NOISY_CC); PHALCON_INIT_VAR(wildcard); ZVAL_STRING(wildcard, ":controller", 1); PHALCON_ALLOC_ZVAL_MM(r0); phalcon_fast_str_replace(r0, wildcard, controller_name, replaced_pattern TSRMLS_CC); PHALCON_CPY_WRT(replaced_pattern, r0); } eval_int = phalcon_array_isset_string(uri, SL("action")+1); if (eval_int) { PHALCON_INIT_VAR(action_name); phalcon_array_fetch_string(&action_name, uri, SL("action"), PH_NOISY_CC); PHALCON_INIT_VAR(wildcard); ZVAL_STRING(wildcard, ":action", 1); PHALCON_ALLOC_ZVAL_MM(r1); phalcon_fast_str_replace(r1, wildcard, action_name, replaced_pattern TSRMLS_CC); PHALCON_CPY_WRT(replaced_pattern, r1); } PHALCON_INIT_VAR(have_bracket); phalcon_fast_strpos_str(have_bracket, replaced_pattern, SL("{") TSRMLS_CC); if (Z_TYPE_P(have_bracket) != IS_BOOL || (Z_TYPE_P(have_bracket) == IS_BOOL && Z_BVAL_P(have_bracket))) { PHALCON_INIT_VAR(matches); ZVAL_NULL(matches); PHALCON_INIT_VAR(match_position); ZVAL_LONG(match_position, 1); PHALCON_INIT_VAR(t0); ZVAL_LONG(t0, 2); PHALCON_CPY_WRT(set_order, t0); PHALCON_INIT_VAR(names_pattern); ZVAL_STRING(names_pattern, "#{([a-zA-Z][a-zA-Z0-9\\_\\-]+)(:([^}]+))*}#", 1); p0[0] = names_pattern; p0[1] = replaced_pattern; Z_SET_ISREF_P(matches); p0[2] = matches; p0[3] = set_order; PHALCON_ALLOC_ZVAL_MM(r2); PHALCON_CALL_FUNC_PARAMS(r2, "preg_match_all", 4, p0); Z_UNSET_ISREF_P(p0[2]); PHALCON_CPY_WRT(have_variables, r2); if (zend_is_true(have_variables)) { if (!phalcon_valid_foreach(matches TSRMLS_CC)) { return; } ah0 = Z_ARRVAL_P(matches); zend_hash_internal_pointer_reset_ex(ah0, &hp0); fes_0306_0: if(zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) != SUCCESS){ goto fee_0306_0; } PHALCON_INIT_VAR(match); ZVAL_ZVAL(match, *hd, 1, 0); PHALCON_INIT_VAR(match_zero); phalcon_array_fetch_long(&match_zero, match, 0, PH_NOISY_CC); PHALCON_INIT_VAR(match_one); phalcon_array_fetch_long(&match_one, match, 1, PH_NOISY_CC); eval_int = phalcon_array_isset(uri, match_one); if (eval_int) { PHALCON_INIT_VAR(value); phalcon_array_fetch(&value, uri, match_one, PH_NOISY_CC); PHALCON_INIT_VAR(new_pcre_pattern); phalcon_fast_str_replace(new_pcre_pattern, match_zero, value, replaced_pattern TSRMLS_CC); PHALCON_CPY_WRT(replaced_pattern, new_pcre_pattern); } zend_hash_move_forward_ex(ah0, &hp0); goto fes_0306_0; fee_0306_0: if(0){} } } RETURN_CCTOR(replaced_pattern); } else { PHALCON_INIT_VAR(final_uri); PHALCON_CONCAT_VV(final_uri, base_uri, uri); RETURN_CTOR(final_uri); } PHALCON_MM_RESTORE(); }
/** * Replaces placeholders from pattern returning a valid PCRE regular expression * * @param string $pattern * @return string */ PHP_METHOD(Phalcon_Mvc_Router, compilePattern){ zval *pattern = NULL, *id_pattern = NULL, *compiled_pattern = NULL; zval *r0 = NULL, *r1 = NULL, *r2 = NULL, *r3 = NULL, *r4 = NULL; zval *c0 = NULL, *c1 = NULL, *c2 = NULL, *c3 = NULL, *c4 = NULL, *c5 = NULL, *c6 = NULL; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &pattern) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } PHALCON_INIT_VAR(id_pattern); ZVAL_STRING(id_pattern, "/([a-zA-Z0-9\\_]+)", 1); PHALCON_ALLOC_ZVAL_MM(r0); phalcon_fast_strpos_str(r0, pattern, SL(":") TSRMLS_CC); if (zend_is_true(r0)) { PHALCON_INIT_VAR(c0); ZVAL_STRING(c0, "/:module", 1); PHALCON_INIT_VAR(compiled_pattern); phalcon_fast_str_replace(compiled_pattern, c0, id_pattern, pattern TSRMLS_CC); PHALCON_INIT_VAR(c1); ZVAL_STRING(c1, "/:controller", 1); PHALCON_INIT_VAR(compiled_pattern); phalcon_fast_str_replace(compiled_pattern, c1, id_pattern, pattern TSRMLS_CC); PHALCON_INIT_VAR(c2); ZVAL_STRING(c2, "/:action", 1); PHALCON_ALLOC_ZVAL_MM(r1); phalcon_fast_str_replace(r1, c2, id_pattern, compiled_pattern TSRMLS_CC); PHALCON_CPY_WRT(compiled_pattern, r1); PHALCON_INIT_VAR(c3); ZVAL_STRING(c3, "/:params", 1); PHALCON_INIT_VAR(c4); ZVAL_STRING(c4, "(/.*)*", 1); PHALCON_ALLOC_ZVAL_MM(r2); phalcon_fast_str_replace(r2, c3, c4, compiled_pattern TSRMLS_CC); PHALCON_CPY_WRT(compiled_pattern, r2); PHALCON_INIT_VAR(c5); ZVAL_STRING(c5, "/:int", 1); PHALCON_INIT_VAR(c6); ZVAL_STRING(c6, "/([0-9]+)", 1); PHALCON_ALLOC_ZVAL_MM(r3); phalcon_fast_str_replace(r3, c5, c6, compiled_pattern TSRMLS_CC); PHALCON_CPY_WRT(compiled_pattern, r3); } else { PHALCON_CPY_WRT(compiled_pattern, pattern); } PHALCON_ALLOC_ZVAL_MM(r4); PHALCON_CONCAT_SVS(r4, "#^", compiled_pattern, "$#"); RETURN_CTOR(r4); }
/** * Converts bound params like :name: or ?1 into ? bind params * * @param string $sql * @param array $params * @return array */ PHP_METHOD(Phalcon_Db_Adapter_Pdo, convertBoundParams){ zval *sql = NULL, *params = NULL, *query_params = NULL, *placeholders = NULL; zval *matches = NULL, *set_order = NULL, *bind_pattern = NULL, *status = NULL; zval *place_match = NULL, *numeric_place = NULL, *value = NULL, *str_place = NULL; zval *question = NULL, *bound_sql = NULL; zval *r0 = NULL; zval *p0[] = { NULL, NULL, NULL, NULL }; HashTable *ah0; HashPosition hp0; zval **hd; int eval_int; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz", &sql, ¶ms) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } PHALCON_INIT_VAR(query_params); array_init(query_params); PHALCON_INIT_VAR(placeholders); array_init(placeholders); PHALCON_INIT_VAR(matches); ZVAL_NULL(matches); PHALCON_INIT_VAR(set_order); ZVAL_LONG(set_order, 2); PHALCON_INIT_VAR(bind_pattern); ZVAL_STRING(bind_pattern, "/\\?([0-9]+)|:([a-zA-Z0-9_]+):/", 1); p0[0] = bind_pattern; p0[1] = sql; Z_SET_ISREF_P(matches); p0[2] = matches; p0[3] = set_order; PHALCON_ALLOC_ZVAL_MM(r0); PHALCON_CALL_FUNC_PARAMS(r0, "preg_match_all", 4, p0); Z_UNSET_ISREF_P(p0[2]); PHALCON_CPY_WRT(status, r0); if (zend_is_true(status)) { if (!phalcon_valid_foreach(matches TSRMLS_CC)) { return; } ah0 = Z_ARRVAL_P(matches); zend_hash_internal_pointer_reset_ex(ah0, &hp0); ph_cycle_start_0: if(zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) != SUCCESS){ goto ph_cycle_end_0; } PHALCON_GET_FOREACH_VALUE(place_match); PHALCON_INIT_VAR(numeric_place); phalcon_array_fetch_long(&numeric_place, place_match, 1, PH_NOISY_CC); eval_int = phalcon_array_isset(params, numeric_place); if (eval_int) { PHALCON_INIT_VAR(value); phalcon_array_fetch(&value, params, numeric_place, PH_NOISY_CC); } else { eval_int = phalcon_array_isset_long(place_match, 2); if (eval_int) { PHALCON_INIT_VAR(str_place); phalcon_array_fetch_long(&str_place, place_match, 2, PH_NOISY_CC); eval_int = phalcon_array_isset(params, str_place); if (eval_int) { PHALCON_INIT_VAR(value); phalcon_array_fetch(&value, params, str_place, PH_NOISY_CC); } else { PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Matched parameter wasn't found in parameters list"); return; } } else { PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Matched parameter wasn't found in parameters list"); return; } } phalcon_array_append(&placeholders, value, PH_SEPARATE TSRMLS_CC); zend_hash_move_forward_ex(ah0, &hp0); goto ph_cycle_start_0; ph_cycle_end_0: PHALCON_INIT_VAR(question); ZVAL_STRING(question, "?", 1); PHALCON_INIT_VAR(bound_sql); PHALCON_CALL_FUNC_PARAMS_3(bound_sql, "preg_replace", bind_pattern, question, sql); } else { PHALCON_CPY_WRT(bound_sql, sql); } PHALCON_INIT_VAR(query_params); array_init(query_params); phalcon_array_update_string(&query_params, SL("sql"), &bound_sql, PH_COPY | PH_SEPARATE TSRMLS_CC); phalcon_array_update_string(&query_params, SL("params"), &placeholders, PH_COPY | PH_SEPARATE TSRMLS_CC); RETURN_CTOR(query_params); }
/** * This method is automatically called in Phalcon\Db\Adapter\Pdo constructor. * Call it when you need to restore a database connection * * @param array $descriptor * @return boolean */ PHP_METHOD(Phalcon_Db_Adapter_Pdo, connect){ zval *descriptor = NULL, *username = NULL, *password = NULL, *dsn_parts = NULL; zval *value = NULL, *key = NULL, *dsn_attribute = NULL, *dot_comma = NULL, *dsn_attributes = NULL; zval *pdo_type = NULL, *dsn = NULL, *options = NULL, *persistent = NULL, *pdo = NULL; HashTable *ah0; HashPosition hp0; zval **hd; char *hash_index; uint hash_index_len; ulong hash_num; int hash_type; int eval_int; zend_class_entry *ce0; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|z", &descriptor) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } if (!descriptor) { PHALCON_ALLOC_ZVAL_MM(descriptor); ZVAL_NULL(descriptor); } else { PHALCON_SEPARATE_PARAM(descriptor); } if (Z_TYPE_P(descriptor) == IS_NULL) { PHALCON_INIT_VAR(descriptor); phalcon_read_property(&descriptor, this_ptr, SL("_descriptor"), PH_NOISY_CC); } eval_int = phalcon_array_isset_string(descriptor, SS("username")); if (eval_int) { PHALCON_INIT_VAR(username); phalcon_array_fetch_string(&username, descriptor, SL("username"), PH_NOISY_CC); PHALCON_SEPARATE_PARAM(descriptor); phalcon_array_unset_string(descriptor, SS("username")); } else { PHALCON_INIT_VAR(username); ZVAL_NULL(username); } eval_int = phalcon_array_isset_string(descriptor, SS("password")); if (eval_int) { PHALCON_INIT_VAR(password); phalcon_array_fetch_string(&password, descriptor, SL("password"), PH_NOISY_CC); PHALCON_SEPARATE_PARAM(descriptor); phalcon_array_unset_string(descriptor, SS("password")); } else { PHALCON_INIT_VAR(password); ZVAL_NULL(password); } eval_int = phalcon_array_isset_string(descriptor, SS("dsn")); if (!eval_int) { PHALCON_INIT_VAR(dsn_parts); array_init(dsn_parts); if (!phalcon_valid_foreach(descriptor TSRMLS_CC)) { return; } ah0 = Z_ARRVAL_P(descriptor); zend_hash_internal_pointer_reset_ex(ah0, &hp0); ph_cycle_start_0: if(zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) != SUCCESS){ goto ph_cycle_end_0; } PHALCON_INIT_VAR(key); PHALCON_GET_FOREACH_KEY(key, ah0, hp0); PHALCON_GET_FOREACH_VALUE(value); PHALCON_INIT_VAR(dsn_attribute); PHALCON_CONCAT_VSV(dsn_attribute, key, "=", value); phalcon_array_append(&dsn_parts, dsn_attribute, PH_SEPARATE TSRMLS_CC); zend_hash_move_forward_ex(ah0, &hp0); goto ph_cycle_start_0; ph_cycle_end_0: PHALCON_INIT_VAR(dot_comma); ZVAL_STRING(dot_comma, ";", 1); PHALCON_INIT_VAR(dsn_attributes); phalcon_fast_join(dsn_attributes, dot_comma, dsn_parts TSRMLS_CC); } else { PHALCON_INIT_VAR(dsn_attributes); phalcon_array_fetch_string(&dsn_attributes, descriptor, SL("dsn"), PH_NOISY_CC); } PHALCON_INIT_VAR(pdo_type); phalcon_read_property(&pdo_type, this_ptr, SL("_type"), PH_NOISY_CC); PHALCON_INIT_VAR(dsn); PHALCON_CONCAT_VSV(dsn, pdo_type, ":", dsn_attributes); PHALCON_INIT_VAR(options); array_init(options); add_index_long(options, PDO_ATTR_ERRMODE, PDO_ERRMODE_EXCEPTION); add_index_long(options, PDO_ATTR_CASE, PDO_CASE_LOWER); add_index_long(options, PDO_ATTR_CURSOR, PDO_CURSOR_SCROLL); eval_int = phalcon_array_isset_string(descriptor, SS("persistent")); if (eval_int) { PHALCON_INIT_VAR(persistent); phalcon_array_fetch_string(&persistent, descriptor, SL("persistent"), PH_NOISY_CC); if (zend_is_true(persistent)) { phalcon_array_update_long_bool(&options, PDO_ATTR_PERSISTENT, 1, PH_SEPARATE TSRMLS_CC); } } ce0 = zend_fetch_class(SL("PDO"), ZEND_FETCH_CLASS_AUTO TSRMLS_CC); PHALCON_INIT_VAR(pdo); object_init_ex(pdo, ce0); PHALCON_CALL_METHOD_PARAMS_4_NORETURN(pdo, "__construct", dsn, username, password, options, PH_CHECK); phalcon_update_property_zval(this_ptr, SL("_pdo"), pdo TSRMLS_CC); PHALCON_MM_RESTORE();}
/** * Generates SQL to add an index to a table * * @param string $tableName * @param string $schemaName * @param Phalcon\Db\Reference $reference * @return string */ PHP_METHOD(Phalcon_Db_Dialect_Mysql, addForeignKey){ zval *table_name = NULL, *schema_name = NULL, *reference = NULL, *sql = NULL; zval *referenced_schema = NULL; zval *r0 = NULL, *r1 = NULL, *r2 = NULL, *r3 = NULL, *r4 = NULL, *r5 = NULL, *r6 = NULL; zval *r7 = NULL, *r8 = NULL; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zzz", &table_name, &schema_name, &reference) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } if (Z_TYPE_P(reference) != IS_OBJECT) { PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Reference parameter must be an instance of Phalcon\\Db\\Reference"); return; } if (zend_is_true(schema_name)) { PHALCON_INIT_VAR(sql); PHALCON_CONCAT_SVSVS(sql, "ALTER TABLE `", schema_name, "`.`", table_name, "` ADD FOREIGN KEY "); } else { PHALCON_INIT_VAR(sql); PHALCON_CONCAT_SVS(sql, "ALTER TABLE `", table_name, "` ADD FOREIGN KEY "); } PHALCON_ALLOC_ZVAL_MM(r0); PHALCON_CALL_METHOD(r0, reference, "getname", PH_NO_CHECK); PHALCON_ALLOC_ZVAL_MM(r1); PHALCON_CALL_METHOD(r1, reference, "getcolumns", PH_NO_CHECK); PHALCON_ALLOC_ZVAL_MM(r2); PHALCON_CALL_SELF_PARAMS_1(r2, this_ptr, "getcolumnlist", r1); PHALCON_ALLOC_ZVAL_MM(r3); PHALCON_CONCAT_SVSVS(r3, "`", r0, "`(", r2, ") REFERENCES "); phalcon_concat_self(&sql, r3 TSRMLS_CC); PHALCON_INIT_VAR(referenced_schema); PHALCON_CALL_METHOD(referenced_schema, reference, "getreferencedschema", PH_NO_CHECK); if (zend_is_true(referenced_schema)) { PHALCON_ALLOC_ZVAL_MM(r4); PHALCON_CONCAT_SVS(r4, "`", referenced_schema, "`."); phalcon_concat_self(&sql, r4 TSRMLS_CC); } PHALCON_ALLOC_ZVAL_MM(r5); PHALCON_CALL_METHOD(r5, reference, "getreferencedtable", PH_NO_CHECK); PHALCON_ALLOC_ZVAL_MM(r6); PHALCON_CALL_METHOD(r6, reference, "getreferencedcolumns", PH_NO_CHECK); PHALCON_ALLOC_ZVAL_MM(r7); PHALCON_CALL_SELF_PARAMS_1(r7, this_ptr, "getcolumnlist", r6); PHALCON_ALLOC_ZVAL_MM(r8); PHALCON_CONCAT_SVSVS(r8, "`", r5, "`(", r7, ")"); phalcon_concat_self(&sql, r8 TSRMLS_CC); RETURN_CTOR(sql); }
/** * Generates SQL to create a table in MySQL * * @param string $tableName * @param string $schemaName * @param array $definition * @return string */ PHP_METHOD(Phalcon_Db_Dialect_Mysql, createTable){ zval *table_name = NULL, *schema_name = NULL, *definition = NULL; zval *table = NULL, *temporary = NULL, *sql = NULL, *create_lines = NULL, *column = NULL; zval *column_line = NULL, *index = NULL, *index_name = NULL, *column_list = NULL; zval *reference = NULL, *reference_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, *r11 = NULL, *r12 = NULL, *r13 = NULL; zval *r14 = NULL, *r15 = NULL, *r16 = NULL, *r17 = NULL, *r18 = NULL, *r19 = NULL, *r20 = NULL; zval *r21 = NULL, *r22 = NULL, *r23 = NULL; zval *t0 = NULL, *t1 = NULL; zval *c0 = NULL; HashTable *ah0, *ah1, *ah2; HashPosition hp0, hp1, hp2; zval **hd; int eval_int; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zzz", &table_name, &schema_name, &definition) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } if (zend_is_true(schema_name)) { PHALCON_INIT_VAR(table); PHALCON_CONCAT_SVSVS(table, "`", schema_name, "`.`", table_name, "`"); } else { PHALCON_INIT_VAR(table); PHALCON_CONCAT_SVS(table, "`", table_name, "`"); } PHALCON_INIT_VAR(temporary); ZVAL_BOOL(temporary, 0); eval_int = phalcon_array_isset_string(definition, SL("options")+1); if (eval_int) { PHALCON_ALLOC_ZVAL_MM(r0); phalcon_array_fetch_string(&r0, definition, SL("options"), PH_NOISY_CC); eval_int = phalcon_array_isset_string(r0, SL("temporary")+1); if (eval_int) { PHALCON_ALLOC_ZVAL_MM(r1); phalcon_array_fetch_string(&r1, definition, SL("options"), PH_NOISY_CC); PHALCON_ALLOC_ZVAL_MM(r2); phalcon_array_fetch_string(&r2, r1, SL("temporary"), PH_NOISY_CC); if (zend_is_true(r2)) { PHALCON_INIT_VAR(temporary); ZVAL_BOOL(temporary, 1); } } } if (zend_is_true(temporary)) { PHALCON_INIT_VAR(sql); PHALCON_CONCAT_SVS(sql, "CREATE TEMPORARY TABLE ", table, " (\n\t"); } else { PHALCON_INIT_VAR(sql); PHALCON_CONCAT_SVS(sql, "CREATE TABLE ", table, " (\n\t"); } PHALCON_INIT_VAR(create_lines); array_init(create_lines); PHALCON_ALLOC_ZVAL_MM(r3); phalcon_array_fetch_string(&r3, definition, SL("columns"), PH_NOISY_CC); if (!phalcon_valid_foreach(r3 TSRMLS_CC)) { return; } ah0 = Z_ARRVAL_P(r3); zend_hash_internal_pointer_reset_ex(ah0, &hp0); fes_52be_2: if(zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) != SUCCESS){ goto fee_52be_2; } PHALCON_INIT_VAR(column); ZVAL_ZVAL(column, *hd, 1, 0); PHALCON_INIT_VAR(r4); PHALCON_CALL_METHOD(r4, column, "getname", PH_NO_CHECK); PHALCON_INIT_VAR(r5); PHALCON_CALL_SELF_PARAMS_1(r5, this_ptr, "getcolumndefinition", column); PHALCON_INIT_VAR(column_line); PHALCON_CONCAT_SVSV(column_line, "`", r4, "` ", r5); PHALCON_INIT_VAR(r6); PHALCON_CALL_METHOD(r6, column, "isnotnull", PH_NO_CHECK); if (zend_is_true(r6)) { PHALCON_INIT_VAR(t0); ZVAL_STRING(t0, " NOT NULL", 1); phalcon_concat_self(&column_line, t0 TSRMLS_CC); } PHALCON_INIT_VAR(r7); PHALCON_CALL_METHOD(r7, column, "isautoincrement", PH_NO_CHECK); if (zend_is_true(r7)) { PHALCON_INIT_VAR(t1); ZVAL_STRING(t1, " AUTO_INCREMENT", 1); phalcon_concat_self(&column_line, t1 TSRMLS_CC); } phalcon_array_append(&create_lines, column_line, PH_SEPARATE TSRMLS_CC); zend_hash_move_forward_ex(ah0, &hp0); goto fes_52be_2; fee_52be_2: eval_int = phalcon_array_isset_string(definition, SL("indexes")+1); if (eval_int) { PHALCON_ALLOC_ZVAL_MM(r8); phalcon_array_fetch_string(&r8, definition, SL("indexes"), PH_NOISY_CC); if (!phalcon_valid_foreach(r8 TSRMLS_CC)) { return; } ah1 = Z_ARRVAL_P(r8); zend_hash_internal_pointer_reset_ex(ah1, &hp1); fes_52be_3: if(zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) != SUCCESS){ goto fee_52be_3; } PHALCON_INIT_VAR(index); ZVAL_ZVAL(index, *hd, 1, 0); PHALCON_INIT_VAR(index_name); PHALCON_CALL_METHOD(index_name, index, "getname", PH_NO_CHECK); PHALCON_INIT_VAR(r9); PHALCON_CALL_METHOD(r9, index, "getcolumns", PH_NO_CHECK); PHALCON_INIT_VAR(column_list); PHALCON_CALL_SELF_PARAMS_1(column_list, this_ptr, "getcolumnlist", r9); if (PHALCON_COMPARE_STRING(index_name, "PRIMARY")) { PHALCON_INIT_VAR(r10); PHALCON_CONCAT_SVS(r10, "PRIMARY KEY (", column_list, ")"); phalcon_array_append(&create_lines, r10, PH_SEPARATE TSRMLS_CC); } else { PHALCON_INIT_VAR(r11); PHALCON_CONCAT_SVSVS(r11, "KEY `", index_name, "` (", column_list, ")"); phalcon_array_append(&create_lines, r11, PH_SEPARATE TSRMLS_CC); } zend_hash_move_forward_ex(ah1, &hp1); goto fes_52be_3; fee_52be_3: if(0){} } eval_int = phalcon_array_isset_string(definition, SL("references")+1); if (eval_int) { PHALCON_ALLOC_ZVAL_MM(r12); phalcon_array_fetch_string(&r12, definition, SL("references"), PH_NOISY_CC); if (!phalcon_valid_foreach(r12 TSRMLS_CC)) { return; } ah2 = Z_ARRVAL_P(r12); zend_hash_internal_pointer_reset_ex(ah2, &hp2); fes_52be_4: if(zend_hash_get_current_data_ex(ah2, (void**) &hd, &hp2) != SUCCESS){ goto fee_52be_4; } PHALCON_INIT_VAR(reference); ZVAL_ZVAL(reference, *hd, 1, 0); PHALCON_INIT_VAR(r13); PHALCON_CALL_METHOD(r13, reference, "getname", PH_NO_CHECK); PHALCON_INIT_VAR(r14); PHALCON_CALL_METHOD(r14, reference, "getcolumns", PH_NO_CHECK); PHALCON_INIT_VAR(r15); PHALCON_CALL_SELF_PARAMS_1(r15, this_ptr, "getcolumnlist", r14); PHALCON_INIT_VAR(reference_sql); PHALCON_CONCAT_SVSV(reference_sql, "CONSTRAINT `", r13, "` FOREIGN KEY (", r15); PHALCON_INIT_VAR(r16); PHALCON_CALL_METHOD(r16, reference, "getreferencedtable", PH_NO_CHECK); PHALCON_INIT_VAR(r17); PHALCON_CALL_METHOD(r17, reference, "getreferencedcolumns", PH_NO_CHECK); PHALCON_INIT_VAR(r18); PHALCON_CALL_SELF_PARAMS_1(r18, this_ptr, "getcolumnlist", r17); PHALCON_INIT_VAR(r19); PHALCON_CONCAT_SVSVS(r19, ") REFERENCES `", r16, "`(", r18, ")"); phalcon_concat_self(&reference_sql, r19 TSRMLS_CC); phalcon_array_append(&create_lines, reference_sql, PH_SEPARATE TSRMLS_CC); zend_hash_move_forward_ex(ah2, &hp2); goto fes_52be_4; fee_52be_4: if(0){} } PHALCON_INIT_VAR(c0); ZVAL_STRING(c0, ",\n\t", 1); PHALCON_ALLOC_ZVAL_MM(r20); phalcon_fast_join(r20, c0, create_lines TSRMLS_CC); PHALCON_ALLOC_ZVAL_MM(r21); PHALCON_CONCAT_VS(r21, r20, "\n)"); phalcon_concat_self(&sql, r21 TSRMLS_CC); eval_int = phalcon_array_isset_string(definition, SL("options")+1); if (eval_int) { PHALCON_ALLOC_ZVAL_MM(r22); PHALCON_CALL_SELF_PARAMS_1(r22, this_ptr, "_gettableoptions", definition); PHALCON_ALLOC_ZVAL_MM(r23); PHALCON_CONCAT_SV(r23, " ", r22); phalcon_concat_self(&sql, r23 TSRMLS_CC); } RETURN_CTOR(sql); }
/** * Restore a Phalcon_Db_Reference object from export * * @param array $data * @return Phalcon_Db_Reference */ PHP_METHOD(Phalcon_Db_Reference, __set_state){ zval *data = NULL, *constraint_name = NULL, *referenced_schema = NULL; zval *referenced_table = NULL, *columns = NULL, *referenced_columns = NULL; zval *r0 = NULL, *r1 = NULL, *r2 = NULL, *r3 = NULL, *r4 = NULL; zval *i0 = NULL; zval *a0 = NULL; int eval_int; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &data) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } eval_int = phalcon_array_isset_string(data, "_referenceName", strlen("_referenceName")+1); if (!eval_int) { PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "_referenceName parameter is required"); return; } else { PHALCON_ALLOC_ZVAL_MM(r0); phalcon_array_fetch_string(&r0, data, "_referenceName", strlen("_referenceName"), PHALCON_NOISY TSRMLS_CC); PHALCON_CPY_WRT(constraint_name, r0); } eval_int = phalcon_array_isset_string(data, "_referencedSchema", strlen("_referencedSchema")+1); if (eval_int) { PHALCON_ALLOC_ZVAL_MM(r1); phalcon_array_fetch_string(&r1, data, "_referencedSchema", strlen("_referencedSchema"), PHALCON_NOISY TSRMLS_CC); PHALCON_CPY_WRT(referenced_schema, r1); } else { PHALCON_INIT_VAR(referenced_schema); ZVAL_NULL(referenced_schema); } eval_int = phalcon_array_isset_string(data, "_referencedTable", strlen("_referencedTable")+1); if (eval_int) { PHALCON_ALLOC_ZVAL_MM(r2); phalcon_array_fetch_string(&r2, data, "_referencedTable", strlen("_referencedTable"), PHALCON_NOISY TSRMLS_CC); PHALCON_CPY_WRT(referenced_table, r2); } else { PHALCON_INIT_VAR(referenced_table); ZVAL_NULL(referenced_table); } eval_int = phalcon_array_isset_string(data, "_columns", strlen("_columns")+1); if (eval_int) { PHALCON_ALLOC_ZVAL_MM(r3); phalcon_array_fetch_string(&r3, data, "_columns", strlen("_columns"), PHALCON_NOISY TSRMLS_CC); PHALCON_CPY_WRT(columns, r3); } else { PHALCON_INIT_VAR(columns); ZVAL_NULL(columns); } eval_int = phalcon_array_isset_string(data, "_referencedColumns", strlen("_referencedColumns")+1); if (eval_int) { PHALCON_ALLOC_ZVAL_MM(r4); phalcon_array_fetch_string(&r4, data, "_referencedColumns", strlen("_referencedColumns"), PHALCON_NOISY TSRMLS_CC); PHALCON_CPY_WRT(referenced_columns, r4); } else { PHALCON_INIT_VAR(referenced_columns); ZVAL_NULL(referenced_columns); } PHALCON_ALLOC_ZVAL_MM(i0); object_init_ex(i0, phalcon_db_reference_ce); PHALCON_INIT_VAR(a0); array_init(a0); phalcon_array_update_string(&a0, "referencedSchema", strlen("referencedSchema"), &referenced_schema, PHALCON_SEPARATE_PLZ, PHALCON_COPY, PHALCON_NO_CTOR TSRMLS_CC); phalcon_array_update_string(&a0, "referencedTable", strlen("referencedTable"), &referenced_table, PHALCON_SEPARATE_PLZ, PHALCON_COPY, PHALCON_NO_CTOR TSRMLS_CC); phalcon_array_update_string(&a0, "columns", strlen("columns"), &columns, PHALCON_SEPARATE_PLZ, PHALCON_COPY, PHALCON_NO_CTOR TSRMLS_CC); phalcon_array_update_string(&a0, "referencedColumns", strlen("referencedColumns"), &referenced_columns, PHALCON_SEPARATE_PLZ, PHALCON_COPY, PHALCON_NO_CTOR TSRMLS_CC); PHALCON_CALL_METHOD_PARAMS_2_NORETURN(i0, "__construct", constraint_name, a0, PHALCON_CHECK); PHALCON_RETURN_CTOR(i0); }
/** * Phalcon_Db_Reference constructor * * @param string $referenceName * @param array $definition */ PHP_METHOD(Phalcon_Db_Reference, __construct){ zval *reference_name = NULL, *definition = NULL; zval *r0 = NULL, *r1 = NULL, *r2 = NULL, *r3 = NULL, *r4 = NULL, *r5 = NULL, *r6 = NULL; zval *r7 = NULL; zval *t0 = NULL, *t1 = NULL; int eval_int; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz", &reference_name, &definition) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } phalcon_update_property_zval(this_ptr, "_referenceName", strlen("_referenceName"), reference_name TSRMLS_CC); eval_int = phalcon_array_isset_string(definition, "referencedTable", strlen("referencedTable")+1); if (eval_int) { PHALCON_ALLOC_ZVAL_MM(r0); phalcon_array_fetch_string(&r0, definition, "referencedTable", strlen("referencedTable"), PHALCON_NOISY TSRMLS_CC); phalcon_update_property_zval(this_ptr, "_referencedTable", strlen("_referencedTable"), r0 TSRMLS_CC); } else { PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Referenced table is required"); return; } eval_int = phalcon_array_isset_string(definition, "columns", strlen("columns")+1); if (eval_int) { PHALCON_ALLOC_ZVAL_MM(r1); phalcon_array_fetch_string(&r1, definition, "columns", strlen("columns"), PHALCON_NOISY TSRMLS_CC); phalcon_update_property_zval(this_ptr, "_columns", strlen("_columns"), r1 TSRMLS_CC); } else { PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Foreign key columns are required"); return; } eval_int = phalcon_array_isset_string(definition, "referencedColumns", strlen("referencedColumns")+1); if (eval_int) { PHALCON_ALLOC_ZVAL_MM(r2); phalcon_array_fetch_string(&r2, definition, "referencedColumns", strlen("referencedColumns"), PHALCON_NOISY TSRMLS_CC); phalcon_update_property_zval(this_ptr, "_referencedColumns", strlen("_referencedColumns"), r2 TSRMLS_CC); } else { PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Referenced columns of the foreign key are required"); return; } eval_int = phalcon_array_isset_string(definition, "schema", strlen("schema")+1); if (eval_int) { PHALCON_ALLOC_ZVAL_MM(r3); phalcon_array_fetch_string(&r3, definition, "schema", strlen("schema"), PHALCON_NOISY TSRMLS_CC); phalcon_update_property_zval(this_ptr, "_schema", strlen("_schema"), r3 TSRMLS_CC); } eval_int = phalcon_array_isset_string(definition, "referencedSchema", strlen("referencedSchema")+1); if (eval_int) { PHALCON_ALLOC_ZVAL_MM(r4); phalcon_array_fetch_string(&r4, definition, "referencedSchema", strlen("referencedSchema"), PHALCON_NOISY TSRMLS_CC); phalcon_update_property_zval(this_ptr, "_referencedSchema", strlen("_referencedSchema"), r4 TSRMLS_CC); } PHALCON_ALLOC_ZVAL_MM(t0); phalcon_read_property(&t0, this_ptr, "_columns", sizeof("_columns")-1, PHALCON_NOISY TSRMLS_CC); PHALCON_ALLOC_ZVAL_MM(r5); phalcon_fast_count(r5, t0 TSRMLS_CC); PHALCON_ALLOC_ZVAL_MM(t1); phalcon_read_property(&t1, this_ptr, "_referencedColumns", sizeof("_referencedColumns")-1, PHALCON_NOISY TSRMLS_CC); PHALCON_ALLOC_ZVAL_MM(r6); phalcon_fast_count(r6, t1 TSRMLS_CC); PHALCON_INIT_VAR(r7); is_not_equal_function(r7, r5, r6 TSRMLS_CC); if (zend_is_true(r7)) { PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Number of columns is not equals than the number of columns referenced"); return; } PHALCON_MM_RESTORE(); }
/** * Appends a message to the validator * * @param string $message * @param string $field * @param string $type */ PHP_METHOD(Phalcon_Model_Validator, appendMessage){ zval *v0 = NULL, *v1 = NULL, *v2 = NULL; zval *t0 = NULL, *t1 = NULL; zval *r0 = NULL, *r1 = NULL; zval *i0 = NULL; zval *p0[] = { NULL, NULL, NULL }, *p2[] = { NULL, NULL, NULL }; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|zz", &v0, &v1, &v2) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } if (!v1) { PHALCON_INIT_VAR(v1); ZVAL_STRING(v1, "", 1); } else { PHALCON_SEPARATE_PARAM(v1); } if (!v2) { PHALCON_INIT_VAR(v2); ZVAL_STRING(v2, "", 1); } else { PHALCON_SEPARATE_PARAM(v2); } if (PHALCON_COMPARE_STRING(v1, "")) { PHALCON_ALLOC_ZVAL_MM(t0); phalcon_read_property(&t0, this_ptr, "_fieldName", sizeof("_fieldName")-1, PHALCON_NOISY_FETCH TSRMLS_CC); PHALCON_CPY_WRT(v1, t0); } if (PHALCON_COMPARE_STRING(v2, "")) { PHALCON_ALLOC_ZVAL_MM(r0); PHALCON_INIT_VAR(p0[0]); ZVAL_STRING(p0[0], "Validator", 1); PHALCON_INIT_VAR(p0[1]); ZVAL_STRING(p0[1], "", 1); PHALCON_ALLOC_ZVAL_MM(r1); PHALCON_CALL_FUNC_PARAMS_1(r1, "get_class", this_ptr, 0x049); p0[2] = r1; PHALCON_CALL_FUNC_PARAMS(r0, "str_replace", 3, p0, 0x01A); PHALCON_CPY_WRT(v2, r0); } PHALCON_ALLOC_ZVAL_MM(i0); object_init_ex(i0, phalcon_model_message_class_entry); Z_ADDREF_P(v0); p2[0] = v0; Z_ADDREF_P(v1); p2[1] = v1; Z_ADDREF_P(v2); p2[2] = v2; PHALCON_CALL_METHOD_PARAMS_NORETURN(i0, "__construct", 3, p2, PHALCON_CALL_CHECK); Z_DELREF_P(p2[0]); Z_DELREF_P(p2[1]); Z_DELREF_P(p2[2]); PHALCON_ALLOC_ZVAL_MM(t1); phalcon_read_property(&t1, this_ptr, "_messages", sizeof("_messages")-1, PHALCON_NOISY_FETCH TSRMLS_CC); Z_ADDREF_P(i0); phalcon_array_append(t1, i0 TSRMLS_CC); phalcon_update_property_zval(this_ptr, "_messages", strlen("_messages"), t1 TSRMLS_CC); PHALCON_MM_RESTORE(); RETURN_NULL(); }
/** * Assigns values to a row from an array returning a new row * * @param array $result * @return Phalcon\Mvc\Model $result */ PHP_METHOD(Phalcon_Mvc_Model_Row, dumpResult){ zval *result = NULL, *object_row = NULL, *columns = NULL, *value = NULL, *field = NULL; zval *i0 = NULL; zval *t0 = NULL, *t1 = NULL, *t2 = NULL; zval *r0 = NULL, *r1 = NULL; HashTable *ah0, *ah1; HashPosition hp0, hp1; 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, "z", &result) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } PHALCON_ALLOC_ZVAL_MM(i0); if (phalcon_clone(i0, this_ptr TSRMLS_CC) == FAILURE){ return; } PHALCON_CPY_WRT(object_row, i0); PHALCON_ALLOC_ZVAL_MM(t0); phalcon_read_property(&t0, this_ptr, SL("_columns"), PH_NOISY_CC); PHALCON_ALLOC_ZVAL_MM(r0); phalcon_fast_count(r0, t0 TSRMLS_CC); PHALCON_INIT_VAR(t1); ZVAL_LONG(t1, 0); PHALCON_ALLOC_ZVAL_MM(r1); is_equal_function(r1, r0, t1 TSRMLS_CC); if (zend_is_true(r1)) { PHALCON_INIT_VAR(columns); array_init(columns); if (!phalcon_valid_foreach(result TSRMLS_CC)) { return; } ah0 = Z_ARRVAL_P(result); zend_hash_internal_pointer_reset_ex(ah0, &hp0); fes_4c15_0: if(zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) != SUCCESS){ goto fee_4c15_0; } PHALCON_INIT_VAR(field); PHALCON_GET_FOREACH_KEY(field, ah0, hp0); PHALCON_INIT_VAR(value); ZVAL_ZVAL(value, *hd, 1, 0); phalcon_array_update_zval_bool(&columns, field, 1, PH_SEPARATE TSRMLS_CC); phalcon_update_property_zval_zval(object_row, field, value TSRMLS_CC); zend_hash_move_forward_ex(ah0, &hp0); goto fes_4c15_0; fee_4c15_0: if(0){} phalcon_update_property_zval(object_row, SL("_columns"), columns TSRMLS_CC); phalcon_update_property_zval(this_ptr, SL("_columns"), columns TSRMLS_CC); } else { if (!phalcon_valid_foreach(result TSRMLS_CC)) { return; } ah1 = Z_ARRVAL_P(result); zend_hash_internal_pointer_reset_ex(ah1, &hp1); fes_4c15_1: if(zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) != SUCCESS){ goto fee_4c15_1; } PHALCON_INIT_VAR(field); PHALCON_GET_FOREACH_KEY(field, ah1, hp1); PHALCON_INIT_VAR(value); ZVAL_ZVAL(value, *hd, 1, 0); phalcon_update_property_zval_zval(object_row, field, value TSRMLS_CC); zend_hash_move_forward_ex(ah1, &hp1); goto fes_4c15_1; fee_4c15_1: if(0){} PHALCON_ALLOC_ZVAL_MM(t2); phalcon_read_property(&t2, this_ptr, SL("_columns"), PH_NOISY_CC); phalcon_update_property_zval(object_row, SL("_columns"), t2 TSRMLS_CC); } RETURN_CCTOR(object_row); }
/** * Initialize the metadata for certain table * * @param Phalcon\Mvc\Model $model * @param string $table * @param string $schema */ PHP_METHOD(Phalcon_Mvc_Model_MetaData, _initializeMetaData){ zval *model = NULL, *table = NULL, *schema = NULL, *key = NULL, *connection = NULL, *exists = NULL; zval *complete_table = NULL, *attributes = NULL, *primary_keys = NULL; zval *non_primary_keys = NULL, *numeric_typed = NULL, *not_null = NULL; zval *field_types = NULL, *identity_field = NULL, *columns = NULL; zval *column = NULL, *field_name = NULL, *table_metadata = NULL; zval *t0 = NULL, *t1 = NULL, *t2 = NULL; zval *i0 = NULL; zval *r0 = NULL, *r1 = NULL, *r2 = NULL, *r3 = NULL, *r4 = NULL, *r5 = NULL, *r6 = NULL; zval *a0 = NULL; HashTable *ah0; HashPosition hp0; zval **hd; int eval_int; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zzz", &model, &table, &schema) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } PHALCON_INIT_VAR(key); PHALCON_CONCAT_VV(key, schema, table); PHALCON_ALLOC_ZVAL_MM(t0); phalcon_read_property(&t0, this_ptr, SL("_metaData"), PH_NOISY_CC); eval_int = phalcon_array_isset(t0, key); if (!eval_int) { PHALCON_INIT_VAR(connection); PHALCON_CALL_METHOD(connection, model, "getconnection", PH_NO_CHECK); PHALCON_INIT_VAR(exists); PHALCON_CALL_METHOD_PARAMS_2(exists, connection, "tableexists", table, schema, PH_NO_CHECK); if (!zend_is_true(exists)) { if (zend_is_true(schema)) { PHALCON_INIT_VAR(complete_table); PHALCON_CONCAT_VSV(complete_table, schema, "\".\"", table); } else { PHALCON_CPY_WRT(complete_table, table); } PHALCON_ALLOC_ZVAL_MM(i0); object_init_ex(i0, phalcon_mvc_model_exception_ce); PHALCON_ALLOC_ZVAL_MM(r0); phalcon_get_class(r0, model TSRMLS_CC); PHALCON_ALLOC_ZVAL_MM(r1); PHALCON_CONCAT_SVSV(r1, "Table \"", complete_table, "\" doesn't exist on database when dumping meta-data for ", r0); PHALCON_CALL_METHOD_PARAMS_1_NORETURN(i0, "__construct", r1, PH_CHECK); phalcon_throw_exception(i0 TSRMLS_CC); return; } PHALCON_INIT_VAR(attributes); array_init(attributes); PHALCON_INIT_VAR(primary_keys); array_init(primary_keys); PHALCON_INIT_VAR(non_primary_keys); array_init(non_primary_keys); PHALCON_INIT_VAR(numeric_typed); array_init(numeric_typed); PHALCON_INIT_VAR(not_null); array_init(not_null); PHALCON_INIT_VAR(field_types); array_init(field_types); PHALCON_INIT_VAR(identity_field); ZVAL_BOOL(identity_field, 0); PHALCON_INIT_VAR(columns); PHALCON_CALL_METHOD_PARAMS_2(columns, connection, "describecolumns", table, schema, PH_NO_CHECK); if (!phalcon_valid_foreach(columns TSRMLS_CC)) { return; } ah0 = Z_ARRVAL_P(columns); zend_hash_internal_pointer_reset_ex(ah0, &hp0); fes_c40c_0: if(zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) != SUCCESS){ goto fee_c40c_0; } PHALCON_INIT_VAR(column); ZVAL_ZVAL(column, *hd, 1, 0); PHALCON_INIT_VAR(field_name); PHALCON_CALL_METHOD(field_name, column, "getname", PH_NO_CHECK); phalcon_array_append(&attributes, field_name, PH_SEPARATE TSRMLS_CC); PHALCON_INIT_VAR(r2); PHALCON_CALL_METHOD(r2, column, "isprimary", PH_NO_CHECK); if (zend_is_true(r2)) { phalcon_array_append(&primary_keys, field_name, PH_SEPARATE TSRMLS_CC); } else { phalcon_array_append(&non_primary_keys, field_name, PH_SEPARATE TSRMLS_CC); } PHALCON_INIT_VAR(r3); PHALCON_CALL_METHOD(r3, column, "isnumeric", PH_NO_CHECK); if (zend_is_true(r3)) { phalcon_array_update_zval_bool(&numeric_typed, field_name, 1, PH_SEPARATE TSRMLS_CC); } PHALCON_INIT_VAR(r4); PHALCON_CALL_METHOD(r4, column, "isnotnull", PH_NO_CHECK); if (zend_is_true(r4)) { phalcon_array_append(¬_null, field_name, PH_SEPARATE TSRMLS_CC); } PHALCON_INIT_VAR(r5); PHALCON_CALL_METHOD(r5, column, "isautoincrement", PH_NO_CHECK); if (zend_is_true(r5)) { PHALCON_CPY_WRT(identity_field, field_name); } PHALCON_INIT_VAR(r6); PHALCON_CALL_METHOD(r6, column, "gettype", PH_NO_CHECK); phalcon_array_update_zval(&field_types, field_name, &r6, PH_COPY | PH_SEPARATE TSRMLS_CC); zend_hash_move_forward_ex(ah0, &hp0); goto fes_c40c_0; fee_c40c_0: if(0){} PHALCON_INIT_VAR(table_metadata); array_init(table_metadata); phalcon_array_update_long(&table_metadata, 0, &attributes, PH_COPY | PH_SEPARATE TSRMLS_CC); phalcon_array_update_long(&table_metadata, 1, &primary_keys, PH_COPY | PH_SEPARATE TSRMLS_CC); phalcon_array_update_long(&table_metadata, 2, &non_primary_keys, PH_COPY | PH_SEPARATE TSRMLS_CC); phalcon_array_update_long(&table_metadata, 3, ¬_null, PH_COPY | PH_SEPARATE TSRMLS_CC); phalcon_array_update_long(&table_metadata, 4, &field_types, PH_COPY | PH_SEPARATE TSRMLS_CC); phalcon_array_update_long(&table_metadata, 5, &numeric_typed, PH_COPY | PH_SEPARATE TSRMLS_CC); phalcon_array_update_long(&table_metadata, 8, &identity_field, PH_COPY | PH_SEPARATE TSRMLS_CC); PHALCON_ALLOC_ZVAL_MM(t1); phalcon_read_property(&t1, this_ptr, SL("_metaData"), PH_NOISY_CC); phalcon_array_update_zval(&t1, key, &table_metadata, PH_COPY TSRMLS_CC); phalcon_update_property_zval(this_ptr, SL("_metaData"), t1 TSRMLS_CC); PHALCON_ALLOC_ZVAL_MM(t2); phalcon_read_property(&t2, this_ptr, SL("_changed"), PH_NOISY_CC); if (!zend_is_true(t2)) { PHALCON_ALLOC_ZVAL_MM(a0); array_init(a0); phalcon_array_append(&a0, this_ptr, PH_SEPARATE TSRMLS_CC); add_next_index_stringl(a0, SL("storeMetaData"), 1); PHALCON_CALL_FUNC_PARAMS_1_NORETURN("register_shutdown_function", a0); phalcon_update_property_bool(this_ptr, SL("_changed"), 1 TSRMLS_CC); } } PHALCON_MM_RESTORE(); }
PHP_METHOD(Phalcon_Flash, _showMessage){ zval *v0 = NULL, *v1 = NULL, *v2 = NULL, *v3 = NULL; zval *r0 = NULL, *r1 = NULL, *r2 = NULL, *r3 = NULL, *r4 = NULL, *r5 = NULL, *r6 = NULL; zval *c0 = NULL; zval *t0 = NULL, *t1 = NULL; HashTable *ah0; HashPosition hp0; zval **hd; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz", &v0, &v1) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } if (Z_TYPE_P(v1) == IS_ARRAY) { PHALCON_ALLOC_ZVAL_MM(r0); PHALCON_INIT_VAR(c0); ZVAL_STRING(c0, " ", 1); PHALCON_CALL_FUNC_PARAMS_2(r0, "join", c0, v1, 0x00F); PHALCON_CPY_WRT(v2, r0); } else { PHALCON_CPY_WRT(v2, v1); } if (Z_TYPE_P(v0) == IS_ARRAY) { if (Z_TYPE_P(v0) != IS_ARRAY) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid argument supplied for foreach()"); } else { ah0 = Z_ARRVAL_P(v0); zend_hash_internal_pointer_reset_ex(ah0, &hp0); fes_3b3c_0: if(zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) != SUCCESS){ goto fee_3b3c_0; } PHALCON_INIT_VAR(v3); ZVAL_ZVAL(v3, *hd, 1, 0); PHALCON_INIT_VAR(r3); PHALCON_CONCAT_LEFT(r3, "<div class=\"", v2); PHALCON_INIT_VAR(r2); PHALCON_CONCAT_VBOTH(r2, r3, "\">", v3); PHALCON_INIT_VAR(t0); zend_get_constant("PHP_EOL", strlen("PHP_EOL"), t0 TSRMLS_CC); PHALCON_INIT_VAR(r1); PHALCON_CONCAT_VBOTH(r1, r2, "</div>", t0); zend_print_zval(r1, 0); zend_hash_move_forward_ex(ah0, &hp0); goto fes_3b3c_0; fee_3b3c_0: if(0){ }; } } else { PHALCON_ALLOC_ZVAL_MM(r6); PHALCON_CONCAT_LEFT(r6, "<div class=\"", v2); PHALCON_ALLOC_ZVAL_MM(r5); PHALCON_CONCAT_VBOTH(r5, r6, "\">", v0); PHALCON_ALLOC_ZVAL_MM(t1); zend_get_constant("PHP_EOL", strlen("PHP_EOL"), t1 TSRMLS_CC); PHALCON_ALLOC_ZVAL_MM(r4); PHALCON_CONCAT_VBOTH(r4, r5, "</div>", t1); zend_print_zval(r4, 0); } PHALCON_MM_RESTORE(); RETURN_NULL(); }
/** * Stores cached content into the file backend * * @param string $keyName * @param string $content * @param boolean $stopBuffer */ PHP_METHOD(Phalcon_Cache_Backend_File, save){ zval *key_name = NULL, *content = NULL, *stop_buffer = NULL, *last_key = NULL; zval *front_end = NULL, *backend = NULL, *cache_dir = NULL, *cache_file = NULL; zval *cached_content = NULL, *prepared_content = NULL, *is_buffering = NULL; zval *t0 = NULL, *t1 = NULL, *t2 = NULL; zval *r0 = NULL, *r1 = NULL, *r2 = NULL, *r3 = NULL, *r4 = NULL, *r5 = NULL, *r6 = NULL; zval *i0 = NULL, *i1 = NULL; zval *c0 = NULL, *c1 = NULL; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|zzz", &key_name, &content, &stop_buffer) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } if (!key_name) { PHALCON_INIT_VAR(key_name); ZVAL_NULL(key_name); } if (!content) { PHALCON_INIT_VAR(content); ZVAL_NULL(content); } if (!stop_buffer) { PHALCON_INIT_VAR(stop_buffer); ZVAL_BOOL(stop_buffer, 1); } if (Z_TYPE_P(key_name) == IS_NULL) { PHALCON_ALLOC_ZVAL_MM(t0); phalcon_read_property(&t0, this_ptr, "_lastKey", sizeof("_lastKey")-1, PHALCON_NOISY TSRMLS_CC); PHALCON_CPY_WRT(last_key, t0); } else { PHALCON_ALLOC_ZVAL_MM(r0); phalcon_filter_alphanum(r0, key_name); PHALCON_CPY_WRT(last_key, r0); } if (!zend_is_true(last_key)) { PHALCON_ALLOC_ZVAL_MM(i0); object_init_ex(i0, phalcon_cache_exception_ce); PHALCON_INIT_VAR(c0); ZVAL_STRING(c0, "The cache must be started first", 1); PHALCON_CALL_METHOD_PARAMS_1_NORETURN(i0, "__construct", c0, PHALCON_CHECK); phalcon_throw_exception(i0 TSRMLS_CC); return; } PHALCON_ALLOC_ZVAL_MM(t1); phalcon_read_property(&t1, this_ptr, "_frontendObject", sizeof("_frontendObject")-1, PHALCON_NOISY TSRMLS_CC); PHALCON_CPY_WRT(front_end, t1); PHALCON_ALLOC_ZVAL_MM(t2); phalcon_read_property(&t2, this_ptr, "_backendOptions", sizeof("_backendOptions")-1, PHALCON_NOISY TSRMLS_CC); PHALCON_CPY_WRT(backend, t2); PHALCON_ALLOC_ZVAL_MM(r1); phalcon_array_fetch_string(&r1, backend, "cacheDir", strlen("cacheDir"), PHALCON_NOISY TSRMLS_CC); PHALCON_CPY_WRT(cache_dir, r1); PHALCON_ALLOC_ZVAL_MM(r2); PHALCON_CALL_FUNC_PARAMS_1(r2, "is_writable", cache_dir, 0x017); if (!zend_is_true(r2)) { PHALCON_ALLOC_ZVAL_MM(i1); object_init_ex(i1, phalcon_cache_exception_ce); PHALCON_INIT_VAR(c1); ZVAL_STRING(c1, "The cache file is not writable", 1); PHALCON_CALL_METHOD_PARAMS_1_NORETURN(i1, "__construct", c1, PHALCON_CHECK); phalcon_throw_exception(i1 TSRMLS_CC); return; } PHALCON_ALLOC_ZVAL_MM(r3); concat_function(r3, cache_dir, last_key TSRMLS_CC); PHALCON_CPY_WRT(cache_file, r3); if (!zend_is_true(content)) { PHALCON_ALLOC_ZVAL_MM(r4); PHALCON_CALL_METHOD(r4, front_end, "getcontent", PHALCON_NO_CHECK); PHALCON_CPY_WRT(cached_content, r4); } else { PHALCON_CPY_WRT(cached_content, content); } PHALCON_ALLOC_ZVAL_MM(r5); PHALCON_CALL_METHOD_PARAMS_1(r5, front_end, "beforestore", cached_content, PHALCON_NO_CHECK); PHALCON_CPY_WRT(prepared_content, r5); PHALCON_CALL_FUNC_PARAMS_2_NORETURN("file_put_contents", cache_file, prepared_content, 0x01B); PHALCON_ALLOC_ZVAL_MM(r6); PHALCON_CALL_METHOD(r6, front_end, "isbuffering", PHALCON_NO_CHECK); PHALCON_CPY_WRT(is_buffering, r6); if (zend_is_true(stop_buffer)) { PHALCON_CALL_METHOD_NORETURN(front_end, "stop", PHALCON_NO_CHECK); } if (zend_is_true(is_buffering)) { zend_print_zval(cached_content, 1); } PHALCON_MM_RESTORE(); }
/** * Gets the column name in MySQL * * @param Phalcon\Db\Column $column */ PHP_METHOD(Phalcon_Db_Dialect_Mysql, getColumnDefinition){ zval *column = NULL, *size = NULL, *column_type = NULL, *column_sql = NULL; zval *scale = NULL; zval *r0 = NULL, *r1 = NULL, *r2 = NULL, *r3 = NULL, *r4 = NULL, *r5 = NULL; zval *t0 = NULL, *t1 = NULL, *t2 = NULL, *t3 = NULL; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &column) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } if (Z_TYPE_P(column) != IS_OBJECT) { PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Column definition must be an instance of Phalcon\\Db\\Column"); return; } PHALCON_INIT_VAR(size); PHALCON_CALL_METHOD(size, column, "getsize", PH_NO_CHECK); PHALCON_INIT_VAR(column_type); PHALCON_CALL_METHOD(column_type, column, "gettype", PH_NO_CHECK); if (phalcon_compare_strict_long(column_type, 0 TSRMLS_CC)) { PHALCON_INIT_VAR(column_sql); PHALCON_CONCAT_SVS(column_sql, "INT(", size, ")"); PHALCON_ALLOC_ZVAL_MM(r0); PHALCON_CALL_METHOD(r0, column, "isunsigned", PH_NO_CHECK); if (zend_is_true(r0)) { PHALCON_INIT_VAR(t0); ZVAL_STRING(t0, " UNSIGNED", 1); phalcon_concat_self(&column_sql, t0 TSRMLS_CC); } goto se_52be_1; } if (phalcon_compare_strict_long(column_type, 1 TSRMLS_CC)) { PHALCON_INIT_VAR(column_sql); ZVAL_STRING(column_sql, "DATE", 1); goto se_52be_1; } if (phalcon_compare_strict_long(column_type, 2 TSRMLS_CC)) { PHALCON_INIT_VAR(column_sql); PHALCON_CONCAT_SVS(column_sql, "VARCHAR(", size, ")"); goto se_52be_1; } if (phalcon_compare_strict_long(column_type, 3 TSRMLS_CC)) { PHALCON_ALLOC_ZVAL_MM(r1); PHALCON_CALL_METHOD(r1, column, "getscale", PH_NO_CHECK); PHALCON_INIT_VAR(column_sql); PHALCON_CONCAT_SVSVS(column_sql, "DECIMAL(", size, ",", r1, ")"); PHALCON_ALLOC_ZVAL_MM(r2); PHALCON_CALL_METHOD(r2, column, "isunsigned", PH_NO_CHECK); if (zend_is_true(r2)) { PHALCON_INIT_VAR(t1); ZVAL_STRING(t1, " UNSIGNED", 1); phalcon_concat_self(&column_sql, t1 TSRMLS_CC); } goto se_52be_1; } if (phalcon_compare_strict_long(column_type, 4 TSRMLS_CC)) { PHALCON_INIT_VAR(column_sql); ZVAL_STRING(column_sql, "DATETIME", 1); goto se_52be_1; } if (phalcon_compare_strict_long(column_type, 5 TSRMLS_CC)) { PHALCON_INIT_VAR(column_sql); PHALCON_CONCAT_SVS(column_sql, "CHAR(", size, ")"); goto se_52be_1; } if (phalcon_compare_strict_long(column_type, 6 TSRMLS_CC)) { PHALCON_INIT_VAR(column_sql); ZVAL_STRING(column_sql, "TEXT", 1); goto se_52be_1; } if (phalcon_compare_strict_long(column_type, 7 TSRMLS_CC)) { PHALCON_INIT_VAR(column_sql); ZVAL_STRING(column_sql, "FLOAT", 1); PHALCON_INIT_VAR(scale); PHALCON_CALL_METHOD(scale, column, "getscale", PH_NO_CHECK); if (zend_is_true(size)) { PHALCON_ALLOC_ZVAL_MM(r3); PHALCON_CONCAT_SV(r3, "(", size); phalcon_concat_self(&column_sql, r3 TSRMLS_CC); if (zend_is_true(scale)) { PHALCON_ALLOC_ZVAL_MM(r4); PHALCON_CONCAT_SVS(r4, ",", scale, ")"); phalcon_concat_self(&column_sql, r4 TSRMLS_CC); } else { PHALCON_INIT_VAR(t2); ZVAL_STRING(t2, ")", 1); phalcon_concat_self(&column_sql, t2 TSRMLS_CC); } } PHALCON_ALLOC_ZVAL_MM(r5); PHALCON_CALL_METHOD(r5, column, "isunsigned", PH_NO_CHECK); if (zend_is_true(r5)) { PHALCON_INIT_VAR(t3); ZVAL_STRING(t3, " UNSIGNED", 1); phalcon_concat_self(&column_sql, t3 TSRMLS_CC); } goto se_52be_1; } PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Unrecognized MySQL data type"); return; se_52be_1: RETURN_CTOR(column_sql); }
/** * Makes the work of autoload registered classes * * @param string $className * @return boolean */ PHP_METHOD(Phalcon_Loader, autoLoad){ zval *class_name = NULL, *events_manager = NULL, *classes = NULL; zval *file_path = NULL, *extensions = NULL, *namespaces = NULL, *namespace_separator = NULL; zval *ds = NULL, *directory = NULL, *preffix = NULL, *class_name_len = NULL; zval *preffix_len = NULL, *possible_preffix = NULL, *file_name = NULL; zval *extension = NULL, *path = NULL; zval *c0 = NULL, *c1 = NULL, *c2 = NULL, *c3 = NULL, *c4 = NULL, *c5 = NULL, *c6 = NULL; zval *c7 = NULL; zval *r0 = NULL, *r1 = NULL, *r2 = NULL, *r3 = NULL, *r4 = NULL; zval *t0 = NULL; HashTable *ah0, *ah1, *ah2, *ah3; HashPosition hp0, hp1, hp2, hp3; 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", &class_name) == 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_INIT_VAR(c0); ZVAL_STRING(c0, "loader:beforeCheckClass", 1); PHALCON_CALL_METHOD_PARAMS_2_NORETURN(events_manager, "fire", c0, this_ptr, PH_NO_CHECK); } PHALCON_INIT_VAR(classes); phalcon_read_property(&classes, this_ptr, SL("_classes"), PH_NOISY_CC); eval_int = phalcon_array_isset(classes, class_name); if (eval_int) { PHALCON_INIT_VAR(file_path); phalcon_array_fetch(&file_path, classes, class_name, PH_NOISY_CC); if (zend_is_true(events_manager)) { phalcon_update_property_zval(this_ptr, SL("_foundPath"), file_path TSRMLS_CC); PHALCON_INIT_VAR(c1); ZVAL_STRING(c1, "loader:pathFound", 1); PHALCON_CALL_METHOD_PARAMS_2_NORETURN(events_manager, "fire", c1, this_ptr, PH_NO_CHECK); } if (phalcon_require(file_path TSRMLS_CC) == FAILURE) { return; } PHALCON_MM_RESTORE(); RETURN_TRUE; } PHALCON_INIT_VAR(extensions); phalcon_read_property(&extensions, this_ptr, SL("_extensions"), PH_NOISY_CC); PHALCON_INIT_VAR(namespaces); phalcon_read_property(&namespaces, this_ptr, SL("_namespaces"), PH_NOISY_CC); PHALCON_ALLOC_ZVAL_MM(r0); phalcon_fast_count(r0, namespaces TSRMLS_CC); if (zend_is_true(r0)) { PHALCON_INIT_VAR(namespace_separator); ZVAL_STRING(namespace_separator, "\\", 1); PHALCON_INIT_VAR(ds); zend_get_constant(SL("DIRECTORY_SEPARATOR"), ds TSRMLS_CC); if (!phalcon_valid_foreach(namespaces TSRMLS_CC)) { return; } ah0 = Z_ARRVAL_P(namespaces); zend_hash_internal_pointer_reset_ex(ah0, &hp0); fes_0c08_0: if(zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) != SUCCESS){ goto fee_0c08_0; } PHALCON_INIT_VAR(preffix); PHALCON_GET_FOREACH_KEY(preffix, ah0, hp0); PHALCON_INIT_VAR(directory); ZVAL_ZVAL(directory, *hd, 1, 0); PHALCON_INIT_VAR(class_name_len); PHALCON_CALL_FUNC_PARAMS_1(class_name_len, "strlen", class_name); PHALCON_INIT_VAR(preffix_len); PHALCON_CALL_FUNC_PARAMS_1(preffix_len, "strlen", preffix); PHALCON_INIT_VAR(r1); is_smaller_function(r1, preffix_len, class_name_len TSRMLS_CC); if (zend_is_true(r1)) { PHALCON_INIT_VAR(c2); ZVAL_LONG(c2, 0); PHALCON_INIT_VAR(possible_preffix); PHALCON_CALL_FUNC_PARAMS_3(possible_preffix, "substr", class_name, c2, preffix_len); PHALCON_INIT_VAR(r2); is_equal_function(r2, possible_preffix, preffix TSRMLS_CC); if (zend_is_true(r2)) { PHALCON_INIT_VAR(r3); PHALCON_CONCAT_VV(r3, preffix, namespace_separator); PHALCON_INIT_VAR(c3); ZVAL_STRING(c3, "", 1); PHALCON_INIT_VAR(file_name); phalcon_fast_str_replace(file_name, r3, c3, class_name TSRMLS_CC); if (zend_is_true(file_name)) { if (!phalcon_valid_foreach(extensions TSRMLS_CC)) { return; } ah1 = Z_ARRVAL_P(extensions); zend_hash_internal_pointer_reset_ex(ah1, &hp1); fes_0c08_1: if(zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) != SUCCESS){ goto fee_0c08_1; } PHALCON_INIT_VAR(extension); ZVAL_ZVAL(extension, *hd, 1, 0); PHALCON_INIT_VAR(r4); PHALCON_CONCAT_VVSV(r4, directory, file_name, ".", extension); PHALCON_INIT_VAR(path); phalcon_fast_str_replace(path, namespace_separator, ds, r4 TSRMLS_CC); if (zend_is_true(events_manager)) { phalcon_update_property_zval(this_ptr, SL("_checkedPath"), path TSRMLS_CC); PHALCON_INIT_VAR(c4); ZVAL_STRING(c4, "loader:beforeCheckPath", 1); PHALCON_CALL_METHOD_PARAMS_2_NORETURN(events_manager, "fire", c4, this_ptr, PH_NO_CHECK); } if (phalcon_file_exists(path TSRMLS_CC) == SUCCESS) { if (zend_is_true(events_manager)) { phalcon_update_property_zval(this_ptr, SL("_foundPath"), file_path TSRMLS_CC); PHALCON_INIT_VAR(c5); ZVAL_STRING(c5, "loader:pathFound", 1); PHALCON_CALL_METHOD_PARAMS_2_NORETURN(events_manager, "fire", c5, this_ptr, PH_NO_CHECK); } if (phalcon_require(path TSRMLS_CC) == FAILURE) { return; } PHALCON_MM_RESTORE(); RETURN_TRUE; } zend_hash_move_forward_ex(ah1, &hp1); goto fes_0c08_1; fee_0c08_1: if(0){} } } } zend_hash_move_forward_ex(ah0, &hp0); goto fes_0c08_0; fee_0c08_0: if(0){} } PHALCON_ALLOC_ZVAL_MM(t0); phalcon_read_property(&t0, this_ptr, SL("_directories"), PH_NOISY_CC); if (!phalcon_valid_foreach(t0 TSRMLS_CC)) { return; } ah2 = Z_ARRVAL_P(t0); zend_hash_internal_pointer_reset_ex(ah2, &hp2); fes_0c08_2: if(zend_hash_get_current_data_ex(ah2, (void**) &hd, &hp2) != SUCCESS){ goto fee_0c08_2; } PHALCON_INIT_VAR(directory); ZVAL_ZVAL(directory, *hd, 1, 0); if (!phalcon_valid_foreach(extensions TSRMLS_CC)) { return; } ah3 = Z_ARRVAL_P(extensions); zend_hash_internal_pointer_reset_ex(ah3, &hp3); fes_0c08_3: if(zend_hash_get_current_data_ex(ah3, (void**) &hd, &hp3) != SUCCESS){ goto fee_0c08_3; } PHALCON_INIT_VAR(extension); ZVAL_ZVAL(extension, *hd, 1, 0); PHALCON_INIT_VAR(path); PHALCON_CONCAT_VVSV(path, directory, class_name, ".", extension); if (zend_is_true(events_manager)) { phalcon_update_property_zval(this_ptr, SL("_checkedPath"), path TSRMLS_CC); PHALCON_INIT_VAR(c6); ZVAL_STRING(c6, "loader:beforeCheckPath", 1); PHALCON_CALL_METHOD_PARAMS_2_NORETURN(events_manager, "fire", c6, this_ptr, PH_NO_CHECK); } if (phalcon_file_exists(path TSRMLS_CC) == SUCCESS) { if (phalcon_require(path TSRMLS_CC) == FAILURE) { return; } PHALCON_MM_RESTORE(); RETURN_TRUE; } zend_hash_move_forward_ex(ah3, &hp3); goto fes_0c08_3; fee_0c08_3: if(0){} zend_hash_move_forward_ex(ah2, &hp2); goto fes_0c08_2; fee_0c08_2: if (zend_is_true(events_manager)) { PHALCON_INIT_VAR(c7); ZVAL_STRING(c7, "loader:afterCheckClass", 1); PHALCON_CALL_METHOD_PARAMS_2_NORETURN(events_manager, "fire", c7, this_ptr, PH_NO_CHECK); } PHALCON_MM_RESTORE(); RETURN_FALSE; }
/** * Generates SQL to add a column to a table * * @param string $tableName * @param string $schemaName * @param Phalcon\Db\Column $column * @return string */ PHP_METHOD(Phalcon_Db_Dialect_Mysql, addColumn){ zval *table_name = NULL, *schema_name = NULL, *column = NULL, *sql = NULL, *after_position = NULL; zval *r0 = NULL, *r1 = NULL, *r2 = NULL, *r3 = NULL, *r4 = NULL, *r5 = NULL; zval *t0 = NULL, *t1 = NULL; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zzz", &table_name, &schema_name, &column) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } if (Z_TYPE_P(column) != IS_OBJECT) { PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Column parameter must be an instance of Phalcon\\Db\\Column"); return; } if (zend_is_true(schema_name)) { PHALCON_INIT_VAR(sql); PHALCON_CONCAT_SVSVS(sql, "ALTER TABLE `", schema_name, "`.`", table_name, "` ADD "); } else { PHALCON_INIT_VAR(sql); PHALCON_CONCAT_SVS(sql, "ALTER TABLE `", table_name, "` ADD "); } PHALCON_ALLOC_ZVAL_MM(r0); PHALCON_CALL_METHOD(r0, column, "getname", PH_NO_CHECK); PHALCON_ALLOC_ZVAL_MM(r1); PHALCON_CALL_SELF_PARAMS_1(r1, this_ptr, "getcolumndefinition", column); PHALCON_ALLOC_ZVAL_MM(r2); PHALCON_CONCAT_SVSV(r2, "`", r0, "` ", r1); phalcon_concat_self(&sql, r2 TSRMLS_CC); PHALCON_ALLOC_ZVAL_MM(r3); PHALCON_CALL_METHOD(r3, column, "isnotnull", PH_NO_CHECK); if (zend_is_true(r3)) { PHALCON_INIT_VAR(t0); ZVAL_STRING(t0, " NOT NULL", 1); phalcon_concat_self(&sql, t0 TSRMLS_CC); } PHALCON_ALLOC_ZVAL_MM(r4); PHALCON_CALL_METHOD(r4, column, "isfirst", PH_NO_CHECK); if (zend_is_true(r4)) { PHALCON_INIT_VAR(t1); ZVAL_STRING(t1, " FIRST", 1); phalcon_concat_self(&sql, t1 TSRMLS_CC); } else { PHALCON_INIT_VAR(after_position); PHALCON_CALL_METHOD(after_position, column, "getafterposition", PH_NO_CHECK); if (zend_is_true(after_position)) { PHALCON_ALLOC_ZVAL_MM(r5); PHALCON_CONCAT_SV(r5, " AFTER ", after_position); phalcon_concat_self(&sql, r5 TSRMLS_CC); } } RETURN_CTOR(sql); }
/** * Returns the string meaning of a logger constant * * @param integer $type * @return string */ PHP_METHOD(Phalcon_Logger_Adapter_File, getTypeString){ zval *type = NULL; zval *r0 = NULL, *r1 = NULL, *r2 = NULL, *r3 = NULL, *r4 = NULL, *r5 = NULL, *r6 = NULL; zval *r7 = NULL, *r8 = NULL, *r9 = NULL; zval *t0 = NULL, *t1 = NULL, *t2 = NULL, *t3 = NULL, *t4 = NULL, *t5 = NULL, *t6 = NULL; zval *t7 = NULL, *t8 = NULL, *t9 = NULL; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &type) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } PHALCON_SEPARATE_PARAM(type); PHALCON_INIT_VAR(t0); ZVAL_LONG(t0, 7); PHALCON_ALLOC_ZVAL_MM(r0); is_equal_function(r0, type, t0 TSRMLS_CC); if (zend_is_true(r0)) { PHALCON_INIT_VAR(type); ZVAL_STRING(type, "DEBUG", 1); goto se_654f_0; } PHALCON_INIT_VAR(t1); ZVAL_LONG(t1, 3); PHALCON_ALLOC_ZVAL_MM(r1); is_equal_function(r1, type, t1 TSRMLS_CC); if (zend_is_true(r1)) { PHALCON_INIT_VAR(type); ZVAL_STRING(type, "ERROR", 1); goto se_654f_0; } PHALCON_INIT_VAR(t2); ZVAL_LONG(t2, 4); PHALCON_ALLOC_ZVAL_MM(r2); is_equal_function(r2, type, t2 TSRMLS_CC); if (zend_is_true(r2)) { PHALCON_INIT_VAR(type); ZVAL_STRING(type, "WARNING", 1); goto se_654f_0; } PHALCON_INIT_VAR(t3); ZVAL_LONG(t3, 1); PHALCON_ALLOC_ZVAL_MM(r3); is_equal_function(r3, type, t3 TSRMLS_CC); if (zend_is_true(r3)) { PHALCON_INIT_VAR(type); ZVAL_STRING(type, "CRITICAL", 1); goto se_654f_0; } PHALCON_INIT_VAR(t4); ZVAL_LONG(t4, 8); PHALCON_ALLOC_ZVAL_MM(r4); is_equal_function(r4, type, t4 TSRMLS_CC); if (zend_is_true(r4)) { PHALCON_INIT_VAR(type); ZVAL_STRING(type, "CUSTOM", 1); goto se_654f_0; } PHALCON_INIT_VAR(t5); ZVAL_LONG(t5, 2); PHALCON_ALLOC_ZVAL_MM(r5); is_equal_function(r5, type, t5 TSRMLS_CC); if (zend_is_true(r5)) { PHALCON_INIT_VAR(type); ZVAL_STRING(type, "ALERT", 1); goto se_654f_0; } PHALCON_INIT_VAR(t6); ZVAL_LONG(t6, 5); PHALCON_ALLOC_ZVAL_MM(r6); is_equal_function(r6, type, t6 TSRMLS_CC); if (zend_is_true(r6)) { PHALCON_INIT_VAR(type); ZVAL_STRING(type, "NOTICE", 1); goto se_654f_0; } PHALCON_INIT_VAR(t7); ZVAL_LONG(t7, 6); PHALCON_ALLOC_ZVAL_MM(r7); is_equal_function(r7, type, t7 TSRMLS_CC); if (zend_is_true(r7)) { PHALCON_INIT_VAR(type); ZVAL_STRING(type, "INFO", 1); goto se_654f_0; } PHALCON_INIT_VAR(t8); ZVAL_LONG(t8, 0); PHALCON_ALLOC_ZVAL_MM(r8); is_equal_function(r8, type, t8 TSRMLS_CC); if (zend_is_true(r8)) { PHALCON_INIT_VAR(type); ZVAL_STRING(type, "EMERGENCE", 1); goto se_654f_0; } PHALCON_INIT_VAR(t9); ZVAL_LONG(t9, 9); PHALCON_ALLOC_ZVAL_MM(r9); is_equal_function(r9, type, t9 TSRMLS_CC); if (zend_is_true(r9)) { PHALCON_INIT_VAR(type); ZVAL_STRING(type, "SPECIAL", 1); goto se_654f_0; } PHALCON_INIT_VAR(type); ZVAL_STRING(type, "CUSTOM", 1); se_654f_0: RETURN_CCTOR(type); }
/** * Generates SQL to add the table creation options * * @param array $definition * @return array */ PHP_METHOD(Phalcon_Db_Dialect_Mysql, _getTableOptions){ zval *definition = NULL, *table_options = NULL, *engine = NULL, *auto_increment = NULL; zval *table_collation = NULL, *collation_parts = 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; zval *c0 = NULL, *c1 = NULL; int eval_int; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &definition) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } PHALCON_INIT_VAR(table_options); array_init(table_options); PHALCON_ALLOC_ZVAL_MM(r0); phalcon_array_fetch_string(&r0, definition, SL("options"), PH_NOISY_CC); eval_int = phalcon_array_isset_string(r0, SL("ENGINE")+1); if (eval_int) { PHALCON_ALLOC_ZVAL_MM(r1); phalcon_array_fetch_string(&r1, definition, SL("options"), PH_NOISY_CC); PHALCON_INIT_VAR(engine); phalcon_array_fetch_string(&engine, r1, SL("ENGINE"), PH_NOISY_CC); PHALCON_ALLOC_ZVAL_MM(r2); phalcon_array_fetch_string(&r2, definition, SL("options"), PH_NOISY_CC); PHALCON_ALLOC_ZVAL_MM(r3); phalcon_array_fetch_string(&r3, r2, SL("ENGINE"), PH_NOISY_CC); if (zend_is_true(r3)) { PHALCON_ALLOC_ZVAL_MM(r4); PHALCON_CONCAT_SV(r4, "ENGINE=", engine); phalcon_array_append(&table_options, r4, PH_SEPARATE TSRMLS_CC); } } PHALCON_ALLOC_ZVAL_MM(r5); phalcon_array_fetch_string(&r5, definition, SL("options"), PH_NOISY_CC); eval_int = phalcon_array_isset_string(r5, SL("AUTO_INCREMENT")+1); if (eval_int) { PHALCON_ALLOC_ZVAL_MM(r6); phalcon_array_fetch_string(&r6, definition, SL("options"), PH_NOISY_CC); PHALCON_INIT_VAR(auto_increment); phalcon_array_fetch_string(&auto_increment, r6, SL("AUTO_INCREMENT"), PH_NOISY_CC); if (zend_is_true(auto_increment)) { PHALCON_ALLOC_ZVAL_MM(r7); PHALCON_CONCAT_SV(r7, "AUTO_INCREMENT=", auto_increment); phalcon_array_append(&table_options, r7, PH_SEPARATE TSRMLS_CC); } } PHALCON_ALLOC_ZVAL_MM(r8); phalcon_array_fetch_string(&r8, definition, SL("options"), PH_NOISY_CC); eval_int = phalcon_array_isset_string(r8, SL("TABLE_COLLATION")+1); if (eval_int) { PHALCON_ALLOC_ZVAL_MM(r9); phalcon_array_fetch_string(&r9, definition, SL("options"), PH_NOISY_CC); PHALCON_INIT_VAR(table_collation); phalcon_array_fetch_string(&table_collation, r9, SL("TABLE_COLLATION"), PH_NOISY_CC); if (zend_is_true(table_collation)) { PHALCON_INIT_VAR(c0); ZVAL_STRING(c0, "_", 1); PHALCON_INIT_VAR(collation_parts); phalcon_fast_explode(collation_parts, c0, table_collation TSRMLS_CC); PHALCON_ALLOC_ZVAL_MM(r10); phalcon_array_fetch_long(&r10, collation_parts, 0, PH_NOISY_CC); PHALCON_ALLOC_ZVAL_MM(r11); PHALCON_CONCAT_SV(r11, "DEFAULT CHARSET=", r10); phalcon_array_append(&table_options, r11, PH_SEPARATE TSRMLS_CC); PHALCON_ALLOC_ZVAL_MM(r12); PHALCON_CONCAT_SV(r12, "COLLATE=", table_collation); phalcon_array_append(&table_options, r12, PH_SEPARATE TSRMLS_CC); } } PHALCON_ALLOC_ZVAL_MM(r13); phalcon_fast_count(r13, table_options TSRMLS_CC); if (zend_is_true(r13)) { PHALCON_INIT_VAR(c1); ZVAL_STRING(c1, " ", 1); PHALCON_ALLOC_ZVAL_MM(r14); phalcon_fast_join(r14, c1, table_options TSRMLS_CC); RETURN_CTOR(r14); } PHALCON_MM_RESTORE(); RETURN_NULL(); }
/** * Applies the internal format to the message * * @param string $message * @param int $type * @param int $time * @return string */ PHP_METHOD(Phalcon_Logger_Adapter_File, _applyFormat){ zval *message = NULL, *type = NULL, *time = NULL, *format = NULL; zval *c0 = NULL, *c1 = NULL, *c2 = NULL; zval *t0 = NULL; zval *r0 = NULL, *r1 = NULL, *r2 = NULL, *r3 = NULL, *r4 = NULL; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz|z", &message, &type, &time) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } if (!time) { PHALCON_ALLOC_ZVAL_MM(time); ZVAL_LONG(time, 0); } else { PHALCON_SEPARATE_PARAM(time); } if (!zend_is_true(time)) { PHALCON_INIT_VAR(time); PHALCON_CALL_FUNC(time, "time"); } PHALCON_INIT_VAR(format); phalcon_read_property(&format, this_ptr, SL("_format"), PH_NOISY_CC); PHALCON_INIT_VAR(c0); ZVAL_STRING(c0, "%date%", 1); PHALCON_ALLOC_ZVAL_MM(t0); phalcon_read_property(&t0, this_ptr, SL("_dateFormat"), PH_NOISY_CC); PHALCON_ALLOC_ZVAL_MM(r0); PHALCON_CALL_FUNC_PARAMS_2(r0, "date", t0, time); PHALCON_ALLOC_ZVAL_MM(r1); phalcon_fast_str_replace(r1, c0, r0, format TSRMLS_CC); PHALCON_CPY_WRT(format, r1); PHALCON_INIT_VAR(c1); ZVAL_STRING(c1, "%type%", 1); PHALCON_ALLOC_ZVAL_MM(r2); PHALCON_CALL_METHOD_PARAMS_1(r2, this_ptr, "gettypestring", type, PH_NO_CHECK); PHALCON_ALLOC_ZVAL_MM(r3); phalcon_fast_str_replace(r3, c1, r2, format TSRMLS_CC); PHALCON_CPY_WRT(format, r3); PHALCON_INIT_VAR(c2); ZVAL_STRING(c2, "%message%", 1); PHALCON_ALLOC_ZVAL_MM(r4); phalcon_fast_str_replace(r4, c2, message, format TSRMLS_CC); PHALCON_CPY_WRT(format, r4); RETURN_CCTOR(format); }
/** * 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 * *<code> * //Inserting data * $success = $connection->execute("INSERT INTO robots VALUES (1, 'Astro Boy')"); * $success = $connection->execute("INSERT INTO robots VALUES (?, ?)", array(1, 'Astro Boy')); *</code> * * @param string $sqlStatement * @param array $placeholders * @param array $dataTypes * @return boolean */ PHP_METHOD(Phalcon_Db_Adapter_Pdo, execute){ zval *sql_statement = NULL, *placeholders = NULL, *data_types = NULL; zval *events_manager = NULL, *event_name = NULL, *status = NULL, *pdo = NULL; zval *statement = NULL, *affected_rows = NULL; zval *r0 = NULL; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|zz", &sql_statement, &placeholders, &data_types) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } if (!placeholders) { PHALCON_ALLOC_ZVAL_MM(placeholders); ZVAL_NULL(placeholders); } if (!data_types) { PHALCON_ALLOC_ZVAL_MM(data_types); ZVAL_NULL(data_types); } PHALCON_INIT_VAR(events_manager); phalcon_read_property(&events_manager, this_ptr, SL("_eventsManager"), PH_NOISY_CC); if (Z_TYPE_P(events_manager) == IS_OBJECT) { PHALCON_INIT_VAR(event_name); ZVAL_STRING(event_name, "db:beforeQuery", 1); phalcon_update_property_zval(this_ptr, SL("_sqlStatement"), sql_statement TSRMLS_CC); PHALCON_INIT_VAR(status); PHALCON_CALL_METHOD_PARAMS_3(status, events_manager, "fire", event_name, this_ptr, placeholders, PH_NO_CHECK); if (PHALCON_IS_FALSE(status)) { PHALCON_MM_RESTORE(); RETURN_FALSE; } } PHALCON_INIT_VAR(pdo); phalcon_read_property(&pdo, this_ptr, SL("_pdo"), PH_NOISY_CC); if (Z_TYPE_P(placeholders) == IS_ARRAY) { PHALCON_INIT_VAR(statement); PHALCON_CALL_METHOD_PARAMS_1(statement, pdo, "prepare", sql_statement, PH_NO_CHECK); if (Z_TYPE_P(statement) == IS_OBJECT) { PHALCON_ALLOC_ZVAL_MM(r0); PHALCON_CALL_METHOD_PARAMS_3(r0, this_ptr, "_executeprepared", statement, placeholders, data_types, PH_NO_CHECK); PHALCON_CPY_WRT(statement, r0); PHALCON_INIT_VAR(affected_rows); PHALCON_CALL_METHOD(affected_rows, statement, "rowcount", PH_NO_CHECK); } } else { PHALCON_INIT_VAR(affected_rows); PHALCON_CALL_METHOD_PARAMS_1(affected_rows, pdo, "exec", sql_statement, PH_NO_CHECK); } if (Z_TYPE_P(affected_rows) == IS_LONG) { phalcon_update_property_zval(this_ptr, SL("_affectedRows"), affected_rows TSRMLS_CC); if (Z_TYPE_P(events_manager) == IS_OBJECT) { PHALCON_INIT_VAR(event_name); ZVAL_STRING(event_name, "db:afterQuery", 1); PHALCON_CALL_METHOD_PARAMS_3_NORETURN(events_manager, "fire", event_name, this_ptr, placeholders, PH_NO_CHECK); } } PHALCON_MM_RESTORE(); RETURN_TRUE; }
/** * Sends/Writes messages to the file log * * @param string $message * @param int $type */ PHP_METHOD(Phalcon_Logger_Adapter_File, log){ zval *message = NULL, *type = NULL, *msg = NULL; zval *t0 = NULL, *t1 = NULL, *t2 = NULL, *t3 = NULL, *t4 = NULL; zval *r0 = NULL, *r1 = NULL, *r2 = NULL, *r3 = NULL; zval *c0 = NULL; zval *i0 = NULL; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|z", &message, &type) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } if (!type) { PHALCON_ALLOC_ZVAL_MM(type); ZVAL_LONG(type, 7); } PHALCON_ALLOC_ZVAL_MM(t0); phalcon_read_property(&t0, this_ptr, SL("_fileHandler"), PH_NOISY_CC); if (!zend_is_true(t0)) { PHALCON_THROW_EXCEPTION_STR(phalcon_logger_exception_ce, "Cannot send message to the log because it is invalid"); return; } PHALCON_ALLOC_ZVAL_MM(r0); PHALCON_CALL_FUNC_PARAMS_1(r0, "is_scalar", message); if (zend_is_true(r0)) { PHALCON_INIT_VAR(c0); ZVAL_BOOL(c0, 1); PHALCON_INIT_VAR(msg); PHALCON_CALL_FUNC_PARAMS_2(msg, "print_r", message, c0); } PHALCON_ALLOC_ZVAL_MM(t1); phalcon_read_property(&t1, this_ptr, SL("_transaction"), PH_NOISY_CC); if (zend_is_true(t1)) { PHALCON_ALLOC_ZVAL_MM(i0); object_init_ex(i0, phalcon_logger_item_ce); PHALCON_ALLOC_ZVAL_MM(r1); PHALCON_CALL_FUNC(r1, "time"); PHALCON_CALL_METHOD_PARAMS_3_NORETURN(i0, "__construct", message, type, r1, PH_CHECK); PHALCON_ALLOC_ZVAL_MM(t2); phalcon_read_property(&t2, this_ptr, SL("_quenue"), PH_NOISY_CC); phalcon_array_append(&t2, i0, 0 TSRMLS_CC); phalcon_update_property_zval(this_ptr, SL("_quenue"), t2 TSRMLS_CC); } else { PHALCON_ALLOC_ZVAL_MM(t3); phalcon_read_property(&t3, this_ptr, SL("_fileHandler"), PH_NOISY_CC); PHALCON_ALLOC_ZVAL_MM(r2); PHALCON_CALL_METHOD_PARAMS_2(r2, this_ptr, "_applyformat", message, type, PH_NO_CHECK); PHALCON_ALLOC_ZVAL_MM(t4); zend_get_constant(SL("PHP_EOL"), t4 TSRMLS_CC); PHALCON_ALLOC_ZVAL_MM(r3); PHALCON_CONCAT_VV(r3, r2, t4); PHALCON_CALL_FUNC_PARAMS_2_NORETURN("fputs", t3, r3); } PHALCON_MM_RESTORE(); }
/** * Lists table indexes * * @param string $table * @param string $schema * @return Phalcon\Db\Index[] */ PHP_METHOD(Phalcon_Db_Adapter_Pdo, describeIndexes){ zval *table = NULL, *schema = NULL, *dialect = NULL, *fetch_assoc = NULL, *sql = NULL; zval *describe = NULL, *indexes = NULL, *index = NULL, *key_name = NULL, *empty_arr = NULL; zval *column_name = NULL, *index_objects = NULL, *index_columns = NULL; zval *name = NULL; HashTable *ah0, *ah1; HashPosition hp0, hp1; 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", &table, &schema) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } if (!schema) { PHALCON_ALLOC_ZVAL_MM(schema); ZVAL_NULL(schema); } PHALCON_INIT_VAR(dialect); phalcon_read_property(&dialect, this_ptr, SL("_dialect"), PH_NOISY_CC); PHALCON_INIT_VAR(fetch_assoc); phalcon_get_class_constant(fetch_assoc, phalcon_db_ce, SL("FETCH_ASSOC") TSRMLS_CC); PHALCON_INIT_VAR(sql); PHALCON_CALL_METHOD_PARAMS_2(sql, dialect, "describeindexes", table, schema, PH_NO_CHECK); PHALCON_INIT_VAR(describe); PHALCON_CALL_METHOD_PARAMS_2(describe, this_ptr, "fetchall", sql, fetch_assoc, PH_NO_CHECK); PHALCON_INIT_VAR(indexes); array_init(indexes); if (!phalcon_valid_foreach(describe TSRMLS_CC)) { return; } ah0 = Z_ARRVAL_P(describe); zend_hash_internal_pointer_reset_ex(ah0, &hp0); ph_cycle_start_0: if(zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) != SUCCESS){ goto ph_cycle_end_0; } PHALCON_GET_FOREACH_VALUE(index); PHALCON_INIT_VAR(key_name); phalcon_array_fetch_string(&key_name, index, SL("key_name"), PH_NOISY_CC); eval_int = phalcon_array_isset(indexes, key_name); if (!eval_int) { PHALCON_INIT_VAR(empty_arr); array_init(empty_arr); phalcon_array_update_zval(&indexes, key_name, &empty_arr, PH_COPY | PH_SEPARATE TSRMLS_CC); } PHALCON_INIT_VAR(column_name); phalcon_array_fetch_string(&column_name, index, SL("column_name"), PH_NOISY_CC); phalcon_array_update_append_multi_2(&indexes, key_name, column_name, 0 TSRMLS_CC); zend_hash_move_forward_ex(ah0, &hp0); goto ph_cycle_start_0; ph_cycle_end_0: PHALCON_INIT_VAR(index_objects); array_init(index_objects); if (!phalcon_valid_foreach(indexes TSRMLS_CC)) { return; } ah1 = Z_ARRVAL_P(indexes); zend_hash_internal_pointer_reset_ex(ah1, &hp1); ph_cycle_start_1: if(zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) != SUCCESS){ goto ph_cycle_end_1; } PHALCON_INIT_VAR(name); PHALCON_GET_FOREACH_KEY(name, ah1, hp1); PHALCON_GET_FOREACH_VALUE(index_columns); PHALCON_INIT_VAR(index); object_init_ex(index, phalcon_db_index_ce); PHALCON_CALL_METHOD_PARAMS_2_NORETURN(index, "__construct", name, index_columns, PH_CHECK); phalcon_array_update_zval(&index_objects, name, &index, PH_COPY | PH_SEPARATE TSRMLS_CC); zend_hash_move_forward_ex(ah1, &hp1); goto ph_cycle_start_1; ph_cycle_end_1: RETURN_CTOR(index_objects); }
/** * Cache the actual view render to certain level * * @param boolean|array $options */ PHP_METHOD(Phalcon_Mvc_View, cache){ zval *options = NULL, *view_options = NULL, *cache_options = NULL; zval *value = NULL, *key = NULL, *cache_level = 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", &options) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } if (!options) { PHALCON_ALLOC_ZVAL_MM(options); ZVAL_BOOL(options, 1); } if (Z_TYPE_P(options) == IS_ARRAY) { PHALCON_INIT_VAR(view_options); phalcon_read_property(&view_options, this_ptr, SL("_options"), PH_NOISY_CC); eval_int = phalcon_array_isset_string(view_options, SL("cache")+1); if (eval_int) { PHALCON_INIT_VAR(cache_options); phalcon_array_fetch_string(&cache_options, view_options, SL("cache"), PH_NOISY_CC); } else { PHALCON_INIT_VAR(cache_options); array_init(cache_options); } if (!phalcon_valid_foreach(options TSRMLS_CC)) { return; } ah0 = Z_ARRVAL_P(options); zend_hash_internal_pointer_reset_ex(ah0, &hp0); fes_ecde_4: if(zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) != SUCCESS){ goto fee_ecde_4; } PHALCON_INIT_VAR(key); PHALCON_GET_FOREACH_KEY(key, ah0, hp0); PHALCON_INIT_VAR(value); ZVAL_ZVAL(value, *hd, 1, 0); phalcon_array_update_zval(&cache_options, key, &value, PH_COPY | PH_SEPARATE TSRMLS_CC); zend_hash_move_forward_ex(ah0, &hp0); goto fes_ecde_4; fee_ecde_4: eval_int = phalcon_array_isset_string(cache_options, SL("level")+1); if (eval_int) { PHALCON_INIT_VAR(cache_level); phalcon_array_fetch_string(&cache_level, cache_options, SL("level"), PH_NOISY_CC); phalcon_update_property_zval(this_ptr, SL("_cacheLevel"), cache_level TSRMLS_CC); } else { phalcon_update_property_long(this_ptr, SL("_cacheLevel"), 5 TSRMLS_CC); } phalcon_update_property_zval(view_options, SL("cache"), cache_options TSRMLS_CC); phalcon_update_property_zval(this_ptr, SL("_options"), view_options TSRMLS_CC); } else { if (zend_is_true(options)) { phalcon_update_property_long(this_ptr, SL("_cacheLevel"), 5 TSRMLS_CC); } else { phalcon_update_property_long(this_ptr, SL("_cacheLevel"), 0 TSRMLS_CC); } } PHALCON_MM_RESTORE(); }
/** * Returns the prefix for all the generated urls. By default / * * @return string */ PHP_METHOD(Phalcon_Mvc_Url, getBaseUri){ zval *base_uri = NULL, *slash = NULL, *php_self = NULL, *dirname = NULL, *dir_parts = NULL; zval *slice = NULL, *uri = NULL; zval *g0 = NULL; zval *c0 = NULL; zval *r0 = NULL; zval *t0 = NULL, *t1 = NULL; int eval_int; PHALCON_MM_GROW(); PHALCON_INIT_VAR(base_uri); phalcon_read_property(&base_uri, this_ptr, SL("_baseUri"), PH_NOISY_CC); if (Z_TYPE_P(base_uri) == IS_NULL) { PHALCON_INIT_VAR(slash); ZVAL_STRING(slash, "/", 1); phalcon_get_global(&g0, SL("_SERVER")+1 TSRMLS_CC); eval_int = phalcon_array_isset_string(g0, SL("PHP_SELF")+1); if (eval_int) { PHALCON_INIT_VAR(php_self); phalcon_array_fetch_string(&php_self, g0, SL("PHP_SELF"), PH_NOISY_CC); PHALCON_INIT_VAR(dirname); PHALCON_CALL_FUNC_PARAMS_1(dirname, "dirname", php_self); PHALCON_INIT_VAR(dir_parts); phalcon_fast_explode(dir_parts, slash, dirname TSRMLS_CC); PHALCON_INIT_VAR(c0); ZVAL_LONG(c0, 1); PHALCON_INIT_VAR(t1); ZVAL_LONG(t1, 1); PHALCON_INIT_VAR(t0); ZVAL_LONG(t0, -1); PHALCON_ALLOC_ZVAL_MM(r0); mul_function(r0, t0, t1 TSRMLS_CC); PHALCON_INIT_VAR(slice); PHALCON_CALL_FUNC_PARAMS_3(slice, "array_slice", dir_parts, c0, r0); PHALCON_INIT_VAR(uri); phalcon_fast_join(uri, slash, slice TSRMLS_CC); } else { PHALCON_INIT_VAR(uri); ZVAL_STRING(uri, "", 1); } if (PHALCON_COMPARE_STRING(uri, "")) { PHALCON_CPY_WRT(base_uri, slash); } else { PHALCON_INIT_VAR(base_uri); PHALCON_CONCAT_VVV(base_uri, slash, uri, slash); } phalcon_update_property_zval(this_ptr, SL("_baseUri"), base_uri TSRMLS_CC); } RETURN_CCTOR(base_uri); }
/** * Checks whether view exists on registered extensions and render it * * @param array $engines * @param string $viewPath * @param boolean $silence * @param boolean $mustClean * @param Phalcon\Cache\Backend $cache */ PHP_METHOD(Phalcon_Mvc_View, _engineRender){ zval *engines = NULL, *view_path = NULL, *silence = NULL, *must_clean = NULL; zval *cache = NULL, *not_exists = NULL, *view_params = NULL, *views_dir = NULL; zval *base_path = NULL, *views_dir_path = NULL, *events_manager = NULL; zval *render_level = NULL, *cache_level = NULL, *is_started = NULL; zval *key = NULL, *view_options = NULL, *cache_options = NULL, *cached_view = NULL; zval *is_fresh = NULL, *engine = NULL, *extension = NULL, *view_engine_path = NULL; zval *event_name = NULL, *status = NULL, *exception_message = NULL; zval *exception = 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, "zzzzz", &engines, &view_path, &silence, &must_clean, &cache) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } PHALCON_INIT_VAR(not_exists); ZVAL_BOOL(not_exists, 1); PHALCON_INIT_VAR(view_params); phalcon_read_property(&view_params, this_ptr, SL("_viewParams"), PH_NOISY_CC); PHALCON_INIT_VAR(views_dir); phalcon_read_property(&views_dir, this_ptr, SL("_viewsDir"), PH_NOISY_CC); PHALCON_INIT_VAR(base_path); phalcon_read_property(&base_path, this_ptr, SL("_basePath"), PH_NOISY_CC); PHALCON_INIT_VAR(views_dir_path); PHALCON_CONCAT_VVV(views_dir_path, base_path, views_dir, view_path); PHALCON_INIT_VAR(events_manager); phalcon_read_property(&events_manager, this_ptr, SL("_eventsManager"), PH_NOISY_CC); if (Z_TYPE_P(cache) == IS_OBJECT) { PHALCON_INIT_VAR(render_level); phalcon_read_property(&render_level, this_ptr, SL("_renderLevel"), PH_NOISY_CC); PHALCON_INIT_VAR(cache_level); phalcon_read_property(&cache_level, this_ptr, SL("_cacheLevel"), PH_NOISY_CC); PHALCON_ALLOC_ZVAL_MM(r0); is_smaller_or_equal_function(r0, cache_level, render_level TSRMLS_CC); if (zend_is_true(r0)) { PHALCON_INIT_VAR(is_started); PHALCON_CALL_METHOD(is_started, cache, "isstarted", PH_NO_CHECK); if (!zend_is_true(is_started)) { PHALCON_INIT_VAR(key); ZVAL_NULL(key); PHALCON_INIT_VAR(view_options); phalcon_read_property(&view_options, this_ptr, SL("_options"), PH_NOISY_CC); eval_int = phalcon_array_isset_string(view_options, SL("cache")+1); if (eval_int) { PHALCON_INIT_VAR(cache_options); phalcon_array_fetch_string(&cache_options, view_options, SL("cache"), PH_NOISY_CC); if (Z_TYPE_P(cache_options) == IS_ARRAY) { eval_int = phalcon_array_isset_string(cache_options, SL("key")+1); if (eval_int) { PHALCON_INIT_VAR(key); phalcon_array_fetch_string(&key, cache_options, SL("key"), PH_NOISY_CC); } } } if (Z_TYPE_P(key) == IS_NULL) { PHALCON_INIT_VAR(key); PHALCON_CALL_FUNC_PARAMS_1(key, "md5", view_path); } PHALCON_INIT_VAR(cached_view); PHALCON_CALL_METHOD_PARAMS_1(cached_view, cache, "start", key, PH_NO_CHECK); if (Z_TYPE_P(cached_view) != IS_NULL) { phalcon_update_property_zval(this_ptr, SL("_content"), cached_view TSRMLS_CC); PHALCON_MM_RESTORE(); RETURN_NULL(); } } PHALCON_INIT_VAR(is_fresh); PHALCON_CALL_METHOD(is_fresh, cache, "isfresh", PH_NO_CHECK); if (!zend_is_true(is_fresh)) { PHALCON_MM_RESTORE(); RETURN_NULL(); } } } if (!phalcon_valid_foreach(engines TSRMLS_CC)) { return; } ah0 = Z_ARRVAL_P(engines); zend_hash_internal_pointer_reset_ex(ah0, &hp0); fes_ecde_1: if(zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) != SUCCESS){ goto fee_ecde_1; } PHALCON_INIT_VAR(extension); PHALCON_GET_FOREACH_KEY(extension, ah0, hp0); PHALCON_INIT_VAR(engine); ZVAL_ZVAL(engine, *hd, 1, 0); PHALCON_INIT_VAR(view_engine_path); PHALCON_CONCAT_VV(view_engine_path, views_dir_path, extension); if (phalcon_file_exists(view_engine_path TSRMLS_CC) == SUCCESS) { if (Z_TYPE_P(events_manager) == IS_OBJECT) { phalcon_update_property_zval(this_ptr, SL("_activeRenderPath"), view_engine_path TSRMLS_CC); PHALCON_INIT_VAR(event_name); ZVAL_STRING(event_name, "view:beforeRenderView", 1); PHALCON_INIT_VAR(status); PHALCON_CALL_METHOD_PARAMS_2(status, events_manager, "fire", event_name, this_ptr, PH_NO_CHECK); if (Z_TYPE_P(status) == IS_BOOL && !Z_BVAL_P(status)) { zend_hash_move_forward_ex(ah0, &hp0); goto fes_ecde_1; } } PHALCON_CALL_METHOD_PARAMS_3_NORETURN(engine, "render", view_engine_path, view_params, must_clean, PH_NO_CHECK); PHALCON_INIT_VAR(not_exists); ZVAL_BOOL(not_exists, 0); if (Z_TYPE_P(events_manager) == IS_OBJECT) { phalcon_update_property_zval(this_ptr, SL("_activeRenderPath"), view_engine_path TSRMLS_CC); PHALCON_INIT_VAR(event_name); ZVAL_STRING(event_name, "view:afterRenderView", 1); PHALCON_INIT_VAR(status); PHALCON_CALL_METHOD_PARAMS_2(status, events_manager, "fire", event_name, this_ptr, PH_NO_CHECK); if (Z_TYPE_P(status) == IS_BOOL && !Z_BVAL_P(status)) { zend_hash_move_forward_ex(ah0, &hp0); goto fes_ecde_1; } } goto fee_ecde_1; } zend_hash_move_forward_ex(ah0, &hp0); goto fes_ecde_1; fee_ecde_1: if (Z_TYPE_P(not_exists) == IS_BOOL && Z_BVAL_P(not_exists)) { if (!zend_is_true(silence)) { PHALCON_INIT_VAR(exception_message); PHALCON_CONCAT_SVS(exception_message, "View '", views_dir_path, "' was not found in the views directory"); PHALCON_INIT_VAR(exception); object_init_ex(exception, phalcon_mvc_view_exception_ce); PHALCON_CALL_METHOD_PARAMS_1_NORETURN(exception, "__construct", exception_message, PH_CHECK); phalcon_throw_exception(exception TSRMLS_CC); return; } } PHALCON_MM_RESTORE(); }
/** * Rollbacks the transaction * * @param string $rollbackMessage * @param Phalcon\Mvc\Model $rollbackRecord * @return boolean */ PHP_METHOD(Phalcon_Mvc_Model_Transaction, rollback){ zval *rollback_message = NULL, *rollback_record = NULL; zval *manager = NULL, *call_object = NULL, *arguments = NULL, *connection = NULL; zval *success = NULL, *exception = NULL; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|zz", &rollback_message, &rollback_record) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } if (!rollback_message) { PHALCON_ALLOC_ZVAL_MM(rollback_message); ZVAL_NULL(rollback_message); } else { PHALCON_SEPARATE_PARAM(rollback_message); } if (!rollback_record) { PHALCON_ALLOC_ZVAL_MM(rollback_record); ZVAL_NULL(rollback_record); } else { PHALCON_SEPARATE_PARAM(rollback_record); } PHALCON_INIT_VAR(manager); phalcon_read_property(&manager, this_ptr, SL("_manager"), PH_NOISY_CC); if (zend_is_true(manager)) { PHALCON_INIT_VAR(call_object); array_init(call_object); phalcon_array_append(&call_object, manager, PH_SEPARATE TSRMLS_CC); add_next_index_stringl(call_object, SL("notifyRollback"), 1); PHALCON_INIT_VAR(arguments); array_init(arguments); phalcon_array_append(&arguments, this_ptr, PH_SEPARATE TSRMLS_CC); PHALCON_CALL_FUNC_PARAMS_2_NORETURN("call_user_func_array", call_object, arguments); } PHALCON_INIT_VAR(connection); phalcon_read_property(&connection, this_ptr, SL("_connection"), PH_NOISY_CC); PHALCON_INIT_VAR(success); PHALCON_CALL_METHOD(success, connection, "rollback", PH_NO_CHECK); if (zend_is_true(success)) { if (!zend_is_true(rollback_message)) { PHALCON_INIT_VAR(rollback_message); ZVAL_STRING(rollback_message, "Transaction aborted", 1); } if (zend_is_true(rollback_record)) { phalcon_update_property_zval(this_ptr, SL("_rollbackRecord"), rollback_record TSRMLS_CC); } PHALCON_INIT_VAR(rollback_record); phalcon_read_property(&rollback_record, this_ptr, SL("_rollbackRecord"), PH_NOISY_CC); PHALCON_INIT_VAR(exception); object_init_ex(exception, phalcon_mvc_model_transaction_failed_ce); PHALCON_CALL_METHOD_PARAMS_2_NORETURN(exception, "__construct", rollback_message, rollback_record, PH_CHECK); phalcon_throw_exception(exception TSRMLS_CC); return; } PHALCON_MM_RESTORE(); }
/** * Handles routing information received from the rewrite engine * * @param string $uri */ PHP_METHOD(Phalcon_Mvc_Router, handle) { zval *uri = NULL, *real_uri = NULL, *request = NULL, *route_found = NULL, *parts = NULL; zval *params = NULL, *matches = NULL, *routes = NULL, *reversed_routes = NULL; zval *route = NULL, *methods = NULL, *dependency_injector = NULL; zval *service = NULL, *match_method = NULL, *pattern = NULL, *have_parenthesis = NULL; zval *paths = NULL, *position = NULL, *part = NULL, *match_position = NULL; zval *module = NULL, *default_module = NULL, *controller = NULL, *default_controller = NULL; zval *action = NULL, *default_action = NULL, *params_str = NULL, *one = NULL; zval *str_params = NULL, *slash = NULL, *params_merge = NULL, *default_params = NULL; HashTable *ah0, *ah1; HashPosition hp0, hp1; 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", &uri) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } if (!uri) { PHALCON_ALLOC_ZVAL_MM(uri); ZVAL_NULL(uri); } if (!zend_is_true(uri)) { PHALCON_INIT_VAR(real_uri); PHALCON_CALL_METHOD(real_uri, this_ptr, "_getrewriteuri", PH_NO_CHECK); } else { PHALCON_CPY_WRT(real_uri, uri); } PHALCON_INIT_VAR(request); ZVAL_NULL(request); PHALCON_INIT_VAR(route_found); ZVAL_BOOL(route_found, 0); PHALCON_INIT_VAR(parts); array_init(parts); PHALCON_INIT_VAR(params); array_init(params); PHALCON_INIT_VAR(matches); ZVAL_NULL(matches); phalcon_update_property_bool(this_ptr, SL("_wasMatched"), 0 TSRMLS_CC); PHALCON_INIT_VAR(routes); phalcon_read_property(&routes, this_ptr, SL("_routes"), PH_NOISY_CC); PHALCON_INIT_VAR(reversed_routes); PHALCON_CALL_FUNC_PARAMS_1(reversed_routes, "array_reverse", routes); if (!phalcon_valid_foreach(reversed_routes TSRMLS_CC)) { return; } ah0 = Z_ARRVAL_P(reversed_routes); zend_hash_internal_pointer_reset_ex(ah0, &hp0); ph_cycle_start_0: if(zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) != SUCCESS) { goto ph_cycle_end_0; } PHALCON_GET_FOREACH_VALUE(route); PHALCON_INIT_VAR(methods); PHALCON_CALL_METHOD(methods, route, "gethttpmethods", PH_NO_CHECK); if (Z_TYPE_P(methods) != IS_NULL) { if (Z_TYPE_P(request) == IS_NULL) { PHALCON_INIT_VAR(dependency_injector); phalcon_read_property(&dependency_injector, this_ptr, SL("_dependencyInjector"), PH_NOISY_CC); if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_dispatcher_exception_ce, "A dependency injection container is required to access the 'request' service"); return; } PHALCON_INIT_VAR(service); ZVAL_STRING(service, "request", 1); PHALCON_INIT_VAR(request); PHALCON_CALL_METHOD_PARAMS_1(request, dependency_injector, "getshared", service, PH_NO_CHECK); } PHALCON_INIT_VAR(match_method); PHALCON_CALL_METHOD_PARAMS_1(match_method, request, "ismethod", methods, PH_NO_CHECK); if (PHALCON_IS_FALSE(match_method)) { zend_hash_move_forward_ex(ah0, &hp0); goto ph_cycle_start_0; } } PHALCON_INIT_VAR(pattern); PHALCON_CALL_METHOD(pattern, route, "getcompiledpattern", PH_NO_CHECK); PHALCON_INIT_VAR(have_parenthesis); phalcon_fast_strpos_str(have_parenthesis, pattern, SL("(") TSRMLS_CC); if (PHALCON_IS_NOT_FALSE(have_parenthesis)) { Z_SET_ISREF_P(matches); PHALCON_INIT_VAR(route_found); PHALCON_CALL_FUNC_PARAMS_3(route_found, "preg_match", pattern, real_uri, matches); Z_UNSET_ISREF_P(matches); } else { PHALCON_INIT_VAR(route_found); is_equal_function(route_found, pattern, real_uri TSRMLS_CC); } if (zend_is_true(route_found)) { PHALCON_INIT_VAR(paths); PHALCON_CALL_METHOD(paths, route, "getpaths", PH_NO_CHECK); PHALCON_CPY_WRT(parts, paths); if (Z_TYPE_P(matches) == IS_ARRAY) { if (!phalcon_valid_foreach(paths TSRMLS_CC)) { return; } ah1 = Z_ARRVAL_P(paths); zend_hash_internal_pointer_reset_ex(ah1, &hp1); ph_cycle_start_1: if(zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) != SUCCESS) { goto ph_cycle_end_1; } PHALCON_INIT_VAR(part); PHALCON_GET_FOREACH_KEY(part, ah1, hp1); PHALCON_GET_FOREACH_VALUE(position); eval_int = phalcon_array_isset(matches, position); if (eval_int) { PHALCON_INIT_VAR(match_position); phalcon_array_fetch(&match_position, matches, position, PH_NOISY_CC); phalcon_array_update_zval(&parts, part, &match_position, PH_COPY | PH_SEPARATE TSRMLS_CC); } zend_hash_move_forward_ex(ah1, &hp1); goto ph_cycle_start_1; ph_cycle_end_1: phalcon_update_property_zval(this_ptr, SL("_matches"), matches TSRMLS_CC); } phalcon_update_property_zval(this_ptr, SL("_matchedRoute"), route TSRMLS_CC); goto ph_cycle_end_0; } zend_hash_move_forward_ex(ah0, &hp0); goto ph_cycle_start_0; ph_cycle_end_0: if (zend_is_true(route_found)) { eval_int = phalcon_array_isset_string(parts, SL("module")+1); if (eval_int) { PHALCON_INIT_VAR(module); phalcon_array_fetch_string(&module, parts, SL("module"), PH_NOISY_CC); phalcon_update_property_zval(this_ptr, SL("_module"), module TSRMLS_CC); PHALCON_SEPARATE(parts); phalcon_array_unset_string(parts, SL("module")+1); } else { PHALCON_INIT_VAR(default_module); phalcon_read_property(&default_module, this_ptr, SL("_defaultModule"), PH_NOISY_CC); phalcon_update_property_zval(this_ptr, SL("_module"), default_module TSRMLS_CC); } eval_int = phalcon_array_isset_string(parts, SL("controller")+1); if (eval_int) { PHALCON_INIT_VAR(controller); phalcon_array_fetch_string(&controller, parts, SL("controller"), PH_NOISY_CC); phalcon_update_property_zval(this_ptr, SL("_controller"), controller TSRMLS_CC); PHALCON_SEPARATE(parts); phalcon_array_unset_string(parts, SL("controller")+1); } else { PHALCON_INIT_VAR(default_controller); phalcon_read_property(&default_controller, this_ptr, SL("_defaultController"), PH_NOISY_CC); phalcon_update_property_zval(this_ptr, SL("_controller"), default_controller TSRMLS_CC); } eval_int = phalcon_array_isset_string(parts, SL("action")+1); if (eval_int) { PHALCON_INIT_VAR(action); phalcon_array_fetch_string(&action, parts, SL("action"), PH_NOISY_CC); phalcon_update_property_zval(this_ptr, SL("_action"), action TSRMLS_CC); PHALCON_SEPARATE(parts); phalcon_array_unset_string(parts, SL("action")+1); } else { PHALCON_INIT_VAR(default_action); phalcon_read_property(&default_action, this_ptr, SL("_defaultAction"), PH_NOISY_CC); phalcon_update_property_zval(this_ptr, SL("_action"), default_action TSRMLS_CC); } eval_int = phalcon_array_isset_string(parts, SL("params")+1); if (eval_int) { PHALCON_INIT_VAR(params_str); phalcon_array_fetch_string(¶ms_str, parts, SL("params"), PH_NOISY_CC); PHALCON_INIT_VAR(one); ZVAL_LONG(one, 1); PHALCON_INIT_VAR(str_params); PHALCON_CALL_FUNC_PARAMS_2(str_params, "substr", params_str, one); if (zend_is_true(str_params)) { PHALCON_INIT_VAR(slash); ZVAL_STRING(slash, "/", 1); PHALCON_INIT_VAR(params); phalcon_fast_explode(params, slash, str_params TSRMLS_CC); } PHALCON_SEPARATE(parts); phalcon_array_unset_string(parts, SL("params")+1); } PHALCON_INIT_VAR(params_merge); PHALCON_CALL_FUNC_PARAMS_2(params_merge, "array_merge", params, parts); phalcon_update_property_zval(this_ptr, SL("_params"), params_merge TSRMLS_CC); phalcon_update_property_bool(this_ptr, SL("_wasMatched"), 1 TSRMLS_CC); } else { PHALCON_INIT_VAR(default_module); phalcon_read_property(&default_module, this_ptr, SL("_defaultModule"), PH_NOISY_CC); phalcon_update_property_zval(this_ptr, SL("_module"), default_module TSRMLS_CC); PHALCON_INIT_VAR(default_controller); phalcon_read_property(&default_controller, this_ptr, SL("_defaultController"), PH_NOISY_CC); phalcon_update_property_zval(this_ptr, SL("_controller"), default_controller TSRMLS_CC); PHALCON_INIT_VAR(default_action); phalcon_read_property(&default_action, this_ptr, SL("_defaultAction"), PH_NOISY_CC); phalcon_update_property_zval(this_ptr, SL("_action"), default_action TSRMLS_CC); PHALCON_INIT_VAR(default_params); phalcon_read_property(&default_params, this_ptr, SL("_defaultParams"), PH_NOISY_CC); phalcon_update_property_zval(this_ptr, SL("_params"), default_params TSRMLS_CC); phalcon_update_property_bool(this_ptr, SL("_wasMatched"), 0 TSRMLS_CC); } PHALCON_MM_RESTORE(); }
/** * Add a route to the router * * @param string $pattern * @param string/array $paths */ PHP_METHOD(Phalcon_Mvc_Router, add){ zval *pattern = NULL, *paths = NULL, *parts = NULL, *route_paths = NULL, *pcre_pattern = NULL; zval *matches = NULL, *match = NULL, *n = NULL; zval *c0 = NULL, *c1 = NULL, *c2 = 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; zval *t0 = NULL, *t1 = NULL, *t2 = NULL; zval *a0 = NULL; zval *p0[] = { NULL, NULL, NULL, 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, "zz", &pattern, &paths) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } if (Z_TYPE_P(paths) == IS_STRING) { PHALCON_INIT_VAR(c0); ZVAL_STRING(c0, "::", 1); PHALCON_INIT_VAR(parts); phalcon_fast_explode(parts, c0, paths TSRMLS_CC); PHALCON_INIT_VAR(route_paths); array_init(route_paths); PHALCON_ALLOC_ZVAL_MM(r0); phalcon_array_fetch_long(&r0, parts, 0, PH_NOISY_CC); PHALCON_ALLOC_ZVAL_MM(r1); PHALCON_CALL_FUNC_PARAMS_1(r1, "strtolower", r0); phalcon_array_update_string(&route_paths, SL("controller"), &r1, PH_COPY | PH_SEPARATE TSRMLS_CC); eval_int = phalcon_array_isset_long(parts, 1); if (eval_int) { PHALCON_ALLOC_ZVAL_MM(r2); phalcon_array_fetch_long(&r2, parts, 1, PH_NOISY_CC); phalcon_array_update_string(&route_paths, SL("action"), &r2, PH_COPY | PH_SEPARATE TSRMLS_CC); } } else { PHALCON_CPY_WRT(route_paths, paths); } PHALCON_INIT_VAR(c1); ZVAL_STRING(c1, "#", 1); PHALCON_INIT_VAR(c2); ZVAL_STRING(c2, "\\#", 1); PHALCON_INIT_VAR(pcre_pattern); phalcon_fast_str_replace(pcre_pattern, c1, c2, pattern TSRMLS_CC); PHALCON_ALLOC_ZVAL_MM(r3); phalcon_fast_strpos_str(r3, pcre_pattern, SL("{") TSRMLS_CC); if (zend_is_true(r3)) { PHALCON_INIT_VAR(matches); array_init(matches); PHALCON_INIT_VAR(p0[0]); ZVAL_STRING(p0[0], "#{([a-zA-Z0-9\\_\\-]+):([^}]+)}#", 1); p0[1] = pcre_pattern; Z_SET_ISREF_P(matches); p0[2] = matches; PHALCON_INIT_VAR(t0); ZVAL_LONG(t0, 2); p0[3] = t0; PHALCON_ALLOC_ZVAL_MM(r4); PHALCON_CALL_FUNC_PARAMS(r4, "preg_match_all", 4, p0); Z_UNSET_ISREF_P(p0[2]); if (zend_is_true(r4)) { if (!phalcon_valid_foreach(matches TSRMLS_CC)) { return; } ah0 = Z_ARRVAL_P(matches); zend_hash_internal_pointer_reset_ex(ah0, &hp0); fes_c9ff_0: if(zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) != SUCCESS){ goto fee_c9ff_0; } PHALCON_INIT_VAR(n); PHALCON_GET_FOREACH_KEY(n, ah0, hp0); PHALCON_INIT_VAR(match); ZVAL_ZVAL(match, *hd, 1, 0); PHALCON_INIT_VAR(r5); phalcon_array_fetch_long(&r5, match, 0, PH_NOISY_CC); PHALCON_INIT_VAR(r6); phalcon_array_fetch_long(&r6, match, 2, PH_NOISY_CC); PHALCON_INIT_VAR(r7); PHALCON_CONCAT_SVS(r7, "(", r6, ")"); PHALCON_INIT_VAR(r8); phalcon_fast_str_replace(r8, r5, r7, pcre_pattern TSRMLS_CC); PHALCON_CPY_WRT(pcre_pattern, r8); PHALCON_INIT_VAR(t1); ZVAL_LONG(t1, 1); PHALCON_INIT_VAR(r9); phalcon_add_function(r9, n, t1 TSRMLS_CC); PHALCON_INIT_VAR(r10); phalcon_array_fetch_long(&r10, match, 1, PH_NOISY_CC); phalcon_array_update_zval(&route_paths, r10, &r9, PH_COPY | PH_SEPARATE TSRMLS_CC); zend_hash_move_forward_ex(ah0, &hp0); goto fes_c9ff_0; fee_c9ff_0: if(0){} } } PHALCON_ALLOC_ZVAL_MM(a0); array_init(a0); PHALCON_ALLOC_ZVAL_MM(r11); PHALCON_CALL_METHOD_PARAMS_1(r11, this_ptr, "compilepattern", pcre_pattern, PH_NO_CHECK); phalcon_array_update_string(&a0, SL("pattern"), &r11, PH_COPY | PH_SEPARATE TSRMLS_CC); phalcon_array_update_string(&a0, SL("paths"), &route_paths, PH_COPY | PH_SEPARATE TSRMLS_CC); PHALCON_ALLOC_ZVAL_MM(t2); phalcon_read_property(&t2, this_ptr, SL("_routes"), PH_NOISY_CC); phalcon_array_append(&t2, a0, 0 TSRMLS_CC); phalcon_update_property_zval(this_ptr, SL("_routes"), t2 TSRMLS_CC); PHALCON_MM_RESTORE(); }
/** * Phalcon_Config_Adapter_Ini constructor * * @param string $filePath * @return Phalcon_Config_Adapter_Ini * */ PHP_METHOD(Phalcon_Config_Adapter_Ini, __construct){ zval *file_path = NULL, *config = NULL, *ini_config = NULL, *directives = NULL; zval *section = NULL, *value = NULL, *key = NULL, *directive_parts = NULL; zval *a0 = NULL; zval *c0 = NULL, *c1 = NULL, *c2 = NULL; zval *i0 = NULL; zval *r0 = NULL, *r1 = NULL, *r2 = NULL, *r3 = NULL, *r4 = NULL, *r5 = NULL; zval *t0 = NULL, *t1 = NULL; HashTable *ah0, *ah1; HashPosition hp0, hp1; 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, "z", &file_path) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } PHALCON_INIT_VAR(a0); array_init(a0); PHALCON_CPY_WRT(config, a0); PHALCON_INIT_VAR(c0); ZVAL_BOOL(c0, 1); PHALCON_INIT_VAR(ini_config); PHALCON_CALL_FUNC_PARAMS_2(ini_config, "parse_ini_file", file_path, c0); if (Z_TYPE_P(ini_config) == IS_BOOL && !Z_BVAL_P(ini_config)) { PHALCON_ALLOC_ZVAL_MM(i0); object_init_ex(i0, phalcon_config_exception_ce); PHALCON_ALLOC_ZVAL_MM(r0); PHALCON_ALLOC_ZVAL_MM(r1); PHALCON_CALL_FUNC_PARAMS_1(r1, "basename", file_path); PHALCON_CONCAT_SVS(r0, "Configuration file ", r1, " can't be loaded"); PHALCON_CALL_METHOD_PARAMS_1_NORETURN(i0, "__construct", r0, PHALCON_CHECK); phalcon_throw_exception(i0 TSRMLS_CC); return; } if (phalcon_valid_foreach(ini_config TSRMLS_CC)) { ah0 = Z_ARRVAL_P(ini_config); zend_hash_internal_pointer_reset_ex(ah0, &hp0); fes_b840_0: if(zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) != SUCCESS){ goto fee_b840_0; } else { PHALCON_INIT_VAR(section); PHALCON_GET_FOREACH_KEY(section, ah0, hp0); } PHALCON_INIT_VAR(directives); ZVAL_ZVAL(directives, *hd, 1, 0); if (phalcon_valid_foreach(directives TSRMLS_CC)) { ah1 = Z_ARRVAL_P(directives); zend_hash_internal_pointer_reset_ex(ah1, &hp1); fes_b840_1: if(zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) != SUCCESS){ goto fee_b840_1; } else { PHALCON_INIT_VAR(key); PHALCON_GET_FOREACH_KEY(key, ah1, hp1); } PHALCON_INIT_VAR(value); ZVAL_ZVAL(value, *hd, 1, 0); PHALCON_INIT_VAR(c1); ZVAL_STRING(c1, ".", 1); PHALCON_INIT_VAR(r2); phalcon_fast_strpos(r2, key, c1 TSRMLS_CC); if (Z_TYPE_P(r2) != IS_BOOL || (Z_TYPE_P(r2) == IS_BOOL && Z_BVAL_P(r2))) { PHALCON_INIT_VAR(c2); ZVAL_STRING(c2, ".", 1); PHALCON_INIT_VAR(r3); phalcon_fast_explode(r3, c2, key TSRMLS_CC); PHALCON_CPY_WRT(directive_parts, r3); if (Z_TYPE_P(config) == IS_ARRAY) { PHALCON_INIT_VAR(t0); phalcon_array_fetch(&t0, config, section, PHALCON_SILENT TSRMLS_CC); } if (Z_REFCOUNT_P(t0) > 1) { phalcon_array_update(&config, section, &t0, PHALCON_NO_SEPARATE_THX, PHALCON_COPY, PHALCON_CTOR TSRMLS_CC); } if (Z_TYPE_P(t0) != IS_ARRAY) { convert_to_array(t0); phalcon_array_update(&config, section, &t0, PHALCON_NO_SEPARATE_THX, PHALCON_COPY, PHALCON_NO_CTOR TSRMLS_CC); } PHALCON_INIT_VAR(r4); phalcon_array_fetch_long(&r4, directive_parts, 0, PHALCON_NOISY TSRMLS_CC); if (Z_TYPE_P(t0) == IS_ARRAY) { PHALCON_INIT_VAR(t1); phalcon_array_fetch(&t1, t0, r4, PHALCON_SILENT TSRMLS_CC); } if (Z_REFCOUNT_P(t1) > 1) { phalcon_array_update(&t0, r4, &t1, PHALCON_NO_SEPARATE_THX, PHALCON_COPY, PHALCON_CTOR TSRMLS_CC); } if (Z_TYPE_P(t1) != IS_ARRAY) { convert_to_array(t1); phalcon_array_update(&t0, r4, &t1, PHALCON_NO_SEPARATE_THX, PHALCON_COPY, PHALCON_NO_CTOR TSRMLS_CC); } PHALCON_INIT_VAR(r5); phalcon_array_fetch_long(&r5, directive_parts, 1, PHALCON_NOISY TSRMLS_CC); phalcon_array_update(&t1, r5, &value, PHALCON_NO_SEPARATE_THX, PHALCON_COPY, PHALCON_NO_CTOR TSRMLS_CC); } else { phalcon_array_update_multi_2(&config, section, key, &value, PHALCON_NO_SEPARATE_THX TSRMLS_CC); } zend_hash_move_forward_ex(ah1, &hp1); goto fes_b840_1; fee_b840_1: if(0){} } else { return; } zend_hash_move_forward_ex(ah0, &hp0); goto fes_b840_0; fee_b840_0: if(0){} } else { return; } PHALCON_CALL_PARENT_PARAMS_1_NORETURN(this_ptr, "Phalcon_Config_Adapter_Ini", "__construct", config); PHALCON_MM_RESTORE(); }