/** * Handles routing information received from command-line arguments * * @param array $arguments */ PHP_METHOD(Phalcon_CLI_Router, handle){ zval *arguments = NULL, *module_name = NULL, *task_name = NULL, *action_name = NULL; PHALCON_MM_GROW(); phalcon_fetch_params(1, 0, 1, &arguments); if (!arguments) { PHALCON_INIT_VAR(arguments); array_init(arguments); } else { PHALCON_SEPARATE_PARAM(arguments); } if (Z_TYPE_P(arguments) != IS_ARRAY) { PHALCON_THROW_EXCEPTION_STR(phalcon_cli_router_exception_ce, "Arguments must be an Array"); return; } PHALCON_INIT_VAR(module_name); PHALCON_INIT_VAR(task_name); PHALCON_INIT_VAR(action_name); /** * Check for a module */ if (phalcon_array_isset_string(arguments, SS("module"))) { PHALCON_OBS_NVAR(module_name); phalcon_array_fetch_string(&module_name, arguments, SL("module"), PH_NOISY); phalcon_array_unset_string(&arguments, SS("module"), PH_SEPARATE); } /** * Check for a task */ if (phalcon_array_isset_string(arguments, SS("task"))) { PHALCON_OBS_NVAR(task_name); phalcon_array_fetch_string(&task_name, arguments, SL("task"), PH_NOISY); phalcon_array_unset_string(&arguments, SS("task"), PH_SEPARATE); } /** * Check for an action */ if (phalcon_array_isset_string(arguments, SS("action"))) { PHALCON_OBS_NVAR(action_name); phalcon_array_fetch_string(&action_name, arguments, SL("action"), PH_NOISY); phalcon_array_unset_string(&arguments, SS("action"), PH_SEPARATE); } phalcon_update_property_this(this_ptr, SL("_module"), module_name TSRMLS_CC); phalcon_update_property_this(this_ptr, SL("_task"), task_name TSRMLS_CC); phalcon_update_property_this(this_ptr, SL("_action"), action_name TSRMLS_CC); phalcon_update_property_this(this_ptr, SL("_params"), arguments TSRMLS_CC); PHALCON_MM_RESTORE(); }
/** * This method is automatically called in Phalcon\Db\Adapter\Pdo constructor. * Call it when you need to restore a database connection. * * Support set search_path after connectted if schema is specified in config. * * @param array $descriptor * @return boolean */ PHP_METHOD(Phalcon_Db_Adapter_Pdo_Postgresql, connect){ zval *descriptor = NULL, *schema = NULL, *sql, *password; PHALCON_MM_GROW(); phalcon_fetch_params(1, 0, 1, &descriptor); if (!descriptor) { PHALCON_INIT_VAR(descriptor); } else { PHALCON_SEPARATE_PARAM(descriptor); } if (!zend_is_true(descriptor)) { PHALCON_OBS_NVAR(descriptor); phalcon_read_property_this(&descriptor, this_ptr, SL("_descriptor"), PH_NOISY TSRMLS_CC); } if (phalcon_array_isset_string(descriptor, SS("schema"))) { PHALCON_OBS_VAR(schema); phalcon_array_fetch_string(&schema, descriptor, SL("schema"), PH_NOISY); phalcon_array_unset_string(&descriptor, SS("schema"), PH_COPY); phalcon_update_property_this(this_ptr, SL("_schema"), schema TSRMLS_CC); } else { PHALCON_INIT_VAR(schema); } if (phalcon_array_isset_string_fetch(&password, descriptor, SS("password"))) { /* There is a bug in pdo_pgsql driver when the password is empty, * the driver tries to access invalid memory: * * if (dbh->password[0] != '\'' && dbh->password[strlen(dbh->password) - 1] != '\'') * * To avoid this we set the password to null */ if (Z_TYPE_P(password) == IS_STRING && Z_STRLEN_P(password) == 0) { phalcon_array_update_string(&descriptor, SL("password"), PHALCON_GLOBAL(z_null), PH_COPY); } } PHALCON_CALL_PARENT(NULL, phalcon_db_adapter_pdo_postgresql_ce, this_ptr, "connect", descriptor); /** * Execute the search path in the after connect */ if (Z_TYPE_P(schema) == IS_STRING) { PHALCON_INIT_VAR(sql); PHALCON_CONCAT_SVS(sql, "SET search_path TO '", schema, "'"); PHALCON_CALL_METHOD(NULL, this_ptr, "execute", sql); } PHALCON_MM_RESTORE(); }
/** * This method is automatically called in Phalcon\Db\Adapter\Pdo constructor. * Call it when you need to restore a database connection. * * Support set search_path after connectted if schema is specified in config. * * @param array $descriptor * @return boolean */ PHP_METHOD(Phalcon_Db_Adapter_Pdo_Postgresql, connect) { zval *descriptor = NULL, *schema = NULL, *sql = NULL; int eval_int; 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 (!zend_is_true(descriptor)) { PHALCON_INIT_VAR(descriptor); phalcon_read_property(&descriptor, this_ptr, SL("_descriptor"), PH_NOISY_CC); } PHALCON_INIT_VAR(schema); ZVAL_NULL(schema); eval_int = phalcon_array_isset_string(descriptor, SS("schema")); if (eval_int) { PHALCON_INIT_VAR(schema); phalcon_array_fetch_string(&schema, descriptor, SL("schema"), PH_NOISY_CC); PHALCON_SEPARATE_PARAM(descriptor); phalcon_array_unset_string(descriptor, SS("schema")); } PHALCON_CALL_PARENT_PARAMS_1_NORETURN(this_ptr, "Phalcon\\Db\\Adapter\\Pdo\\Postgresql", "connect", descriptor); if (Z_TYPE_P(schema) == IS_STRING) { PHALCON_INIT_VAR(sql); PHALCON_CONCAT_SVS(sql, "SET search_path TO '", schema, "'"); PHALCON_CALL_METHOD_PARAMS_1_NORETURN(this_ptr, "execute", sql, PH_NO_CHECK); } PHALCON_MM_RESTORE(); }
/** * This method is automatically called in Phalcon\Db\Adapter\Pdo constructor. * Call it when you need to restore a database connection. * * Support set search_path after connectted if schema is specified in config. * * @param array $descriptor * @return boolean */ PHP_METHOD(Phalcon_Db_Adapter_Pdo_Postgresql, connect){ zval *descriptor = NULL, *schema = NULL, *sql; PHALCON_MM_GROW(); phalcon_fetch_params(1, 0, 1, &descriptor); if (!descriptor) { PHALCON_INIT_VAR(descriptor); } else { PHALCON_SEPARATE_PARAM(descriptor); } if (!zend_is_true(descriptor)) { PHALCON_OBS_NVAR(descriptor); phalcon_read_property_this(&descriptor, this_ptr, SL("_descriptor"), PH_NOISY_CC); } PHALCON_INIT_VAR(schema); if (phalcon_array_isset_string(descriptor, SS("schema"))) { PHALCON_OBS_NVAR(schema); phalcon_array_fetch_string(&schema, descriptor, SL("schema"), PH_NOISY); phalcon_array_unset_string(&descriptor, SS("schema"), PH_SEPARATE); } PHALCON_CALL_PARENT_PARAMS_1_NORETURN(this_ptr, "Phalcon\\Db\\Adapter\\Pdo\\Postgresql", "connect", descriptor); /** * Execute the search path in the after connect */ if (Z_TYPE_P(schema) == IS_STRING) { PHALCON_INIT_VAR(sql); PHALCON_CONCAT_SVS(sql, "SET search_path TO '", schema, "'"); phalcon_call_method_p1_noret(this_ptr, "execute", sql); } PHALCON_MM_RESTORE(); }
/** * Generates a SELECT tag * * @param array $parameters * @param array $data */ PHP_METHOD(Phalcon_Tag_Select, selectField){ zval *parameters, *data = NULL, *params = NULL, *eol, *id = NULL, *name, *value = NULL; zval *use_empty = NULL, *empty_value = NULL, *empty_text = NULL, *code; zval *avalue = NULL, *key = NULL, *close_option, *options = NULL, *using; zval *resultset_options, *array_options; HashTable *ah0; HashPosition hp0; zval **hd; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|z", ¶meters, &data) == FAILURE) { RETURN_MM_NULL(); } if (!data) { PHALCON_INIT_VAR(data); } if (Z_TYPE_P(parameters) != IS_ARRAY) { PHALCON_INIT_VAR(params); array_init_size(params, 2); phalcon_array_append(¶ms, parameters, PH_SEPARATE TSRMLS_CC); phalcon_array_append(¶ms, data, PH_SEPARATE TSRMLS_CC); } else { PHALCON_CPY_WRT(params, parameters); } PHALCON_INIT_VAR(eol); zend_get_constant(SL("PHP_EOL"), eol TSRMLS_CC); if (!phalcon_array_isset_long(params, 0)) { PHALCON_OBS_VAR(id); phalcon_array_fetch_string(&id, params, SL("id"), PH_NOISY_CC); phalcon_array_update_long(¶ms, 0, &id, PH_COPY | PH_SEPARATE TSRMLS_CC); } PHALCON_OBS_NVAR(id); phalcon_array_fetch_long(&id, params, 0, PH_NOISY_CC); if (!phalcon_array_isset_string(params, SS("name"))) { phalcon_array_update_string(¶ms, SL("name"), &id, PH_COPY | PH_SEPARATE TSRMLS_CC); } else { PHALCON_OBS_VAR(name); phalcon_array_fetch_string(&name, params, SL("name"), PH_NOISY_CC); if (!zend_is_true(name)) { phalcon_array_update_string(¶ms, SL("name"), &id, PH_COPY | PH_SEPARATE TSRMLS_CC); } } if (!phalcon_array_isset_string(params, SS("id"))) { phalcon_array_update_string(¶ms, SL("id"), &id, PH_COPY | PH_SEPARATE TSRMLS_CC); } if (!phalcon_array_isset_string(params, SS("value"))) { PHALCON_INIT_VAR(value); PHALCON_CALL_STATIC_PARAMS_2(value, "phalcon\\tag", "getvalue", id, params); } else { PHALCON_OBS_NVAR(value); phalcon_array_fetch_string(&value, params, SL("value"), PH_NOISY_CC); PHALCON_SEPARATE(params); phalcon_array_unset_string(params, SS("value")); } PHALCON_INIT_VAR(use_empty); ZVAL_BOOL(use_empty, 0); if (phalcon_array_isset_string(params, SS("useEmpty"))) { if (!phalcon_array_isset_string(params, SS("emptyValue"))) { PHALCON_INIT_VAR(empty_value); ZVAL_STRING(empty_value, "", 1); } else { PHALCON_OBS_NVAR(empty_value); phalcon_array_fetch_string(&empty_value, params, SL("emptyValue"), PH_NOISY_CC); PHALCON_SEPARATE(params); phalcon_array_unset_string(params, SS("emptyValue")); } if (!phalcon_array_isset_string(params, SS("emptyText"))) { PHALCON_INIT_VAR(empty_text); ZVAL_STRING(empty_text, "Choose...", 1); } else { PHALCON_OBS_NVAR(empty_text); phalcon_array_fetch_string(&empty_text, params, SL("emptyText"), PH_NOISY_CC); PHALCON_SEPARATE(params); phalcon_array_unset_string(params, SS("emptyText")); } PHALCON_OBS_NVAR(use_empty); phalcon_array_fetch_string(&use_empty, params, SL("useEmpty"), PH_NOISY_CC); PHALCON_SEPARATE(params); phalcon_array_unset_string(params, SS("useEmpty")); } PHALCON_INIT_VAR(code); ZVAL_STRING(code, "<select", 1); if (Z_TYPE_P(params) == IS_ARRAY) { if (!phalcon_is_iterable(params, &ah0, &hp0, 0, 0 TSRMLS_CC)) { return; } while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { PHALCON_GET_FOREACH_KEY(key, ah0, hp0); PHALCON_GET_FOREACH_VALUE(avalue); if (Z_TYPE_P(key) != IS_LONG) { if (Z_TYPE_P(avalue) != IS_ARRAY) { PHALCON_SCONCAT_SVSVS(code, " ", key, "=\"", avalue, "\""); } } zend_hash_move_forward_ex(ah0, &hp0); } } PHALCON_SCONCAT_SV(code, ">", eol); PHALCON_INIT_VAR(close_option); PHALCON_CONCAT_SV(close_option, "</option>", eol); if (zend_is_true(use_empty)) { /** * Create an empty value */ PHALCON_SCONCAT_SVSVV(code, "\t<option value=\"", empty_value, "\">", empty_text, close_option); PHALCON_SEPARATE(params); phalcon_array_unset_string(params, SS("useEmpty")); } if (phalcon_array_isset_long(params, 1)) { PHALCON_OBS_VAR(options); phalcon_array_fetch_long(&options, params, 1, PH_NOISY_CC); } else { PHALCON_CPY_WRT(options, data); } if (Z_TYPE_P(options) == IS_OBJECT) { /** * The options is a resultset */ if (!phalcon_array_isset_string(params, SS("using"))) { PHALCON_THROW_EXCEPTION_STR(phalcon_tag_exception_ce, "The 'using' parameter is required"); return; } else { PHALCON_OBS_VAR(using); phalcon_array_fetch_string(&using, params, SL("using"), PH_NOISY_CC); if (Z_TYPE_P(using) != IS_ARRAY) { PHALCON_THROW_EXCEPTION_STR(phalcon_tag_exception_ce, "The 'using' parameter should be an Array"); return; } } /** * Create the SELECT's option from a resultset */ PHALCON_INIT_VAR(resultset_options); PHALCON_CALL_SELF_PARAMS_4(resultset_options, this_ptr, "_optionsfromresultset", options, using, value, close_option); phalcon_concat_self(&code, resultset_options TSRMLS_CC); } else { if (Z_TYPE_P(options) == IS_ARRAY) {
/** * This method is automatically called in Phalcon\Db\Adapter\Pdo constructor. * Call it when you need to restore a database connection * *<code> * //Make a connection * $connection = new Phalcon\Db\Adapter\Pdo\Mysql(array( * 'host' => '192.168.0.11', * 'username' => 'sigma', * 'password' => 'secret', * 'dbname' => 'blog', * )); * * //Reconnect * $connection->connect(); * </code> * * @param array $descriptor * @return boolean */ PHP_METHOD(Phalcon_Db_Adapter_Pdo, connect){ zval *descriptor = NULL, *username = NULL, *password = NULL, *dsn_parts; zval *value = NULL, *key = NULL, *dsn_attribute = NULL, *dsn_attributes = NULL; zval *pdo_type, *dsn, *options = NULL, *persistent, *pdo; zend_class_entry *ce; HashTable *ah0; HashPosition hp0; zval **hd; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|z", &descriptor) == FAILURE) { RETURN_MM_NULL(); } if (!descriptor) { PHALCON_INIT_VAR(descriptor); } else { PHALCON_SEPARATE_PARAM(descriptor); } if (Z_TYPE_P(descriptor) == IS_NULL) { PHALCON_OBS_NVAR(descriptor); phalcon_read_property(&descriptor, this_ptr, SL("_descriptor"), PH_NOISY TSRMLS_CC); } /** * Check for a username or use null as default */ if (phalcon_array_isset_string(descriptor, SS("username"))) { PHALCON_OBS_VAR(username); phalcon_array_fetch_string(&username, descriptor, SL("username"), PH_NOISY); phalcon_array_unset_string(&descriptor, SS("username"), PH_COPY); } else { PHALCON_INIT_NVAR(username); } /** * Check for a password or use null as default */ if (phalcon_array_isset_string(descriptor, SS("password"))) { PHALCON_OBS_VAR(password); phalcon_array_fetch_string(&password, descriptor, SL("password"), PH_NOISY); phalcon_array_unset_string(&descriptor, SS("password"), PH_COPY); } else { PHALCON_INIT_NVAR(password); } /** * Check if the developer has defined custom options or create one from scratch */ if (phalcon_array_isset_string(descriptor, SS("options"))) { PHALCON_OBS_VAR(options); phalcon_array_fetch_string(&options, descriptor, SL("options"), PH_NOISY); phalcon_array_unset_string(&descriptor, SS("options"), PH_COPY); } else { PHALCON_INIT_NVAR(options); array_init(options); } /** * Remove the dialectClass from the descriptor if any */ if (phalcon_array_isset_string(descriptor, SS("dialectClass"))) { phalcon_array_unset_string(&descriptor, SS("dialectClass"), PH_COPY); } /** * Check if the user has defined a custom dsn */ if (!phalcon_array_isset_string(descriptor, SS("dsn"))) { PHALCON_INIT_VAR(dsn_parts); array_init(dsn_parts); phalcon_is_iterable(descriptor, &ah0, &hp0, 0, 0); while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { PHALCON_GET_HKEY(key, ah0, hp0); PHALCON_GET_HVALUE(value); PHALCON_INIT_NVAR(dsn_attribute); PHALCON_CONCAT_VSV(dsn_attribute, key, "=", value); phalcon_array_append(&dsn_parts, dsn_attribute, PH_COPY); zend_hash_move_forward_ex(ah0, &hp0); } PHALCON_INIT_VAR(dsn_attributes); phalcon_fast_join_str(dsn_attributes, SL(";"), dsn_parts TSRMLS_CC); } else { PHALCON_OBS_NVAR(dsn_attributes); phalcon_array_fetch_string(&dsn_attributes, descriptor, SL("dsn"), PH_NOISY); } PHALCON_OBS_VAR(pdo_type); phalcon_read_property(&pdo_type, this_ptr, SL("_type"), PH_NOISY TSRMLS_CC); PHALCON_INIT_VAR(dsn); PHALCON_CONCAT_VSV(dsn, pdo_type, ":", dsn_attributes); /** * Default options */ phalcon_array_update_long_long(&options, PDO_ATTR_ERRMODE, PDO_ERRMODE_EXCEPTION, PH_COPY); /* phalcon_array_update_long_long(&options, PDO_ATTR_CASE, PDO_CASE_LOWER, PH_COPY); phalcon_array_update_long_long(&options, PDO_ATTR_CURSOR, PDO_CURSOR_SCROLL, PH_COPY); */ /** * Check if the connection must be persistent */ if (phalcon_array_isset_string(descriptor, SS("persistent"))) { PHALCON_OBS_VAR(persistent); phalcon_array_fetch_string(&persistent, descriptor, SL("persistent"), PH_NOISY); if (zend_is_true(persistent)) { phalcon_array_update_long_bool(&options, PDO_ATTR_PERSISTENT, 1, PH_COPY); } } /** * Create the connection using PDO */ ce = zend_fetch_class(SL("PDO"), ZEND_FETCH_CLASS_AUTO TSRMLS_CC); PHALCON_INIT_VAR(pdo); object_init_ex(pdo, ce); PHALCON_CALL_METHOD(NULL, pdo, "__construct", dsn, username, password, options); phalcon_update_property_zval(this_ptr, SL("_pdo"), pdo TSRMLS_CC); 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 *match_method = NULL, *pattern = NULL, *paths = NULL, *position = NULL; zval *part = NULL, *match_position = NULL, *module = NULL, *default_module = NULL; zval *controller = NULL, *default_controller = NULL, *action = NULL; zval *default_action = NULL, *params_str = NULL, *str_params = NULL; zval *params_merge = NULL, *default_params = NULL; zval *c0 = NULL, *c1 = NULL, *c2 = 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); array_init(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); fes_c9ff_0: if(zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) != SUCCESS){ goto fee_c9ff_0; } PHALCON_INIT_VAR(route); ZVAL_ZVAL(route, *hd, 1, 0); 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(c0); ZVAL_STRING(c0, "request", 1); PHALCON_INIT_VAR(request); PHALCON_CALL_METHOD_PARAMS_1(request, dependency_injector, "getshared", c0, PH_NO_CHECK); } PHALCON_INIT_VAR(match_method); PHALCON_CALL_METHOD_PARAMS_1(match_method, request, "ismethod", methods, PH_NO_CHECK); if (!zend_is_true(match_method)) { zend_hash_move_forward_ex(ah0, &hp0); goto fes_c9ff_0; } } PHALCON_INIT_VAR(pattern); PHALCON_CALL_METHOD(pattern, route, "getcompiledpattern", PH_NO_CHECK); 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); 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 (!phalcon_valid_foreach(paths TSRMLS_CC)) { return; } ah1 = Z_ARRVAL_P(paths); zend_hash_internal_pointer_reset_ex(ah1, &hp1); fes_c9ff_1: if(zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) != SUCCESS){ goto fee_c9ff_1; } PHALCON_INIT_VAR(part); PHALCON_GET_FOREACH_KEY(part, ah1, hp1); PHALCON_INIT_VAR(position); ZVAL_ZVAL(position, *hd, 1, 0); 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 fes_c9ff_1; fee_c9ff_1: phalcon_update_property_zval(this_ptr, SL("_matches"), matches TSRMLS_CC); phalcon_update_property_zval(this_ptr, SL("_matchedRoute"), route TSRMLS_CC); goto fee_c9ff_0; } zend_hash_move_forward_ex(ah0, &hp0); goto fes_c9ff_0; fee_c9ff_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(c1); ZVAL_LONG(c1, 1); PHALCON_INIT_VAR(str_params); PHALCON_CALL_FUNC_PARAMS_2(str_params, "substr", params_str, c1); if (zend_is_true(str_params)) { PHALCON_INIT_VAR(c2); ZVAL_STRING(c2, "/", 1); PHALCON_INIT_VAR(params); phalcon_fast_explode(params, c2, 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(); }
/** * 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();}
/** * Builds a HTML A tag using framework conventions * *<code> * echo Phalcon\Tag::linkTo('signup/register', 'Register Here!'); * echo Phalcon\Tag::linkTo(array('signup/register', 'Register Here!')); * echo Phalcon\Tag::linkTo(array('signup/register', 'Register Here!', 'class' => 'btn-primary')); *</code> * * @param array|string $parameters * @param string $text * @return string */ PHP_METHOD(Phalcon_Tag, linkTo){ zval *parameters, *text = NULL, *params = NULL, *action = NULL, *url, *internal_url; zval *code, *value = NULL, *key = NULL; HashTable *ah0; HashPosition hp0; zval **hd; PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 1, ¶meters, &text); if (!text) { PHALCON_INIT_VAR(text); } else { PHALCON_SEPARATE_PARAM(text); } if (Z_TYPE_P(parameters) != IS_ARRAY) { PHALCON_INIT_VAR(params); array_init_size(params, 2); phalcon_array_append(¶ms, parameters, PH_SEPARATE TSRMLS_CC); phalcon_array_append(¶ms, text, PH_SEPARATE TSRMLS_CC); } else { PHALCON_CPY_WRT(params, parameters); } PHALCON_INIT_VAR(action); ZVAL_STRING(action, "", 1); if (phalcon_array_isset_long(params, 0)) { PHALCON_OBS_NVAR(action); phalcon_array_fetch_long(&action, params, 0, PH_NOISY_CC); } else { if (phalcon_array_isset_string(params, SS("action"))) { PHALCON_OBS_NVAR(action); phalcon_array_fetch_string(&action, params, SL("action"), PH_NOISY_CC); phalcon_array_unset_string(¶ms, SS("action"), PH_SEPARATE); } } PHALCON_INIT_NVAR(text); ZVAL_STRING(text, "", 1); if (phalcon_array_isset_long(params, 1)) { PHALCON_OBS_NVAR(text); phalcon_array_fetch_long(&text, params, 1, PH_NOISY_CC); } else { if (phalcon_array_isset_string(params, SS("text"))) { PHALCON_OBS_NVAR(text); phalcon_array_fetch_string(&text, params, SL("text"), PH_NOISY_CC); phalcon_array_unset_string(¶ms, SS("text"), PH_SEPARATE); } } PHALCON_INIT_VAR(url); PHALCON_CALL_SELF(url, this_ptr, "geturlservice"); PHALCON_INIT_VAR(internal_url); PHALCON_CALL_METHOD_PARAMS_1(internal_url, url, "get", action); PHALCON_INIT_VAR(code); PHALCON_CONCAT_SVS(code, "<a href=\"", internal_url, "\""); if (!phalcon_is_iterable(params, &ah0, &hp0, 0, 0 TSRMLS_CC)) { return; } while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { PHALCON_GET_FOREACH_KEY(key, ah0, hp0); PHALCON_GET_FOREACH_VALUE(value); if (Z_TYPE_P(key) != IS_LONG) { PHALCON_SCONCAT_SVSVS(code, " ", key, "=\"", value, "\""); } zend_hash_move_forward_ex(ah0, &hp0); } PHALCON_SCONCAT_SVS(code, ">", text, "</a>"); RETURN_CTOR(code); }
/** * Builds a LINK[rel="stylesheet"] tag * * <code> * echo Phalcon\Tag::stylesheetLink("http://fonts.googleapis.com/css?family=Rosario", false); * echo Phalcon\Tag::stylesheetLink("css/style.css"); * </code> * * Volt Syntax: *<code> * {{ stylesheet_link("http://fonts.googleapis.com/css?family=Rosario", false) }} * {{ stylesheet_link("css/style.css") }} *</code> * * @param array $parameters * @param boolean $local * @return string */ PHP_METHOD(Phalcon_Tag, stylesheetLink){ zval *parameters = NULL, *local = NULL, *params = NULL, *first_param; zval *url, *url_href, *href, *code, *value = NULL, *key = NULL, *five; zval *doctype, *eol, *is_xhtml; HashTable *ah0; HashPosition hp0; zval **hd; PHALCON_MM_GROW(); phalcon_fetch_params(1, 0, 2, ¶meters, &local); if (!parameters) { PHALCON_INIT_VAR(parameters); } if (!local) { PHALCON_INIT_VAR(local); ZVAL_BOOL(local, 1); } else { PHALCON_SEPARATE_PARAM(local); } if (Z_TYPE_P(parameters) != IS_ARRAY) { PHALCON_INIT_VAR(params); array_init_size(params, 2); phalcon_array_append(¶ms, parameters, PH_SEPARATE TSRMLS_CC); phalcon_array_append(¶ms, local, PH_SEPARATE TSRMLS_CC); } else { PHALCON_CPY_WRT(params, parameters); } if (!phalcon_array_isset_string(params, SS("href"))) { if (phalcon_array_isset_long(params, 0)) { PHALCON_OBS_VAR(first_param); phalcon_array_fetch_long(&first_param, params, 0, PH_NOISY_CC); phalcon_array_update_string(¶ms, SL("href"), &first_param, PH_COPY | PH_SEPARATE TSRMLS_CC); } else { phalcon_array_update_string_string(¶ms, SL("href"), SL(""), PH_SEPARATE TSRMLS_CC); } } PHALCON_INIT_NVAR(local); ZVAL_STRING(local, "", 1); if (phalcon_array_isset_long(params, 1)) { PHALCON_OBS_NVAR(local); phalcon_array_fetch_long(&local, params, 1, PH_NOISY_CC); } else { if (phalcon_array_isset_string(params, SS("local"))) { PHALCON_OBS_NVAR(local); phalcon_array_fetch_string(&local, params, SL("local"), PH_NOISY_CC); phalcon_array_unset_string(¶ms, SS("local"), PH_SEPARATE); } } if (!phalcon_array_isset_string(params, SS("type"))) { phalcon_array_update_string_string(¶ms, SL("type"), SL("text/css"), PH_SEPARATE TSRMLS_CC); } if (zend_is_true(local)) { PHALCON_INIT_VAR(url); PHALCON_CALL_SELF(url, this_ptr, "geturlservice"); PHALCON_OBS_VAR(url_href); phalcon_array_fetch_string(&url_href, params, SL("href"), PH_NOISY_CC); PHALCON_INIT_VAR(href); PHALCON_CALL_METHOD_PARAMS_1(href, url, "get", url_href); phalcon_array_update_string(¶ms, SL("href"), &href, PH_COPY | PH_SEPARATE TSRMLS_CC); } PHALCON_INIT_VAR(code); ZVAL_STRING(code, "<link rel=\"stylesheet\"", 1); if (!phalcon_is_iterable(params, &ah0, &hp0, 0, 0 TSRMLS_CC)) { return; } while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { PHALCON_GET_FOREACH_KEY(key, ah0, hp0); PHALCON_GET_FOREACH_VALUE(value); if (Z_TYPE_P(key) != IS_LONG) { PHALCON_SCONCAT_SVSVS(code, " ", key, "=\"", value, "\""); } zend_hash_move_forward_ex(ah0, &hp0); } PHALCON_INIT_VAR(five); ZVAL_LONG(five, 5); PHALCON_OBS_VAR(doctype); phalcon_read_static_property(&doctype, SL("phalcon\\tag"), SL("_documentType") TSRMLS_CC); PHALCON_INIT_VAR(eol); ZVAL_STRING(eol, PHP_EOL, 1); /** * Check if Doctype is XHTML */ PHALCON_INIT_VAR(is_xhtml); is_smaller_function(is_xhtml, five, doctype TSRMLS_CC); if (zend_is_true(is_xhtml)) { PHALCON_SCONCAT_SV(code, " />", eol); } else { PHALCON_SCONCAT_SV(code, ">", eol); } RETURN_CTOR(code); }
PHP_METHOD(Phalcon_Tag_Select, select){ zval *parameters = NULL, *data = NULL, *params = NULL, *eol = NULL, *id = NULL, *value = NULL, *dummy_value = NULL; zval *dummy_text = NULL, *code = NULL, *avalue = NULL, *key = NULL, *close_option = NULL; zval *options = NULL, *using = NULL; zval *a0 = 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, *r10 = NULL, *r11 = NULL, *r12 = NULL, *r13 = NULL; zval *p1[] = { 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, "z|z", ¶meters, &data) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } if (!data) { PHALCON_INIT_VAR(data); ZVAL_NULL(data); } if (Z_TYPE_P(parameters) != IS_ARRAY) { PHALCON_INIT_VAR(a0); array_init(a0); phalcon_array_append(&a0, parameters, PHALCON_SEPARATE_PLZ TSRMLS_CC); phalcon_array_append(&a0, data, PHALCON_SEPARATE_PLZ TSRMLS_CC); PHALCON_CPY_WRT(params, a0); } else { PHALCON_CPY_WRT(params, parameters); } PHALCON_ALLOC_ZVAL_MM(t0); zend_get_constant("PHP_EOL", strlen("PHP_EOL"), t0 TSRMLS_CC); PHALCON_CPY_WRT(eol, t0); PHALCON_ALLOC_ZVAL_MM(r0); phalcon_array_fetch_long(&r0, params, 0, PHALCON_NOISY TSRMLS_CC); PHALCON_CPY_WRT(id, r0); eval_int = phalcon_array_isset_string(params, "value", strlen("value")+1); if (!eval_int) { PHALCON_ALLOC_ZVAL_MM(r1); PHALCON_CALL_STATIC_PARAMS_1(r1, "phalcon_tag", "getvalue", id); PHALCON_CPY_WRT(value, r1); } else { PHALCON_ALLOC_ZVAL_MM(r2); phalcon_array_fetch_string(&r2, params, "value", strlen("value"), PHALCON_NOISY TSRMLS_CC); PHALCON_CPY_WRT(value, r2); PHALCON_SEPARATE(params); phalcon_array_unset_string(params, "value", strlen("value")+1); } eval_int = phalcon_array_isset_string(params, "dummyValue", strlen("dummyValue")+1); if (!eval_int) { PHALCON_INIT_VAR(dummy_value); ZVAL_STRING(dummy_value, "", 1); } else { PHALCON_ALLOC_ZVAL_MM(r3); phalcon_array_fetch_string(&r3, params, "dummyValue", strlen("dummyValue"), PHALCON_NOISY TSRMLS_CC); PHALCON_CPY_WRT(dummy_value, r3); PHALCON_SEPARATE(params); phalcon_array_unset_string(params, "dummyValue", strlen("dummyValue")+1); } eval_int = phalcon_array_isset_string(params, "dummyText", strlen("dummyText")+1); if (!eval_int) { PHALCON_INIT_VAR(dummy_text); ZVAL_STRING(dummy_text, "Choose...", 1); } else { PHALCON_ALLOC_ZVAL_MM(r4); phalcon_array_fetch_string(&r4, params, "dummyText", strlen("dummyText"), PHALCON_NOISY TSRMLS_CC); PHALCON_CPY_WRT(dummy_text, r4); PHALCON_SEPARATE(params); phalcon_array_unset_string(params, "dummyText", strlen("dummyText")+1); } PHALCON_ALLOC_ZVAL_MM(r5); PHALCON_CONCAT_SVSVS(r5, "<select id=\"", id, "\" name=\"", id, "\""); PHALCON_CPY_WRT(code, r5); if (Z_TYPE_P(params) == IS_ARRAY) { if (phalcon_valid_foreach(params TSRMLS_CC)) { ah0 = Z_ARRVAL_P(params); zend_hash_internal_pointer_reset_ex(ah0, &hp0); fes_9c31_0: if(zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) != SUCCESS){ goto fee_9c31_0; } else { PHALCON_INIT_VAR(key); PHALCON_GET_FOREACH_KEY(key, ah0, hp0); } PHALCON_INIT_VAR(avalue); ZVAL_ZVAL(avalue, *hd, 1, 0); if (Z_TYPE_P(key) != IS_LONG) { if (Z_TYPE_P(avalue) != IS_ARRAY) { PHALCON_INIT_VAR(r6); PHALCON_CONCAT_SVSVS(r6, " ", key, "=\"", avalue, "\""); phalcon_concat_self(&code, r6 TSRMLS_CC); } } zend_hash_move_forward_ex(ah0, &hp0); goto fes_9c31_0; fee_9c31_0: if(0){} } else { return; } } PHALCON_ALLOC_ZVAL_MM(r7); PHALCON_CONCAT_SV(r7, ">", eol); phalcon_concat_self(&code, r7 TSRMLS_CC); PHALCON_ALLOC_ZVAL_MM(r8); PHALCON_CONCAT_SV(r8, "</option>", eol); PHALCON_CPY_WRT(close_option, r8); eval_int = phalcon_array_isset_string(params, "useDummy", strlen("useDummy")+1); if (eval_int) { PHALCON_ALLOC_ZVAL_MM(r9); PHALCON_CONCAT_SVSVV(r9, "\t<option value=\"", dummy_value, "\">", dummy_text, close_option); phalcon_concat_self(&code, r9 TSRMLS_CC); } eval_int = phalcon_array_isset_long(params, 1); if (eval_int) { PHALCON_ALLOC_ZVAL_MM(r10); phalcon_array_fetch_long(&r10, params, 1, PHALCON_NOISY TSRMLS_CC); PHALCON_CPY_WRT(options, r10); } else { PHALCON_CPY_WRT(options, data); } if (Z_TYPE_P(options) == IS_OBJECT) { eval_int = phalcon_array_isset_string(params, "using", strlen("using")+1); if (!eval_int) { PHALCON_THROW_EXCEPTION_STR(phalcon_tag_exception_ce, "The 'using' parameter is required"); return; } else { PHALCON_ALLOC_ZVAL_MM(r11); phalcon_array_fetch_string(&r11, params, "using", strlen("using"), PHALCON_NOISY TSRMLS_CC); PHALCON_CPY_WRT(using, r11); if (Z_TYPE_P(using) != IS_ARRAY) { PHALCON_THROW_EXCEPTION_STR(phalcon_tag_exception_ce, "The 'using' parameter should be an Array"); return; } } PHALCON_ALLOC_ZVAL_MM(r12); p1[0] = options; p1[1] = using; p1[2] = value; p1[3] = close_option; PHALCON_CALL_SELF_PARAMS(r12, this_ptr, "_optionsfromresultset", 4, p1); phalcon_concat_self(&code, r12 TSRMLS_CC); } else {
/** * Builds a HTML input[type="submit"] tag * * <code>echo Phalcon\Tag::submitButton("Save")</code> * * @param array $params * @return string */ PHP_METHOD(Phalcon_Tag, submitButton){ zval *parameters = NULL, *params = NULL, *value = NULL, *code = NULL, *avalue = NULL; zval *key = NULL, *attribute = NULL; zval *t0 = NULL; HashTable *ah0; HashPosition hp0; zval **hd; char *hash_index; uint hash_index_len; ulong hash_num; int hash_type; int eval_int; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", ¶meters) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } if (Z_TYPE_P(parameters) != IS_ARRAY) { PHALCON_INIT_VAR(params); array_init(params); phalcon_array_append(¶ms, parameters, PH_SEPARATE TSRMLS_CC); } else { PHALCON_CPY_WRT(params, parameters); } eval_int = phalcon_array_isset_string(params, SL("value")+1); if (eval_int) { PHALCON_INIT_VAR(value); phalcon_array_fetch_string(&value, params, SL("value"), PH_NOISY_CC); PHALCON_SEPARATE(params); phalcon_array_unset_string(params, SL("value")+1); } else { eval_int = phalcon_array_isset_long(params, 0); if (eval_int) { PHALCON_INIT_VAR(value); phalcon_array_fetch_long(&value, params, 0, PH_NOISY_CC); } else { PHALCON_INIT_VAR(value); ZVAL_STRING(value, "", 1); } } PHALCON_INIT_VAR(code); PHALCON_CONCAT_SVS(code, "<input type=\"submit\" value=\"", value, "\" "); if (!phalcon_valid_foreach(params TSRMLS_CC)) { return; } ah0 = Z_ARRVAL_P(params); zend_hash_internal_pointer_reset_ex(ah0, &hp0); fes_9b93_3: if(zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) != SUCCESS){ goto fee_9b93_3; } PHALCON_INIT_VAR(key); PHALCON_GET_FOREACH_KEY(key, ah0, hp0); PHALCON_INIT_VAR(avalue); ZVAL_ZVAL(avalue, *hd, 1, 0); if (Z_TYPE_P(key) != IS_LONG) { PHALCON_INIT_VAR(attribute); PHALCON_CONCAT_VSVS(attribute, key, "=\"", avalue, "\" "); phalcon_concat_self(&code, attribute TSRMLS_CC); } zend_hash_move_forward_ex(ah0, &hp0); goto fes_9b93_3; fee_9b93_3: PHALCON_INIT_VAR(t0); ZVAL_STRING(t0, " />", 1); phalcon_concat_self(&code, t0 TSRMLS_CC); RETURN_CTOR(code); }
/** * Builds a LINK[rel="stylesheet"] tag * * <code> * echo Phalcon\Tag::stylesheetLink("http://fonts.googleapis.com/css?family=Rosario", false); * echo Phalcon\Tag::stylesheetLink("css/style.css"); * </code> * * @param array $parameters * @param boolean $local * @return string */ PHP_METHOD(Phalcon_Tag, stylesheetLink){ zval *parameters = NULL, *local = NULL, *params = NULL, *first_param = NULL; zval *url = NULL, *href = NULL, *code = NULL, *value = NULL, *key = NULL, *attribute = NULL; zval *r0 = NULL; zval *t0 = NULL; HashTable *ah0; HashPosition hp0; zval **hd; char *hash_index; uint hash_index_len; ulong hash_num; int hash_type; int eval_int; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|zz", ¶meters, &local) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } if (!parameters) { PHALCON_ALLOC_ZVAL_MM(parameters); ZVAL_NULL(parameters); } if (!local) { PHALCON_ALLOC_ZVAL_MM(local); ZVAL_BOOL(local, 1); } else { PHALCON_SEPARATE_PARAM(local); } if (Z_TYPE_P(parameters) != IS_ARRAY) { PHALCON_INIT_VAR(params); array_init(params); phalcon_array_append(¶ms, parameters, PH_SEPARATE TSRMLS_CC); phalcon_array_append(¶ms, local, PH_SEPARATE TSRMLS_CC); } else { PHALCON_CPY_WRT(params, parameters); } eval_int = phalcon_array_isset_string(params, SL("href")+1); if (!eval_int) { eval_int = phalcon_array_isset_long(params, 0); if (eval_int) { PHALCON_INIT_VAR(first_param); phalcon_array_fetch_long(&first_param, params, 0, PH_NOISY_CC); phalcon_array_update_string(¶ms, SL("href"), &first_param, PH_COPY | PH_SEPARATE TSRMLS_CC); } else { phalcon_array_update_string_string(¶ms, SL("href"), SL(""), PH_SEPARATE TSRMLS_CC); } } PHALCON_INIT_VAR(local); ZVAL_STRING(local, "", 1); eval_int = phalcon_array_isset_long(params, 1); if (eval_int) { PHALCON_INIT_VAR(local); phalcon_array_fetch_long(&local, params, 1, PH_NOISY_CC); } else { eval_int = phalcon_array_isset_string(params, SL("local")+1); if (eval_int) { PHALCON_INIT_VAR(local); phalcon_array_fetch_string(&local, params, SL("local"), PH_NOISY_CC); PHALCON_SEPARATE(params); phalcon_array_unset_string(params, SL("local")+1); } } eval_int = phalcon_array_isset_string(params, SL("type")+1); if (!eval_int) { phalcon_array_update_string_string(¶ms, SL("type"), SL("text/css"), PH_SEPARATE TSRMLS_CC); } if (zend_is_true(local)) { PHALCON_INIT_VAR(url); PHALCON_CALL_SELF(url, this_ptr, "geturlservice"); PHALCON_ALLOC_ZVAL_MM(r0); phalcon_array_fetch_string(&r0, params, SL("href"), PH_NOISY_CC); PHALCON_INIT_VAR(href); PHALCON_CALL_METHOD_PARAMS_1(href, url, "get", r0, PH_NO_CHECK); phalcon_array_update_string(¶ms, SL("href"), &href, PH_COPY | PH_SEPARATE TSRMLS_CC); } PHALCON_INIT_VAR(code); ZVAL_STRING(code, "<link rel=\"stylesheet\"", 1); if (!phalcon_valid_foreach(params TSRMLS_CC)) { return; } ah0 = Z_ARRVAL_P(params); zend_hash_internal_pointer_reset_ex(ah0, &hp0); fes_9b93_6: if(zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) != SUCCESS){ goto fee_9b93_6; } PHALCON_INIT_VAR(key); PHALCON_GET_FOREACH_KEY(key, ah0, hp0); PHALCON_INIT_VAR(value); ZVAL_ZVAL(value, *hd, 1, 0); if (Z_TYPE_P(key) != IS_LONG) { PHALCON_INIT_VAR(attribute); PHALCON_CONCAT_SVSVS(attribute, " ", key, "=\"", value, "\""); phalcon_concat_self(&code, attribute TSRMLS_CC); } zend_hash_move_forward_ex(ah0, &hp0); goto fes_9b93_6; fee_9b93_6: PHALCON_INIT_VAR(t0); ZVAL_STRING(t0, "/>", 1); phalcon_concat_self(&code, t0 TSRMLS_CC); RETURN_CTOR(code); }
/** * Handles routing information received from the rewrite engine * * @param string $uri */ PHP_METHOD(Phalcon_Mvc_Router, handle){ zval *uri = NULL, *real_uri = NULL, *route_found = NULL, *parts = NULL, *params = NULL; zval *matches = NULL, *route = NULL, *position = NULL, *part = NULL, *str_params = NULL; zval *t0 = NULL, *t1 = NULL, *t2 = NULL; zval *r0 = NULL, *r1 = NULL, *r2 = NULL, *r3 = NULL, *r4 = NULL, *r5 = NULL, *r6 = NULL; zval *r7 = NULL, *r8 = NULL, *r9 = NULL; zval *c0 = NULL, *c1 = NULL; zval *a0 = 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(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); array_init(matches); phalcon_update_property_bool(this_ptr, SL("_wasMatched"), 0 TSRMLS_CC); PHALCON_ALLOC_ZVAL_MM(t0); phalcon_read_property(&t0, this_ptr, SL("_routes"), PH_NOISY_CC); PHALCON_ALLOC_ZVAL_MM(r0); PHALCON_CALL_FUNC_PARAMS_1(r0, "array_reverse", t0); if (!phalcon_valid_foreach(r0 TSRMLS_CC)) { return; } ah0 = Z_ARRVAL_P(r0); zend_hash_internal_pointer_reset_ex(ah0, &hp0); fes_c9ff_1: if(zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) != SUCCESS){ goto fee_c9ff_1; } PHALCON_INIT_VAR(route); ZVAL_ZVAL(route, *hd, 1, 0); PHALCON_INIT_VAR(parts); phalcon_array_fetch_string(&parts, route, SL("paths"), PH_NOISY_CC); PHALCON_INIT_VAR(r1); phalcon_array_fetch_string(&r1, route, SL("pattern"), PH_NOISY_CC); Z_SET_ISREF_P(matches); PHALCON_INIT_VAR(r2); PHALCON_CALL_FUNC_PARAMS_3(r2, "preg_match", r1, real_uri, matches); Z_UNSET_ISREF_P(matches); if (zend_is_true(r2)) { PHALCON_INIT_VAR(r3); phalcon_array_fetch_string(&r3, route, SL("paths"), PH_NOISY_CC); if (!phalcon_valid_foreach(r3 TSRMLS_CC)) { return; } ah1 = Z_ARRVAL_P(r3); zend_hash_internal_pointer_reset_ex(ah1, &hp1); fes_c9ff_2: if(zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) != SUCCESS){ goto fee_c9ff_2; } PHALCON_INIT_VAR(part); PHALCON_GET_FOREACH_KEY(part, ah1, hp1); PHALCON_INIT_VAR(position); ZVAL_ZVAL(position, *hd, 1, 0); eval_int = phalcon_array_isset(matches, position); if (eval_int) { PHALCON_INIT_VAR(r4); phalcon_array_fetch(&r4, matches, position, PH_NOISY_CC); phalcon_array_update_zval(&parts, part, &r4, PH_COPY | PH_SEPARATE TSRMLS_CC); } zend_hash_move_forward_ex(ah1, &hp1); goto fes_c9ff_2; fee_c9ff_2: if(0){} phalcon_update_property_zval(this_ptr, SL("_matches"), matches TSRMLS_CC); phalcon_update_property_zval(this_ptr, SL("_currentRoute"), route TSRMLS_CC); PHALCON_INIT_VAR(route_found); ZVAL_BOOL(route_found, 1); goto fee_c9ff_1; } zend_hash_move_forward_ex(ah0, &hp0); goto fes_c9ff_1; fee_c9ff_1: if(0){} if (zend_is_true(route_found)) { eval_int = phalcon_array_isset_string(parts, SL("module")+1); if (eval_int) { PHALCON_ALLOC_ZVAL_MM(r5); phalcon_array_fetch_string(&r5, parts, SL("module"), PH_NOISY_CC); phalcon_update_property_zval(this_ptr, SL("_module"), r5 TSRMLS_CC); PHALCON_SEPARATE(parts); phalcon_array_unset_string(parts, SL("module")+1); } else { PHALCON_ALLOC_ZVAL_MM(t1); phalcon_read_property(&t1, this_ptr, SL("_defaultModule"), PH_NOISY_CC); phalcon_update_property_zval(this_ptr, SL("_module"), t1 TSRMLS_CC); } eval_int = phalcon_array_isset_string(parts, SL("controller")+1); if (eval_int) { PHALCON_ALLOC_ZVAL_MM(r6); phalcon_array_fetch_string(&r6, parts, SL("controller"), PH_NOISY_CC); phalcon_update_property_zval(this_ptr, SL("_controller"), r6 TSRMLS_CC); PHALCON_SEPARATE(parts); phalcon_array_unset_string(parts, SL("controller")+1); } else { phalcon_update_property_null(this_ptr, SL("_controller") TSRMLS_CC); } eval_int = phalcon_array_isset_string(parts, SL("action")+1); if (eval_int) { PHALCON_ALLOC_ZVAL_MM(r7); phalcon_array_fetch_string(&r7, parts, SL("action"), PH_NOISY_CC); phalcon_update_property_zval(this_ptr, SL("_action"), r7 TSRMLS_CC); PHALCON_SEPARATE(parts); phalcon_array_unset_string(parts, SL("action")+1); } else { phalcon_update_property_null(this_ptr, SL("_action") TSRMLS_CC); } eval_int = phalcon_array_isset_string(parts, SL("params")+1); if (eval_int) { PHALCON_ALLOC_ZVAL_MM(r8); phalcon_array_fetch_string(&r8, parts, SL("params"), PH_NOISY_CC); PHALCON_INIT_VAR(c0); ZVAL_LONG(c0, 1); PHALCON_INIT_VAR(str_params); PHALCON_CALL_FUNC_PARAMS_2(str_params, "substr", r8, c0); if (zend_is_true(str_params)) { PHALCON_INIT_VAR(c1); ZVAL_STRING(c1, "/", 1); PHALCON_INIT_VAR(params); phalcon_fast_explode(params, c1, str_params TSRMLS_CC); } PHALCON_SEPARATE(parts); phalcon_array_unset_string(parts, SL("params")+1); } PHALCON_ALLOC_ZVAL_MM(r9); PHALCON_CALL_FUNC_PARAMS_2(r9, "array_merge", params, parts); phalcon_update_property_zval(this_ptr, SL("_params"), r9 TSRMLS_CC); phalcon_update_property_bool(this_ptr, SL("_wasMatched"), 1 TSRMLS_CC); } else { PHALCON_ALLOC_ZVAL_MM(t2); phalcon_read_property(&t2, this_ptr, SL("_defaultModule"), PH_NOISY_CC); phalcon_update_property_zval(this_ptr, SL("_module"), t2 TSRMLS_CC); phalcon_update_property_null(this_ptr, SL("_controller") TSRMLS_CC); phalcon_update_property_null(this_ptr, SL("_action") TSRMLS_CC); PHALCON_ALLOC_ZVAL_MM(a0); array_init(a0); phalcon_update_property_zval(this_ptr, SL("_params"), a0 TSRMLS_CC); phalcon_update_property_bool(this_ptr, SL("_wasMatched"), 0 TSRMLS_CC); } PHALCON_MM_RESTORE(); }
/** * Builds a SCRIPT[type="javascript"] tag * * <code> * echo Phalcon\Tag::javascriptInclude("http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js", false); * echo Phalcon\Tag::javascriptInclude("javascript/jquery.js"); * </code> * * Volt syntax: * <code> * {{ javascript_include("http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js", false) }} * {{ javascript_include("javascript/jquery.js") }} * </code> * * @param array $parameters * @param boolean $local * @return string */ PHP_METHOD(Phalcon_Tag, javascriptInclude){ zval *parameters = NULL, *local = NULL, *params = NULL, *first_param; zval *url, *params_src, *src, *code, *value = NULL, *key = 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", ¶meters, &local) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } if (!parameters) { PHALCON_INIT_NVAR(parameters); } if (!local) { PHALCON_INIT_NVAR(local); ZVAL_BOOL(local, 1); } else { PHALCON_SEPARATE_PARAM(local); } if (Z_TYPE_P(parameters) != IS_ARRAY) { PHALCON_INIT_VAR(params); array_init(params); phalcon_array_append(¶ms, parameters, PH_SEPARATE TSRMLS_CC); phalcon_array_append(¶ms, local, PH_SEPARATE TSRMLS_CC); } else { PHALCON_CPY_WRT(params, parameters); } eval_int = phalcon_array_isset_string(params, SS("src")); if (!eval_int) { eval_int = phalcon_array_isset_long(params, 0); if (eval_int) { PHALCON_INIT_VAR(first_param); phalcon_array_fetch_long(&first_param, params, 0, PH_NOISY_CC); phalcon_array_update_string(¶ms, SL("src"), &first_param, PH_COPY | PH_SEPARATE TSRMLS_CC); } else { phalcon_array_update_string_string(¶ms, SL("src"), SL(""), PH_SEPARATE TSRMLS_CC); } } PHALCON_INIT_NVAR(local); ZVAL_STRING(local, "", 1); eval_int = phalcon_array_isset_long(params, 1); if (eval_int) { PHALCON_INIT_NVAR(local); phalcon_array_fetch_long(&local, params, 1, PH_NOISY_CC); } else { eval_int = phalcon_array_isset_string(params, SS("local")); if (eval_int) { PHALCON_INIT_NVAR(local); phalcon_array_fetch_string(&local, params, SL("local"), PH_NOISY_CC); PHALCON_SEPARATE(params); phalcon_array_unset_string(params, SS("local")); } } eval_int = phalcon_array_isset_string(params, SS("type")); if (!eval_int) { phalcon_array_update_string_string(¶ms, SL("type"), SL("text/javascript"), PH_SEPARATE TSRMLS_CC); } if (zend_is_true(local)) { PHALCON_INIT_VAR(url); PHALCON_CALL_SELF(url, this_ptr, "geturlservice"); PHALCON_INIT_VAR(params_src); phalcon_array_fetch_string(¶ms_src, params, SL("src"), PH_NOISY_CC); PHALCON_INIT_VAR(src); PHALCON_CALL_METHOD_PARAMS_1(src, url, "get", params_src, PH_NO_CHECK); phalcon_array_update_string(¶ms, SL("src"), &src, PH_COPY | PH_SEPARATE TSRMLS_CC); } PHALCON_INIT_VAR(code); ZVAL_STRING(code, "<script", 1); if (!phalcon_valid_foreach(params TSRMLS_CC)) { return; } ah0 = Z_ARRVAL_P(params); 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_KEY(key, ah0, hp0); PHALCON_GET_FOREACH_VALUE(value); if (Z_TYPE_P(key) != IS_LONG) { PHALCON_SCONCAT_SVSVS(code, " ", key, "=\"", value, "\""); } zend_hash_move_forward_ex(ah0, &hp0); goto ph_cycle_start_0; ph_cycle_end_0: phalcon_concat_self_str(code, SL("></script>") TSRMLS_CC); RETURN_CTOR(code); }
/** * Builds a HTML TEXTAREA tag * *<code> * echo Phalcon\Tag::textArea(array("comments", "cols" => 10, "rows" => 4)) *</code> * * Volt syntax: *<code> * {{ text_area("comments", "cols": 10, "rows": 4) }} *</code> * * @param array $parameters * @return string */ PHP_METHOD(Phalcon_Tag, textArea){ zval *parameters, *params = NULL, *id = NULL, *name, *content = NULL, *code; zval *avalue = NULL, *key = NULL; HashTable *ah0; HashPosition hp0; zval **hd; PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 0, ¶meters); if (Z_TYPE_P(parameters) != IS_ARRAY) { PHALCON_INIT_VAR(params); array_init_size(params, 1); phalcon_array_append(¶ms, parameters, PH_SEPARATE TSRMLS_CC); } else { PHALCON_CPY_WRT(params, parameters); } if (!phalcon_array_isset_long(params, 0)) { if (phalcon_array_isset_string(params, SS("id"))) { PHALCON_OBS_VAR(id); phalcon_array_fetch_string(&id, params, SL("id"), PH_NOISY_CC); phalcon_array_update_long(¶ms, 0, &id, PH_COPY | PH_SEPARATE TSRMLS_CC); } } PHALCON_OBS_NVAR(id); phalcon_array_fetch_long(&id, params, 0, PH_NOISY_CC); if (!phalcon_array_isset_string(params, SS("name"))) { phalcon_array_update_string(¶ms, SL("name"), &id, PH_COPY | PH_SEPARATE TSRMLS_CC); } else { PHALCON_OBS_VAR(name); phalcon_array_fetch_string(&name, params, SL("name"), PH_NOISY_CC); if (!zend_is_true(name)) { phalcon_array_update_string(¶ms, SL("name"), &id, PH_COPY | PH_SEPARATE TSRMLS_CC); } } if (!phalcon_array_isset_string(params, SS("id"))) { phalcon_array_update_string(¶ms, SL("id"), &id, PH_COPY | PH_SEPARATE TSRMLS_CC); } if (phalcon_array_isset_string(params, SS("value"))) { PHALCON_OBS_VAR(content); phalcon_array_fetch_string(&content, params, SL("value"), PH_NOISY_CC); phalcon_array_unset_string(¶ms, SS("value"), PH_SEPARATE); } else { PHALCON_INIT_NVAR(content); PHALCON_CALL_SELF_PARAMS_2(content, this_ptr, "getvalue", id, params); } PHALCON_INIT_VAR(code); ZVAL_STRING(code, "<textarea", 1); if (!phalcon_is_iterable(params, &ah0, &hp0, 0, 0 TSRMLS_CC)) { return; } while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { PHALCON_GET_FOREACH_KEY(key, ah0, hp0); PHALCON_GET_FOREACH_VALUE(avalue); if (Z_TYPE_P(key) != IS_LONG) { PHALCON_SCONCAT_SVSVS(code, " ", key, "=\"", avalue, "\""); } zend_hash_move_forward_ex(ah0, &hp0); } PHALCON_SCONCAT_SVS(code, ">", content, "</textarea>"); RETURN_CTOR(code); }
/** * Builds a HTML A tag using framework conventions * *<code> * echo Phalcon\Tag::linkTo('signup/register', 'Register Here!'); *</code> * * @param array $parameters * @return string */ PHP_METHOD(Phalcon_Tag, linkTo){ zval *parameters, *text = NULL, *params = NULL, *action = NULL, *url, *internal_url; zval *code, *value = NULL, *key = NULL; HashTable *ah0; HashPosition hp0; zval **hd; char *hash_index; uint hash_index_len; ulong hash_num; int hash_type; int eval_int; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|z", ¶meters, &text) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } if (!text) { PHALCON_INIT_NVAR(text); } else { PHALCON_SEPARATE_PARAM(text); } if (Z_TYPE_P(parameters) != IS_ARRAY) { PHALCON_INIT_VAR(params); array_init(params); phalcon_array_append(¶ms, parameters, PH_SEPARATE TSRMLS_CC); phalcon_array_append(¶ms, text, PH_SEPARATE TSRMLS_CC); } else { PHALCON_CPY_WRT(params, parameters); } PHALCON_INIT_VAR(action); ZVAL_STRING(action, "", 1); eval_int = phalcon_array_isset_long(params, 0); if (eval_int) { PHALCON_INIT_NVAR(action); phalcon_array_fetch_long(&action, params, 0, PH_NOISY_CC); } else { eval_int = phalcon_array_isset_string(params, SS("action")); if (eval_int) { PHALCON_INIT_NVAR(action); phalcon_array_fetch_string(&action, params, SL("action"), PH_NOISY_CC); PHALCON_SEPARATE(params); phalcon_array_unset_string(params, SS("action")); } } PHALCON_INIT_NVAR(text); ZVAL_STRING(text, "", 1); eval_int = phalcon_array_isset_long(params, 1); if (eval_int) { PHALCON_INIT_NVAR(text); phalcon_array_fetch_long(&text, params, 1, PH_NOISY_CC); } else { eval_int = phalcon_array_isset_string(params, SS("text")); if (eval_int) { PHALCON_INIT_NVAR(text); phalcon_array_fetch_string(&text, params, SL("text"), PH_NOISY_CC); PHALCON_SEPARATE(params); phalcon_array_unset_string(params, SS("text")); } } PHALCON_INIT_VAR(url); PHALCON_CALL_SELF(url, this_ptr, "geturlservice"); PHALCON_INIT_VAR(internal_url); PHALCON_CALL_METHOD_PARAMS_1(internal_url, url, "get", action, PH_NO_CHECK); PHALCON_INIT_VAR(code); PHALCON_CONCAT_SVS(code, "<a href=\"", internal_url, "\""); if (!phalcon_valid_foreach(params TSRMLS_CC)) { return; } ah0 = Z_ARRVAL_P(params); zend_hash_internal_pointer_reset_ex(ah0, &hp0); ph_cycle_start_0: if (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) != SUCCESS) { goto ph_cycle_end_0; } PHALCON_GET_FOREACH_KEY(key, ah0, hp0); PHALCON_GET_FOREACH_VALUE(value); if (Z_TYPE_P(key) != IS_LONG) { PHALCON_SCONCAT_SVSVS(code, " ", key, "=\"", value, "\""); } zend_hash_move_forward_ex(ah0, &hp0); goto ph_cycle_start_0; ph_cycle_end_0: PHALCON_SCONCAT_SVS(code, ">", text, "</a>"); RETURN_CTOR(code); }
/** * Builds a SCRIPT[type="javascript"] tag * * <code> * echo Phalcon\Tag::javascriptInclude("http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js", false); * echo Phalcon\Tag::javascriptInclude("javascript/jquery.js"); * </code> * * Volt syntax: * <code> * {{ javascript_include("http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js", false) }} * {{ javascript_include("javascript/jquery.js") }} * </code> * * @param array $parameters * @param boolean $local * @return string */ PHP_METHOD(Phalcon_Tag, javascriptInclude){ zval *parameters = NULL, *local = NULL, *params = NULL, *first_param; zval *url, *params_src, *src, *eol, *code, *value = NULL, *key = NULL; HashTable *ah0; HashPosition hp0; zval **hd; PHALCON_MM_GROW(); phalcon_fetch_params(1, 0, 2, ¶meters, &local); if (!parameters) { PHALCON_INIT_VAR(parameters); } if (!local) { PHALCON_INIT_VAR(local); ZVAL_BOOL(local, 1); } else { PHALCON_SEPARATE_PARAM(local); } if (Z_TYPE_P(parameters) != IS_ARRAY) { PHALCON_INIT_VAR(params); array_init_size(params, 2); phalcon_array_append(¶ms, parameters, PH_SEPARATE TSRMLS_CC); phalcon_array_append(¶ms, local, PH_SEPARATE TSRMLS_CC); } else { PHALCON_CPY_WRT(params, parameters); } if (!phalcon_array_isset_string(params, SS("src"))) { if (phalcon_array_isset_long(params, 0)) { PHALCON_OBS_VAR(first_param); phalcon_array_fetch_long(&first_param, params, 0, PH_NOISY_CC); phalcon_array_update_string(¶ms, SL("src"), &first_param, PH_COPY | PH_SEPARATE TSRMLS_CC); } else { phalcon_array_update_string_string(¶ms, SL("src"), SL(""), PH_SEPARATE TSRMLS_CC); } } PHALCON_INIT_NVAR(local); ZVAL_STRING(local, "", 1); if (phalcon_array_isset_long(params, 1)) { PHALCON_OBS_NVAR(local); phalcon_array_fetch_long(&local, params, 1, PH_NOISY_CC); } else { if (phalcon_array_isset_string(params, SS("local"))) { PHALCON_OBS_NVAR(local); phalcon_array_fetch_string(&local, params, SL("local"), PH_NOISY_CC); phalcon_array_unset_string(¶ms, SS("local"), PH_SEPARATE); } } if (!phalcon_array_isset_string(params, SS("type"))) { phalcon_array_update_string_string(¶ms, SL("type"), SL("text/javascript"), PH_SEPARATE TSRMLS_CC); } if (zend_is_true(local)) { /** * URLs are generated through the 'url' service */ PHALCON_INIT_VAR(url); PHALCON_CALL_SELF(url, this_ptr, "geturlservice"); PHALCON_OBS_VAR(params_src); phalcon_array_fetch_string(¶ms_src, params, SL("src"), PH_NOISY_CC); PHALCON_INIT_VAR(src); PHALCON_CALL_METHOD_PARAMS_1(src, url, "get", params_src); phalcon_array_update_string(¶ms, SL("src"), &src, PH_COPY | PH_SEPARATE TSRMLS_CC); } PHALCON_INIT_VAR(eol); ZVAL_STRING(eol, PHP_EOL, 1); PHALCON_INIT_VAR(code); ZVAL_STRING(code, "<script", 1); if (!phalcon_is_iterable(params, &ah0, &hp0, 0, 0 TSRMLS_CC)) { return; } while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { PHALCON_GET_FOREACH_KEY(key, ah0, hp0); PHALCON_GET_FOREACH_VALUE(value); if (Z_TYPE_P(key) != IS_LONG) { PHALCON_SCONCAT_SVSVS(code, " ", key, "=\"", value, "\""); } zend_hash_move_forward_ex(ah0, &hp0); } PHALCON_SCONCAT_SV(code, "></script>", eol); RETURN_CTOR(code); }
/** * Builds a HTML TEXTAREA tag * *<code> * echo Phalcon\Tag::textArea(array("comments", "cols" => 10, "rows" => 4)) *</code> * * @param array $parameters * @return string */ PHP_METHOD(Phalcon_Tag, textArea){ zval *parameters, *params = NULL, *id = NULL, *name, *content = NULL, *code; zval *avalue = NULL, *key = NULL; HashTable *ah0; HashPosition hp0; zval **hd; char *hash_index; uint hash_index_len; ulong hash_num; int hash_type; int eval_int; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", ¶meters) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } if (Z_TYPE_P(parameters) != IS_ARRAY) { PHALCON_INIT_VAR(params); array_init(params); phalcon_array_append(¶ms, parameters, PH_SEPARATE TSRMLS_CC); } else { PHALCON_CPY_WRT(params, parameters); } eval_int = phalcon_array_isset_long(params, 0); if (!eval_int) { eval_int = phalcon_array_isset_string(params, SS("id")); if (eval_int) { PHALCON_INIT_VAR(id); phalcon_array_fetch_string(&id, params, SL("id"), PH_NOISY_CC); phalcon_array_update_long(¶ms, 0, &id, PH_COPY | PH_SEPARATE TSRMLS_CC); } } PHALCON_INIT_NVAR(id); phalcon_array_fetch_long(&id, params, 0, PH_NOISY_CC); eval_int = phalcon_array_isset_string(params, SS("name")); if (!eval_int) { phalcon_array_update_string(¶ms, SL("name"), &id, PH_COPY | PH_SEPARATE TSRMLS_CC); } else { PHALCON_INIT_VAR(name); phalcon_array_fetch_string(&name, params, SL("name"), PH_NOISY_CC); if (!zend_is_true(name)) { phalcon_array_update_string(¶ms, SL("name"), &id, PH_COPY | PH_SEPARATE TSRMLS_CC); } } eval_int = phalcon_array_isset_string(params, SS("id")); if (!eval_int) { phalcon_array_update_string(¶ms, SL("id"), &id, PH_COPY | PH_SEPARATE TSRMLS_CC); } eval_int = phalcon_array_isset_string(params, SS("value")); if (eval_int) { PHALCON_INIT_VAR(content); phalcon_array_fetch_string(&content, params, SL("value"), PH_NOISY_CC); PHALCON_SEPARATE(params); phalcon_array_unset_string(params, SS("value")); } else { PHALCON_INIT_NVAR(content); PHALCON_CALL_SELF_PARAMS_1(content, this_ptr, "getvalue", id); } PHALCON_INIT_VAR(code); ZVAL_STRING(code, "<textarea", 1); if (!phalcon_valid_foreach(params TSRMLS_CC)) { return; } ah0 = Z_ARRVAL_P(params); zend_hash_internal_pointer_reset_ex(ah0, &hp0); ph_cycle_start_0: if (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) != SUCCESS) { goto ph_cycle_end_0; } PHALCON_GET_FOREACH_KEY(key, ah0, hp0); PHALCON_GET_FOREACH_VALUE(avalue); if (Z_TYPE_P(key) != IS_LONG) { PHALCON_SCONCAT_SVSVS(code, " ", key, "=\"", avalue, "\""); } zend_hash_move_forward_ex(ah0, &hp0); goto ph_cycle_start_0; ph_cycle_end_0: PHALCON_SCONCAT_SVS(code, ">", content, "</textarea>"); RETURN_CTOR(code); }
/** * Helper method to query records based on a relation definition * * @param array $relation * @param string $method * @param Phalcon\Mvc\Model $record * @param array $parameters * @return Phalcon\Mvc\Model\Resultset\Simple */ PHP_METHOD(Phalcon_Mvc_Model_Manager, _getRelationRecords){ zval *relation = NULL, *method = NULL, *record = NULL, *parameters = NULL, *placeholders = NULL; zval *pre_conditions = NULL, *conditions = NULL, *fields = NULL, *field = NULL; zval *value = NULL, *referenced_field = NULL, *condition = NULL, *i = NULL; zval *referenced_fields = NULL, *join_conditions = NULL; zval *find_params = NULL, *find_arguments = NULL, *arguments = NULL; zval *reference_table = NULL, *referenced_entity = NULL; zval *connection_service = NULL, *call_object = NULL, *records = NULL; zval *c0 = NULL; HashTable *ah0; HashPosition hp0; zval **hd; int eval_int; zend_class_entry *ce0; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zzz|z", &relation, &method, &record, ¶meters) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } if (!parameters) { PHALCON_ALLOC_ZVAL_MM(parameters); ZVAL_NULL(parameters); } else { PHALCON_SEPARATE_PARAM(parameters); } if (Z_TYPE_P(parameters) == IS_ARRAY) { eval_int = phalcon_array_isset_string(parameters, SL("bind")+1); if (eval_int) { PHALCON_INIT_VAR(placeholders); phalcon_array_fetch_string(&placeholders, parameters, SL("bind"), PH_NOISY_CC); PHALCON_SEPARATE_PARAM(parameters); phalcon_array_unset_string(parameters, SL("bind")+1); } else { PHALCON_INIT_VAR(placeholders); array_init(placeholders); } } else { PHALCON_INIT_VAR(placeholders); array_init(placeholders); } PHALCON_INIT_VAR(pre_conditions); ZVAL_NULL(pre_conditions); if (Z_TYPE_P(parameters) == IS_ARRAY) { eval_int = phalcon_array_isset_long(parameters, 0); if (eval_int) { PHALCON_INIT_VAR(pre_conditions); phalcon_array_fetch_long(&pre_conditions, parameters, 0, PH_NOISY_CC); PHALCON_SEPARATE_PARAM(parameters); phalcon_array_unset_long(parameters, 0); } else { eval_int = phalcon_array_isset_string(parameters, SL("conditions")+1); if (eval_int) { PHALCON_INIT_VAR(pre_conditions); phalcon_array_fetch_string(&pre_conditions, parameters, SL("conditions"), PH_NOISY_CC); PHALCON_SEPARATE_PARAM(parameters); phalcon_array_unset_string(parameters, SL("conditions")+1); } } } else { if (Z_TYPE_P(parameters) == IS_STRING) { PHALCON_CPY_WRT(pre_conditions, parameters); } } if (Z_TYPE_P(pre_conditions) != IS_NULL) { PHALCON_INIT_VAR(conditions); array_init(conditions); phalcon_array_append(&conditions, pre_conditions, PH_SEPARATE TSRMLS_CC); } else { PHALCON_INIT_VAR(conditions); array_init(conditions); } PHALCON_INIT_VAR(fields); phalcon_array_fetch_string(&fields, relation, SL("fi"), PH_NOISY_CC); if (Z_TYPE_P(fields) != IS_ARRAY) { PHALCON_CPY_WRT(field, fields); PHALCON_INIT_VAR(value); PHALCON_CALL_METHOD_PARAMS_1(value, record, "readattribute", field, PH_NO_CHECK); PHALCON_INIT_VAR(referenced_field); phalcon_array_fetch_string(&referenced_field, relation, SL("rf"), PH_NOISY_CC); PHALCON_INIT_VAR(condition); PHALCON_CONCAT_VS(condition, referenced_field, " = ?0"); phalcon_array_append(&conditions, condition, PH_SEPARATE TSRMLS_CC); phalcon_array_append(&placeholders, value, PH_SEPARATE TSRMLS_CC); } else { PHALCON_INIT_VAR(i); ZVAL_LONG(i, 0); PHALCON_INIT_VAR(referenced_fields); phalcon_array_fetch_string(&referenced_fields, relation, SL("rf"), PH_NOISY_CC); if (!phalcon_valid_foreach(fields TSRMLS_CC)) { return; } ah0 = Z_ARRVAL_P(fields); zend_hash_internal_pointer_reset_ex(ah0, &hp0); fes_74b5_0: if(zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) != SUCCESS){ goto fee_74b5_0; } PHALCON_INIT_VAR(field); ZVAL_ZVAL(field, *hd, 1, 0); PHALCON_INIT_VAR(value); PHALCON_CALL_METHOD_PARAMS_1(value, record, "readattribute", field, PH_NO_CHECK); PHALCON_INIT_VAR(referenced_field); phalcon_array_fetch(&referenced_field, referenced_fields, i, PH_NOISY_CC); PHALCON_INIT_VAR(condition); PHALCON_CONCAT_VSV(condition, referenced_field, " = ?", i); phalcon_array_append(&conditions, condition, PH_SEPARATE TSRMLS_CC); phalcon_array_append(&placeholders, value, PH_SEPARATE TSRMLS_CC); PHALCON_SEPARATE(i); increment_function(i); zend_hash_move_forward_ex(ah0, &hp0); goto fes_74b5_0; fee_74b5_0: if(0){} } PHALCON_INIT_VAR(c0); ZVAL_STRING(c0, " AND ", 1); PHALCON_INIT_VAR(join_conditions); phalcon_fast_join(join_conditions, c0, conditions TSRMLS_CC); PHALCON_INIT_VAR(find_params); array_init(find_params); phalcon_array_append(&find_params, join_conditions, PH_SEPARATE TSRMLS_CC); phalcon_array_update_string(&find_params, SL("bind"), &placeholders, PH_COPY | PH_SEPARATE TSRMLS_CC); if (Z_TYPE_P(parameters) == IS_ARRAY) { PHALCON_INIT_VAR(find_arguments); PHALCON_CALL_FUNC_PARAMS_2(find_arguments, "array_merge", find_params, parameters); } else { PHALCON_CPY_WRT(find_arguments, find_params); } PHALCON_INIT_VAR(arguments); array_init(arguments); phalcon_array_append(&arguments, find_arguments, PH_SEPARATE TSRMLS_CC); PHALCON_INIT_VAR(reference_table); phalcon_array_fetch_string(&reference_table, relation, SL("rt"), PH_NOISY_CC); ce0 = phalcon_fetch_class(reference_table TSRMLS_CC); PHALCON_INIT_VAR(referenced_entity); object_init_ex(referenced_entity, ce0); PHALCON_CALL_METHOD_NORETURN(referenced_entity, "__construct", PH_CHECK); PHALCON_INIT_VAR(connection_service); PHALCON_CALL_METHOD(connection_service, record, "getconnectionservice", PH_NO_CHECK); PHALCON_CALL_METHOD_PARAMS_1_NORETURN(referenced_entity, "setconnectionservice", connection_service, PH_NO_CHECK); PHALCON_INIT_VAR(call_object); array_init(call_object); phalcon_array_append(&call_object, referenced_entity, PH_SEPARATE TSRMLS_CC); phalcon_array_append(&call_object, method, PH_SEPARATE TSRMLS_CC); PHALCON_INIT_VAR(records); PHALCON_CALL_FUNC_PARAMS_2(records, "call_user_func_array", call_object, arguments); RETURN_CCTOR(records); }
/** * 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 = NULL, *options = NULL, *persistent = NULL; zval *r0 = NULL, *r1 = NULL; zval *t0 = NULL; zval *c0 = NULL; zval *i0 = 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 (!zend_is_true(descriptor)) { PHALCON_INIT_VAR(descriptor); phalcon_read_property(&descriptor, this_ptr, SL("_descriptor"), PH_NOISY_CC); } eval_int = phalcon_array_isset_string(descriptor, SL("username")+1); 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, SL("username")+1); } else { PHALCON_INIT_VAR(username); ZVAL_NULL(username); } eval_int = phalcon_array_isset_string(descriptor, SL("password")+1); 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, SL("password")+1); } else { PHALCON_INIT_VAR(password); ZVAL_NULL(password); } 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); fes_7f5d_0: if(zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) != SUCCESS){ goto fee_7f5d_0; } PHALCON_INIT_VAR(key); PHALCON_GET_FOREACH_KEY(key, ah0, hp0); PHALCON_INIT_VAR(value); ZVAL_ZVAL(value, *hd, 1, 0); PHALCON_INIT_VAR(r0); PHALCON_CONCAT_VSV(r0, key, "=", value); phalcon_array_append(&dsn_parts, r0, PH_SEPARATE TSRMLS_CC); zend_hash_move_forward_ex(ah0, &hp0); goto fes_7f5d_0; fee_7f5d_0: if(0){} PHALCON_ALLOC_ZVAL_MM(t0); phalcon_read_property(&t0, this_ptr, SL("_type"), PH_NOISY_CC); PHALCON_INIT_VAR(c0); ZVAL_STRING(c0, ";", 1); PHALCON_ALLOC_ZVAL_MM(r1); phalcon_fast_join(r1, c0, dsn_parts TSRMLS_CC); PHALCON_INIT_VAR(dsn); PHALCON_CONCAT_VSV(dsn, t0, ":", r1); PHALCON_INIT_VAR(options); array_init(options); add_index_long(options, 3, 0); add_index_long(options, 8, 2); add_index_long(options, 10, 1); eval_int = phalcon_array_isset_string(descriptor, SL("persistent")+1); 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, 12, 1, PH_SEPARATE TSRMLS_CC); } } ce0 = zend_fetch_class(SL("PDO"), ZEND_FETCH_CLASS_AUTO TSRMLS_CC); PHALCON_ALLOC_ZVAL_MM(i0); object_init_ex(i0, ce0); PHALCON_CALL_METHOD_PARAMS_4_NORETURN(i0, "__construct", dsn, username, password, options, PH_CHECK); phalcon_update_property_zval(this_ptr, SL("_pdo"), i0 TSRMLS_CC); PHALCON_CALL_PARENT_PARAMS_1_NORETURN(this_ptr, "Phalcon\\Db\\Adapter\\Pdo", "__construct", descriptor); PHALCON_MM_RESTORE(); }