/** * Uncamelize strings which are camelized * *<code> * echo Phalcon\Text::camelize('CocoBongo'); //coco_bongo *</code> * * @param string $str * @return string */ PHP_METHOD(Phalcon_Text, uncamelize) { zval *str; phalcon_fetch_params(0, 1, 0, &str); phalcon_uncamelize(return_value, str); return; }
/** * Uncamelize strings which are camelized * *<code> * echo Phalcon\Text::camelize('CocoBongo'); //coco_bongo *</code> * * @param string $str * @return string */ PHP_METHOD(Phalcon_Text, uncamelize){ zval *str, *uncamelized; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &str) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } PHALCON_INIT_VAR(uncamelized); phalcon_uncamelize(uncamelized, str TSRMLS_CC); RETURN_CCTOR(uncamelized); }
/** * Reconfigure the route adding a new pattern and a set of paths * * @param string $pattern * @param array $paths */ PHP_METHOD(Phalcon_Mvc_Router_Route, reConfigure){ zval *pattern, *paths = NULL, *module_name = NULL, *controller_name = NULL; zval *action_name = NULL, *parts, *number_parts, *route_paths = NULL; zval *real_class_name = NULL, *namespace_name, *lower_name; zval *pcre_pattern = NULL, *compiled_pattern = NULL; PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 1, &pattern, &paths); if (!paths) { PHALCON_INIT_VAR(paths); } if (Z_TYPE_P(pattern) != IS_STRING) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_router_exception_ce, "The pattern must be string"); return; } if (Z_TYPE_P(paths) != IS_NULL) { if (Z_TYPE_P(paths) == IS_STRING) { PHALCON_INIT_VAR(module_name); PHALCON_INIT_VAR(controller_name); PHALCON_INIT_VAR(action_name); /** * Explode the short paths using the :: separator */ PHALCON_INIT_VAR(parts); phalcon_fast_explode_str(parts, SL("::"), paths); PHALCON_INIT_VAR(number_parts); phalcon_fast_count(number_parts, parts TSRMLS_CC); /** * Create the array paths dynamically */ switch (phalcon_get_intval(number_parts)) { case 3: PHALCON_OBS_NVAR(module_name); phalcon_array_fetch_long(&module_name, parts, 0, PH_NOISY); PHALCON_OBS_NVAR(controller_name); phalcon_array_fetch_long(&controller_name, parts, 1, PH_NOISY); PHALCON_OBS_NVAR(action_name); phalcon_array_fetch_long(&action_name, parts, 2, PH_NOISY); break; case 2: PHALCON_OBS_NVAR(controller_name); phalcon_array_fetch_long(&controller_name, parts, 0, PH_NOISY); PHALCON_OBS_NVAR(action_name); phalcon_array_fetch_long(&action_name, parts, 1, PH_NOISY); break; case 1: PHALCON_OBS_NVAR(controller_name); phalcon_array_fetch_long(&controller_name, parts, 0, PH_NOISY); break; } PHALCON_INIT_VAR(route_paths); array_init(route_paths); /** * Process module name */ if (Z_TYPE_P(module_name) != IS_NULL) { phalcon_array_update_string(&route_paths, SL("module"), &module_name, PH_COPY | PH_SEPARATE); } /** * Process controller name */ if (Z_TYPE_P(controller_name) != IS_NULL) { /** * Check if we need to obtain the namespace */ if (phalcon_memnstr_str(controller_name, SL("\\"))) { /** * Extract the real class name from the namespaced class */ PHALCON_INIT_VAR(real_class_name); phalcon_get_class_ns(real_class_name, controller_name, 0 TSRMLS_CC); /** * Extract the namespace from the namespaced class */ PHALCON_INIT_VAR(namespace_name); phalcon_get_ns_class(namespace_name, controller_name, 0 TSRMLS_CC); /** * Update the namespace */ if (zend_is_true(namespace_name)) { phalcon_array_update_string(&route_paths, SL("namespace"), &namespace_name, PH_COPY | PH_SEPARATE); } } else { PHALCON_CPY_WRT(real_class_name, controller_name); } /** * Always pass the controller to lowercase */ PHALCON_INIT_VAR(lower_name); phalcon_uncamelize(lower_name, real_class_name); /** * Update the controller path */ phalcon_array_update_string(&route_paths, SL("controller"), &lower_name, PH_COPY | PH_SEPARATE); } /** * Process action name */ if (Z_TYPE_P(action_name) != IS_NULL) { phalcon_array_update_string(&route_paths, SL("action"), &action_name, PH_COPY | PH_SEPARATE); } } else { PHALCON_CPY_WRT(route_paths, paths); } } else { PHALCON_INIT_NVAR(route_paths); array_init(route_paths); } if (Z_TYPE_P(route_paths) != IS_ARRAY) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_router_exception_ce, "The route contains invalid paths"); return; } /** * If the route starts with '#' we assume that it is a regular expression */ if (!phalcon_start_with_str(pattern, SL("#"))) { if (phalcon_memnstr_str(pattern, SL("{"))) { /** * The route has named parameters so we need to extract them */ PHALCON_INIT_VAR(pcre_pattern); phalcon_extract_named_params(pcre_pattern, pattern, route_paths); } else { PHALCON_CPY_WRT(pcre_pattern, pattern); } /** * Transform the route's pattern to a regular expression */ PHALCON_INIT_VAR(compiled_pattern); phalcon_call_method_p1(compiled_pattern, this_ptr, "compilepattern", pcre_pattern); } else { PHALCON_CPY_WRT(compiled_pattern, pattern); } /** * Update the original pattern */ phalcon_update_property_this(this_ptr, SL("_pattern"), pattern TSRMLS_CC); /** * Update the compiled pattern */ phalcon_update_property_this(this_ptr, SL("_compiledPattern"), compiled_pattern TSRMLS_CC); /** * Update the route's paths */ phalcon_update_property_this(this_ptr, SL("_paths"), route_paths TSRMLS_CC); PHALCON_MM_RESTORE(); }