/** * Checks whether request has been made using SOAP * * @return boolean */ PHP_METHOD(Phalcon_Http_Request, isSoapRequested){ zval *server = NULL, *position = NULL, *have_content_type = NULL; zval *g0 = NULL; zval *r0 = NULL; zval *t0 = NULL; int eval_int; PHALCON_MM_GROW(); phalcon_get_global(&g0, SL("_SERVER")+1 TSRMLS_CC); PHALCON_CPY_WRT(server, g0); eval_int = phalcon_array_isset_string(server, SL("HTTP_SOAPACTION")+1); if (eval_int) { PHALCON_MM_RESTORE(); RETURN_TRUE; } else { eval_int = phalcon_array_isset_string(server, SL("CONTENT_TYPE")+1); if (eval_int) { PHALCON_ALLOC_ZVAL_MM(r0); phalcon_array_fetch_string(&r0, server, SL("CONTENT_TYPE"), PH_NOISY_CC); PHALCON_INIT_VAR(position); phalcon_fast_strpos_str(position, r0, SL("application/soap+xml") TSRMLS_CC); PHALCON_INIT_VAR(t0); ZVAL_BOOL(t0, 0); PHALCON_INIT_VAR(have_content_type); is_not_identical_function(have_content_type, t0, position TSRMLS_CC); RETURN_NCTOR(have_content_type); } } PHALCON_MM_RESTORE(); RETURN_FALSE; }
/** * 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(); }
/** * Returns an array of Phalcon\Db\Column objects describing a table * * <code>print_r($connection->describeColumns("posts")); ?></code> * * @param string $table * @param string $schema * @return Phalcon\Db\Column[] */ PHP_METHOD(Phalcon_Db_Adapter_Pdo_Postgresql, describeColumns) { zval *table = NULL, *schema = NULL, *columns = NULL, *sql = NULL, *fetch_assoc = NULL; zval *describe = NULL, *old_column = NULL, *field = NULL, *definition = NULL; zval *char_size = NULL, *numeric_size = NULL, *column_type = NULL; zval *status = NULL, *attribute = NULL, *column_name = NULL, *column = NULL; zval *t0 = NULL; HashTable *ah0; HashPosition hp0; zval **hd; 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(columns); array_init(columns); PHALCON_ALLOC_ZVAL_MM(t0); phalcon_read_property(&t0, this_ptr, SL("_dialect"), PH_NOISY_CC); PHALCON_INIT_VAR(sql); PHALCON_CALL_METHOD_PARAMS_2(sql, t0, "describecolumns", table, schema, PH_NO_CHECK); PHALCON_INIT_VAR(fetch_assoc); phalcon_get_class_constant(fetch_assoc, phalcon_db_ce, SL("FETCH_ASSOC") TSRMLS_CC); PHALCON_INIT_VAR(describe); PHALCON_CALL_METHOD_PARAMS_2(describe, this_ptr, "fetchall", sql, fetch_assoc, PH_NO_CHECK); PHALCON_INIT_VAR(old_column); ZVAL_NULL(old_column); 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(field); PHALCON_INIT_VAR(definition); array_init(definition); PHALCON_INIT_VAR(char_size); phalcon_array_fetch_string(&char_size, field, SL("size"), PH_NOISY_CC); PHALCON_INIT_VAR(numeric_size); phalcon_array_fetch_string(&numeric_size, field, SL("numericsize"), PH_NOISY_CC); PHALCON_INIT_VAR(column_type); phalcon_array_fetch_string(&column_type, field, SL("type"), PH_NOISY_CC); PHALCON_INIT_VAR(status); phalcon_fast_strpos_str(status, column_type, SL("int") TSRMLS_CC); if (PHALCON_IS_NOT_FALSE(status)) { phalcon_array_update_string_long(&definition, SL("type"), 0, PH_SEPARATE TSRMLS_CC); phalcon_array_update_string_bool(&definition, SL("isNumeric"), 1, PH_SEPARATE TSRMLS_CC); phalcon_array_update_string(&definition, SL("size"), &numeric_size, PH_COPY | PH_SEPARATE TSRMLS_CC); } else { PHALCON_INIT_VAR(status); phalcon_fast_strpos_str(status, column_type, SL("varying") TSRMLS_CC); if (PHALCON_IS_NOT_FALSE(status)) { phalcon_array_update_string_long(&definition, SL("type"), 2, PH_SEPARATE TSRMLS_CC); phalcon_array_update_string(&definition, SL("size"), &char_size, PH_COPY | PH_SEPARATE TSRMLS_CC); } else { PHALCON_INIT_VAR(status); phalcon_fast_strpos_str(status, column_type, SL("date") TSRMLS_CC); if (PHALCON_IS_NOT_FALSE(status)) { phalcon_array_update_string_long(&definition, SL("type"), 1, PH_SEPARATE TSRMLS_CC); phalcon_array_update_string_long(&definition, SL("size"), 0, PH_SEPARATE TSRMLS_CC); } else { PHALCON_INIT_VAR(status); phalcon_fast_strpos_str(status, column_type, SL("numeric") TSRMLS_CC); if (PHALCON_IS_NOT_FALSE(status)) { phalcon_array_update_string_long(&definition, SL("type"), 3, PH_SEPARATE TSRMLS_CC); phalcon_array_update_string_bool(&definition, SL("isNumeric"), 1, PH_SEPARATE TSRMLS_CC); phalcon_array_update_string(&definition, SL("size"), &numeric_size, PH_COPY | PH_SEPARATE TSRMLS_CC); } else { PHALCON_INIT_VAR(status); phalcon_fast_strpos_str(status, column_type, SL("char") TSRMLS_CC); if (PHALCON_IS_NOT_FALSE(status)) { phalcon_array_update_string_long(&definition, SL("type"), 5, PH_SEPARATE TSRMLS_CC); phalcon_array_update_string(&definition, SL("size"), &char_size, PH_COPY | PH_SEPARATE TSRMLS_CC); } else { PHALCON_INIT_VAR(status); phalcon_fast_strpos_str(status, column_type, SL("timestamp") TSRMLS_CC); if (PHALCON_IS_NOT_FALSE(status)) { phalcon_array_update_string_long(&definition, SL("type"), 4, PH_SEPARATE TSRMLS_CC); phalcon_array_update_string_long(&definition, SL("size"), 0, PH_SEPARATE TSRMLS_CC); } else { PHALCON_INIT_VAR(status); phalcon_fast_strpos_str(status, column_type, SL("text") TSRMLS_CC); if (PHALCON_IS_NOT_FALSE(status)) { phalcon_array_update_string_long(&definition, SL("type"), 6, PH_SEPARATE TSRMLS_CC); phalcon_array_update_string(&definition, SL("size"), &char_size, PH_COPY | PH_SEPARATE TSRMLS_CC); } else { PHALCON_INIT_VAR(status); phalcon_fast_strpos_str(status, column_type, SL("float") TSRMLS_CC); if (PHALCON_IS_NOT_FALSE(status)) { phalcon_array_update_string_long(&definition, SL("type"), 7, PH_SEPARATE TSRMLS_CC); phalcon_array_update_string_bool(&definition, SL("isNumeric"), 1, PH_SEPARATE TSRMLS_CC); phalcon_array_update_string(&definition, SL("size"), &numeric_size, PH_COPY | PH_SEPARATE TSRMLS_CC); } else { PHALCON_INIT_VAR(status); phalcon_fast_strpos_str(status, column_type, SL("uuid") TSRMLS_CC); if (PHALCON_IS_NOT_FALSE(status)) { phalcon_array_update_string_long(&definition, SL("type"), 5, PH_SEPARATE TSRMLS_CC); phalcon_array_update_string_long(&definition, SL("size"), 36, PH_SEPARATE TSRMLS_CC); } else { phalcon_array_update_string_long(&definition, SL("type"), 5, PH_SEPARATE TSRMLS_CC); phalcon_array_update_string(&definition, SL("size"), &char_size, PH_COPY | PH_SEPARATE TSRMLS_CC); } } } } } } } } } PHALCON_INIT_VAR(status); phalcon_fast_strpos_str(status, column_type, SL("unsigned") TSRMLS_CC); if (PHALCON_IS_NOT_FALSE(status)) { phalcon_array_update_string_bool(&definition, SL("unsigned"), 1, PH_SEPARATE TSRMLS_CC); } if (Z_TYPE_P(old_column) == IS_NULL) { phalcon_array_update_string_bool(&definition, SL("first"), 1, PH_SEPARATE TSRMLS_CC); } else { phalcon_array_update_string(&definition, SL("after"), &old_column, PH_COPY | PH_SEPARATE TSRMLS_CC); } PHALCON_INIT_VAR(attribute); phalcon_array_fetch_string(&attribute, field, SL("key"), PH_NOISY_CC); if (PHALCON_COMPARE_STRING(attribute, "PRI")) { phalcon_array_update_string_bool(&definition, SL("primary"), 1, PH_SEPARATE TSRMLS_CC); } PHALCON_INIT_VAR(attribute); phalcon_array_fetch_string(&attribute, field, SL("null"), PH_NOISY_CC); if (PHALCON_COMPARE_STRING(attribute, "NO")) { phalcon_array_update_string_bool(&definition, SL("notNull"), 1, PH_SEPARATE TSRMLS_CC); } PHALCON_INIT_VAR(attribute); phalcon_array_fetch_string(&attribute, field, SL("extra"), PH_NOISY_CC); if (PHALCON_COMPARE_STRING(attribute, "auto_increment")) { phalcon_array_update_string_bool(&definition, SL("autoIncrement"), 1, PH_SEPARATE TSRMLS_CC); } PHALCON_INIT_VAR(column_name); phalcon_array_fetch_string(&column_name, field, SL("field"), PH_NOISY_CC); PHALCON_INIT_VAR(column); object_init_ex(column, phalcon_db_column_ce); PHALCON_CALL_METHOD_PARAMS_2_NORETURN(column, "__construct", column_name, definition, PH_CHECK); phalcon_array_append(&columns, column, PH_SEPARATE TSRMLS_CC); PHALCON_CPY_WRT(old_column, column_name); zend_hash_move_forward_ex(ah0, &hp0); goto ph_cycle_start_0; ph_cycle_end_0: RETURN_CTOR(columns); }
/** * 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); }
/** * 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(); }
/** * 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(); }
/** * Returns an array of Phalcon\Db\Column objects describing a table * * @param string $table * @param string $schema * @return Phalcon\Db\Column[] */ PHP_METHOD(Phalcon_Db_Adapter_Pdo_Mysql, describeColumns){ zval *table = NULL, *schema = NULL, *columns = NULL, *dialect = NULL, *sql = NULL, *describe = NULL; zval *old_column = NULL, *field = NULL, *definition = NULL, *column_type = NULL; zval *pos = NULL, *matches = NULL, *match_one = NULL, *attribute = NULL, *column_name = NULL; zval *column = NULL; zval *t0 = NULL; zval *c0 = NULL; HashTable *ah0; HashPosition hp0; zval **hd; 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(columns); array_init(columns); PHALCON_INIT_VAR(dialect); phalcon_read_property(&dialect, this_ptr, SL("_dialect"), PH_NOISY_CC); PHALCON_INIT_VAR(sql); PHALCON_CALL_METHOD_PARAMS_2(sql, dialect, "describecolumns", table, schema, PH_NO_CHECK); PHALCON_ALLOC_ZVAL_MM(t0); phalcon_get_class_constant(t0, phalcon_db_ce, SL("FETCH_ASSOC") TSRMLS_CC); PHALCON_INIT_VAR(describe); PHALCON_CALL_METHOD_PARAMS_2(describe, this_ptr, "fetchall", sql, t0, PH_NO_CHECK); PHALCON_INIT_VAR(old_column); ZVAL_NULL(old_column); if (!phalcon_valid_foreach(describe TSRMLS_CC)) { return; } ah0 = Z_ARRVAL_P(describe); zend_hash_internal_pointer_reset_ex(ah0, &hp0); fes_ecef_0: if(zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) != SUCCESS){ goto fee_ecef_0; } PHALCON_INIT_VAR(field); ZVAL_ZVAL(field, *hd, 1, 0); PHALCON_INIT_VAR(definition); array_init(definition); PHALCON_INIT_VAR(column_type); phalcon_array_fetch_string(&column_type, field, SL("type"), PH_NOISY_CC); PHALCON_INIT_VAR(pos); phalcon_fast_strpos_str(pos, column_type, SL("int") TSRMLS_CC); if (Z_TYPE_P(pos) != IS_BOOL || (Z_TYPE_P(pos) == IS_BOOL && Z_BVAL_P(pos))) { phalcon_array_update_string_long(&definition, SL("type"), 0, PH_SEPARATE TSRMLS_CC); phalcon_array_update_string_bool(&definition, SL("isNumeric"), 1, PH_SEPARATE TSRMLS_CC); } else { PHALCON_INIT_VAR(pos); phalcon_fast_strpos_str(pos, column_type, SL("varchar") TSRMLS_CC); if (Z_TYPE_P(pos) != IS_BOOL || (Z_TYPE_P(pos) == IS_BOOL && Z_BVAL_P(pos))) { phalcon_array_update_string_long(&definition, SL("type"), 2, PH_SEPARATE TSRMLS_CC); } else { PHALCON_INIT_VAR(pos); phalcon_fast_strpos_str(pos, column_type, SL("date") TSRMLS_CC); if (Z_TYPE_P(pos) != IS_BOOL || (Z_TYPE_P(pos) == IS_BOOL && Z_BVAL_P(pos))) { phalcon_array_update_string_long(&definition, SL("type"), 1, PH_SEPARATE TSRMLS_CC); } else { PHALCON_INIT_VAR(pos); phalcon_fast_strpos_str(pos, column_type, SL("decimal") TSRMLS_CC); if (Z_TYPE_P(pos) != IS_BOOL || (Z_TYPE_P(pos) == IS_BOOL && Z_BVAL_P(pos))) { phalcon_array_update_string_long(&definition, SL("type"), 3, PH_SEPARATE TSRMLS_CC); phalcon_array_update_string_bool(&definition, SL("isNumeric"), 1, PH_SEPARATE TSRMLS_CC); } else { PHALCON_INIT_VAR(pos); phalcon_fast_strpos_str(pos, column_type, SL("char") TSRMLS_CC); if (Z_TYPE_P(pos) != IS_BOOL || (Z_TYPE_P(pos) == IS_BOOL && Z_BVAL_P(pos))) { phalcon_array_update_string_long(&definition, SL("type"), 5, PH_SEPARATE TSRMLS_CC); } else { PHALCON_INIT_VAR(pos); phalcon_fast_strpos_str(pos, column_type, SL("datetime") TSRMLS_CC); if (Z_TYPE_P(pos) != IS_BOOL || (Z_TYPE_P(pos) == IS_BOOL && Z_BVAL_P(pos))) { phalcon_array_update_string_long(&definition, SL("type"), 4, PH_SEPARATE TSRMLS_CC); } else { PHALCON_INIT_VAR(pos); phalcon_fast_strpos_str(pos, column_type, SL("text") TSRMLS_CC); if (Z_TYPE_P(pos) != IS_BOOL || (Z_TYPE_P(pos) == IS_BOOL && Z_BVAL_P(pos))) { phalcon_array_update_string_long(&definition, SL("type"), 6, PH_SEPARATE TSRMLS_CC); } else { PHALCON_INIT_VAR(pos); phalcon_fast_strpos_str(pos, column_type, SL("float") TSRMLS_CC); if (Z_TYPE_P(pos) != IS_BOOL || (Z_TYPE_P(pos) == IS_BOOL && Z_BVAL_P(pos))) { phalcon_array_update_string_long(&definition, SL("type"), 7, PH_SEPARATE TSRMLS_CC); phalcon_array_update_string_bool(&definition, SL("isNumeric"), 1, PH_SEPARATE TSRMLS_CC); } else { PHALCON_INIT_VAR(pos); phalcon_fast_strpos_str(pos, column_type, SL("enum") TSRMLS_CC); if (Z_TYPE_P(pos) != IS_BOOL || (Z_TYPE_P(pos) == IS_BOOL && Z_BVAL_P(pos))) { phalcon_array_update_string_long(&definition, SL("type"), 5, PH_SEPARATE TSRMLS_CC); } else { phalcon_array_update_string_long(&definition, SL("type"), 2, PH_SEPARATE TSRMLS_CC); } } } } } } } } } PHALCON_INIT_VAR(pos); phalcon_fast_strpos_str(pos, column_type, SL("(") TSRMLS_CC); if (Z_TYPE_P(pos) != IS_BOOL || (Z_TYPE_P(pos) == IS_BOOL && Z_BVAL_P(pos))) { PHALCON_INIT_VAR(matches); array_init(matches); PHALCON_INIT_VAR(c0); ZVAL_STRING(c0, "#\\(([0-9]+)(,[0-9]+)*\\)#", 1); Z_SET_ISREF_P(matches); PHALCON_INIT_VAR(pos); PHALCON_CALL_FUNC_PARAMS_3(pos, "preg_match", c0, column_type, matches); Z_UNSET_ISREF_P(matches); if (zend_is_true(pos)) { eval_int = phalcon_array_isset_long(matches, 1); if (eval_int) { PHALCON_INIT_VAR(match_one); phalcon_array_fetch_long(&match_one, matches, 1, PH_NOISY_CC); phalcon_array_update_string(&definition, SL("size"), &match_one, PH_COPY | PH_SEPARATE TSRMLS_CC); } } } PHALCON_INIT_VAR(pos); phalcon_fast_strpos_str(pos, column_type, SL("unsigned") TSRMLS_CC); if (Z_TYPE_P(pos) != IS_BOOL || (Z_TYPE_P(pos) == IS_BOOL && Z_BVAL_P(pos))) { phalcon_array_update_string_bool(&definition, SL("unsigned"), 1, PH_SEPARATE TSRMLS_CC); } if (!zend_is_true(old_column)) { phalcon_array_update_string_bool(&definition, SL("first"), 1, PH_SEPARATE TSRMLS_CC); } else { phalcon_array_update_string(&definition, SL("after"), &old_column, PH_COPY | PH_SEPARATE TSRMLS_CC); } PHALCON_INIT_VAR(attribute); phalcon_array_fetch_string(&attribute, field, SL("key"), PH_NOISY_CC); if (PHALCON_COMPARE_STRING(attribute, "PRI")) { phalcon_array_update_string_bool(&definition, SL("primary"), 1, PH_SEPARATE TSRMLS_CC); } PHALCON_INIT_VAR(attribute); phalcon_array_fetch_string(&attribute, field, SL("null"), PH_NOISY_CC); if (PHALCON_COMPARE_STRING(attribute, "NO")) { phalcon_array_update_string_bool(&definition, SL("notNull"), 1, PH_SEPARATE TSRMLS_CC); } PHALCON_INIT_VAR(attribute); phalcon_array_fetch_string(&attribute, field, SL("extra"), PH_NOISY_CC); if (PHALCON_COMPARE_STRING(attribute, "auto_increment")) { phalcon_array_update_string_bool(&definition, SL("autoIncrement"), 1, PH_SEPARATE TSRMLS_CC); } PHALCON_INIT_VAR(column_name); phalcon_array_fetch_string(&column_name, field, SL("field"), PH_NOISY_CC); PHALCON_INIT_VAR(column); object_init_ex(column, phalcon_db_column_ce); PHALCON_CALL_METHOD_PARAMS_2_NORETURN(column, "__construct", column_name, definition, PH_CHECK); phalcon_array_append(&columns, column, PH_SEPARATE TSRMLS_CC); PHALCON_CPY_WRT(old_column, column_name); zend_hash_move_forward_ex(ah0, &hp0); goto fes_ecef_0; fee_ecef_0: RETURN_CTOR(columns); }
/** * Returns an array of Phalcon\Db\Column objects describing a table * * <code>print_r($connection->describeColumns("posts")); ?></code> * * @param string $table * @param string $schema * @return Phalcon\Db\Column[] */ PHP_METHOD(Phalcon_Db_Adapter_Pdo_Sqlite, describeColumns){ zval *table = NULL, *schema = NULL, *columns = NULL, *sql = NULL, *fetch_assoc = NULL; zval *describe = NULL, *old_column = NULL, *field = NULL, *definition = NULL; zval *column_type = NULL; zval *status = NULL, *matches = NULL, *pattern = NULL, *attribute = NULL, *column_name = NULL; zval *column = NULL, *dialect = NULL; zval *r0 = NULL, *r1 = NULL; zval *status2 = NULL; HashTable *ah0; HashPosition hp0; zval **hd; 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(columns); array_init(columns); PHALCON_ALLOC_ZVAL_MM(dialect); phalcon_read_property(&dialect, this_ptr, SL("_dialect"), PH_NOISY_CC); PHALCON_INIT_VAR(sql); PHALCON_CALL_METHOD_PARAMS_2(sql, dialect, "describecolumns", table, schema, PH_NO_CHECK); PHALCON_INIT_VAR(fetch_assoc); phalcon_get_class_constant(fetch_assoc, phalcon_db_ce, SL("FETCH_ASSOC") TSRMLS_CC); PHALCON_INIT_VAR(describe); PHALCON_CALL_METHOD_PARAMS_2(describe, this_ptr, "fetchall", sql, fetch_assoc, PH_NO_CHECK); PHALCON_INIT_VAR(old_column); ZVAL_NULL(old_column); 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(field); PHALCON_INIT_VAR(definition); array_init(definition); add_assoc_long_ex(definition, SS("bindType"), 2); PHALCON_INIT_VAR(column_type); phalcon_array_fetch_string(&column_type, field, SL("type"), PH_NOISY_CC); PHALCON_INIT_VAR(status); phalcon_fast_strpos_str(status, column_type, SL("int") TSRMLS_CC); if (PHALCON_IS_NOT_FALSE(status)) { add_assoc_long_ex(definition, SS("type"), 0); add_assoc_bool_ex(definition, SS("isNumeric"), 1); add_assoc_long_ex(definition, SS("size"), 32); // default 4byte add_assoc_long_ex(definition, SS("bindType"), 1); } else { PHALCON_INIT_VAR(status); phalcon_fast_strpos_str(status, column_type, SL("varchar") TSRMLS_CC); if (PHALCON_IS_NOT_FALSE(status)) { phalcon_array_update_string_long(&definition, SL("type"), 2, PH_SEPARATE TSRMLS_CC); phalcon_array_update_string_long(&definition, SL("size"), 255, PH_SEPARATE TSRMLS_CC); } else { PHALCON_INIT_VAR(status); phalcon_fast_strpos_str(status, column_type, SL("date") TSRMLS_CC); if (PHALCON_IS_NOT_FALSE(status)) { phalcon_array_update_string_long(&definition, SL("type"), 1, PH_SEPARATE TSRMLS_CC); phalcon_array_update_string_long(&definition, SL("size"), 0, PH_SEPARATE TSRMLS_CC); } else { PHALCON_INIT_VAR(status); PHALCON_INIT_VAR(status2); phalcon_fast_strpos_str(status, column_type, SL("numeric") TSRMLS_CC); phalcon_fast_strpos_str(status2, column_type, SL("decimal") TSRMLS_CC); if ( (PHALCON_IS_NOT_FALSE(status)) || (PHALCON_IS_NOT_FALSE(status2)) ) { add_assoc_long_ex(definition, SS("type"), 3); add_assoc_bool_ex(definition, SS("isNumeric"), 1); add_assoc_long_ex(definition, SS("size"), 32); // default 4byte add_assoc_long_ex(definition, SS("bindType"), 32); } else { PHALCON_INIT_VAR(status); phalcon_fast_strpos_str(status, column_type, SL("char") TSRMLS_CC); if (PHALCON_IS_NOT_FALSE(status)) { add_assoc_long_ex(definition, SS("type"), 5); phalcon_array_update_string_long(&definition, SL("size"), 255, PH_SEPARATE TSRMLS_CC); } else { PHALCON_INIT_VAR(status); phalcon_fast_strpos_str(status, column_type, SL("timestamp") TSRMLS_CC); if (PHALCON_IS_NOT_FALSE(status)) { add_assoc_long_ex(definition, SS("type"), 4); phalcon_array_update_string_long(&definition, SL("size"), 0, PH_SEPARATE TSRMLS_CC); } else { PHALCON_INIT_VAR(status); phalcon_fast_strpos_str(status, column_type, SL("text") TSRMLS_CC); if (PHALCON_IS_NOT_FALSE(status)) { add_assoc_long_ex(definition, SS("type"), 6); phalcon_array_update_string_long(&definition, SL("size"), 2147483647, PH_SEPARATE TSRMLS_CC); } else { PHALCON_INIT_VAR(status); phalcon_fast_strpos_str(status, column_type, SL("float") TSRMLS_CC); if (PHALCON_IS_NOT_FALSE(status)) { add_assoc_long_ex(definition, SS("type"), 7); add_assoc_bool_ex(definition, SS("isNumeric"), 1); add_assoc_long_ex(definition, SS("size"), 64); // default 4byte add_assoc_long_ex(definition, SS("bindType"), 32); } else { add_assoc_long_ex(definition, SS("type"), 5); PHALCON_INIT_VAR(status); phalcon_fast_strpos_str(status, column_type, SL("uuid") TSRMLS_CC); if (PHALCON_IS_NOT_FALSE(status)) { phalcon_array_update_string_long(&definition, SL("size"), 36, PH_SEPARATE TSRMLS_CC); } else { phalcon_array_update_string_long(&definition, SL("size"), 255, PH_SEPARATE TSRMLS_CC); } } } } } } } } } PHALCON_INIT_VAR(status); phalcon_fast_strpos_str(status, column_type, SL("(") TSRMLS_CC); if (PHALCON_IS_NOT_FALSE(status)) { PHALCON_INIT_VAR(matches); array_init(matches); PHALCON_INIT_VAR(pattern); ZVAL_STRING(pattern, "#\\(([0-9]+)(,[0-9]+)*\\)#", 1); Z_SET_ISREF_P(matches); PHALCON_INIT_VAR(r0); PHALCON_CALL_FUNC_PARAMS_3(r0, "preg_match", pattern, column_type, matches); Z_UNSET_ISREF_P(matches); if (zend_is_true(r0)) { eval_int = phalcon_array_isset_long(matches, 1); if (eval_int) { PHALCON_INIT_VAR(r1); phalcon_array_fetch_long(&r1, matches, 1, PH_NOISY_CC); phalcon_array_update_string(&definition, SL("size"), &r1, PH_COPY | PH_SEPARATE TSRMLS_CC); } } } PHALCON_INIT_VAR(status); phalcon_fast_strpos_str(status, column_type, SL("unsigned") TSRMLS_CC); if (PHALCON_IS_NOT_FALSE(status)) { phalcon_array_update_string_bool(&definition, SL("unsigned"), 1, PH_SEPARATE TSRMLS_CC); } if (Z_TYPE_P(old_column) == IS_NULL) { phalcon_array_update_string_bool(&definition, SL("first"), 1, PH_SEPARATE TSRMLS_CC); } else { phalcon_array_update_string(&definition, SL("after"), &old_column, PH_COPY | PH_SEPARATE TSRMLS_CC); } PHALCON_INIT_VAR(attribute); phalcon_array_fetch_string(&attribute, field, SL("pk"), PH_NOISY_CC); if (PHALCON_COMPARE_STRING(attribute, "1")) { phalcon_array_update_string_bool(&definition, SL("primary"), 1, PH_SEPARATE TSRMLS_CC); }else { phalcon_array_update_string_bool(&definition, SL("primary"), 0, PH_SEPARATE TSRMLS_CC); } PHALCON_INIT_VAR(attribute); phalcon_array_fetch_string(&attribute, field, SL("notnull"), PH_NOISY_CC); if (PHALCON_COMPARE_STRING(attribute, "1")) { phalcon_array_update_string_bool(&definition, SL("notNull"), 1, PH_SEPARATE TSRMLS_CC); } PHALCON_INIT_VAR(r0); phalcon_fast_strpos_str(r0, column_type, SL("integer") TSRMLS_CC); PHALCON_INIT_VAR(r1); phalcon_array_fetch_string(&r1, definition, SL("primary"), PH_NOISY_CC); if ((PHALCON_IS_NOT_FALSE(r0)) && (PHALCON_IS_NOT_FALSE(r1))) { phalcon_array_update_string_bool(&definition, SL("autoIncrement"), 1, PH_SEPARATE TSRMLS_CC); } PHALCON_INIT_VAR(column_name); phalcon_array_fetch_string(&column_name, field, SL("name"), PH_NOISY_CC); PHALCON_INIT_VAR(column); object_init_ex(column, phalcon_db_column_ce); PHALCON_CALL_METHOD_PARAMS_2_NORETURN(column, "__construct", column_name, definition, PH_CHECK); phalcon_array_append(&columns, column, PH_SEPARATE TSRMLS_CC); PHALCON_CPY_WRT(old_column, column_name); zend_hash_move_forward_ex(ah0, &hp0); goto ph_cycle_start_0; ph_cycle_end_0: RETURN_CTOR(columns);}