diff --git a/.gitignore b/.gitignore index 255c8b195ab..d3a44368262 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,8 @@ .idea unit-tests/engines/* unit-tests/logs/* +unit-tests/cache/2e11fab3b6861010be11a5deb92bddff +unit-tests/cache/7ea1207f9d82bf4982cf5e1aec693375 build/.deps build/.libs/ build/Makefile diff --git a/CHANGELOG b/CHANGELOG index 2557478b058..d3bdd20900d 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,14 @@ +0.6.1 + - Fixed bug in Phalcon\Mvc\Micro's not-found handler + - Fixed bug reading named-parameters with quantifiers in Phalcon\Mvc\Router + - Now named-routes are processed without use regular expressions + - Now $this->view->disable() disables the auto-rendering mode completely + - Added Phalcon\Mvc\View::enable that re-enables the auto-rendering mode + - Added Phalcon\Cache\Backend::stop() to stop the cache without store anything into the backend + - Fixed bug in Phalcon\Mvc\View that saves a empty cached content when using a cache + - Implemented Phalcon\Db::FETCH_OBJ to return objects instead of arrays + - Removed checking for callable definitions in Phalcon\DI due to security reasons + 0.6.0 - Added functions version, version_id, date and time to Volt - PHQL OFFSET complete implementation diff --git a/build/phalcon.c b/build/phalcon.c index 59e43e880a1..d148badbcb5 100644 --- a/build/phalcon.c +++ b/build/phalcon.c @@ -1049,6 +1049,9 @@ void phalcon_fast_str_replace(zval *return_value, zval *search, zval *replace, z void phalcon_camelize(zval *return_value, zval *str TSRMLS_DC); void phalcon_uncamelize(zval *return_value, zval *str TSRMLS_DC); +/** Extract named parameters */ +void phalcon_extract_named_params(zval *return_value, zval *str, zval *matches); + @@ -4502,6 +4505,118 @@ void phalcon_fast_str_replace(zval *return_value, zval *search, zval *replace, z } +void phalcon_extract_named_params(zval *return_value, zval *str, zval *matches){ + + unsigned int i, j, bracket_count = 0; + unsigned int intermediate, length, number_matches = 0; + int variable_length, regexp_length, not_valid; + char *cursor, *cursor_var, *marker, ch; + char *item, *variable = NULL, *regexp; + smart_str route_str = {0}; + + if (Z_TYPE_P(str) != IS_STRING) { + ZVAL_BOOL(return_value, 0); + return; + } + + if (Z_STRLEN_P(str) <= 0) { + ZVAL_BOOL(return_value, 0); + return; + } + + cursor = Z_STRVAL_P(str); + for (i = 0; i 0) { + if (bracket_count == 0) { + + number_matches++; + + length = cursor - marker - 1; + item = estrndup(marker + 1, length); + cursor_var = item; + marker = item; + for (j=0; j= 'a' && ch <='z') || (ch >= 'A' && ch <='Z'))){ + not_valid = 1; + break; + } + if ((ch >= 'a' && ch <='z') || (ch >= 'A' && ch <='Z') || (ch >= '0' && ch <='9') || ch == ':') { + if (ch == ':') { + regexp_length = length - j - 1; + variable_length = cursor_var - marker; + variable = estrndup(marker, variable_length); + regexp = estrndup(cursor_var+1, regexp_length); + break; + } + } else { + not_valid = 1; + break; + } + cursor_var++; + } + + if (!not_valid) { + { + zval *tmp; + ALLOC_INIT_ZVAL(tmp); + ZVAL_LONG(tmp, number_matches); + + if (variable) { + smart_str_appendc(&route_str, '('); + smart_str_appendl(&route_str, regexp, regexp_length); + smart_str_appendc(&route_str, ')'); + zend_hash_update(Z_ARRVAL_P(matches), variable, variable_length+1, &tmp, sizeof(zval *), NULL); + efree(regexp); + efree(variable); + } else { + smart_str_appendl(&route_str, "([^/]*)", strlen("([^/]*)")); + zend_hash_update(Z_ARRVAL_P(matches), item, length+1, &tmp, sizeof(zval *), NULL); + } + } + } else { + smart_str_appendc(&route_str, '{'); + smart_str_appendl(&route_str, item, length); + smart_str_appendc(&route_str, '}'); + } + + efree(item); + + } + variable = NULL; + } + } else { + if (bracket_count > 0) { + intermediate++; + } else { + smart_str_appendc(&route_str, ch); + } + } + } + cursor++; + } + smart_str_0(&route_str); + + if (route_str.len) { + RETURN_STRINGL(route_str.c, route_str.len, 0); + } else { + smart_str_free(&route_str); + RETURN_EMPTY_STRING(); + } + +} + #ifdef HAVE_CONFIG_H @@ -6994,6 +7109,33 @@ PHP_METHOD(Phalcon_Cache_Backend, start){ RETURN_CCTOR(existing_cache); } +PHP_METHOD(Phalcon_Cache_Backend, stop){ + + zval *stop_buffer = NULL, *front_end; + + PHALCON_MM_GROW(); + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|z", &stop_buffer) == FAILURE) { + PHALCON_MM_RESTORE(); + RETURN_NULL(); + } + + if (!stop_buffer) { + PHALCON_INIT_NVAR(stop_buffer); + ZVAL_BOOL(stop_buffer, 1); + } + + PHALCON_INIT_VAR(front_end); + phalcon_read_property(&front_end, this_ptr, SL("_frontendObject"), PH_NOISY_CC); + if (PHALCON_IS_TRUE(stop_buffer)) { + PHALCON_CALL_METHOD_NORETURN(front_end, "stop", PH_NO_CHECK); + } + + phalcon_update_property_bool(this_ptr, SL("_started"), 0 TSRMLS_CC); + + PHALCON_MM_RESTORE(); +} + PHP_METHOD(Phalcon_Cache_Backend, getFrontend){ zval *frontend; @@ -12020,6 +12162,21 @@ PHP_METHOD(Phalcon_Db_Result_Pdo, execute){ RETURN_CCTOR(status); } +PHP_METHOD(Phalcon_Db_Result_Pdo, fetch){ + + zval *pdo_statement, *row; + + PHALCON_MM_GROW(); + + PHALCON_INIT_VAR(pdo_statement); + phalcon_read_property(&pdo_statement, this_ptr, SL("_pdoStatement"), PH_NOISY_CC); + + PHALCON_INIT_VAR(row); + PHALCON_CALL_METHOD(row, pdo_statement, "fetch", PH_NO_CHECK); + + RETURN_CCTOR(row); +} + PHP_METHOD(Phalcon_Db_Result_Pdo, fetchArray){ zval *pdo_statement, *row; @@ -12100,7 +12257,7 @@ PHP_METHOD(Phalcon_Db_Result_Pdo, numRows){ PHALCON_CALL_METHOD_PARAMS_3(result, connection, "query", sql, bind_params, bind_types, PH_NO_CHECK); PHALCON_INIT_VAR(row); - PHALCON_CALL_METHOD(row, result, "fetcharray", PH_NO_CHECK); + PHALCON_CALL_METHOD(row, result, "fetch", PH_NO_CHECK); PHALCON_INIT_NVAR(row_count); phalcon_array_fetch_long(&row_count, row, 0, PH_NOISY_CC); @@ -12166,7 +12323,7 @@ PHP_METHOD(Phalcon_Db_Result_Pdo, dataSeek){ PHP_METHOD(Phalcon_Db_Result_Pdo, setFetchMode){ long fetch_mode; - zval *pdo_statement = NULL, *fetch_type = NULL; + zval *pdo_statement, *fetch_type; PHALCON_MM_GROW(); @@ -12193,6 +12350,12 @@ PHP_METHOD(Phalcon_Db_Result_Pdo, setFetchMode){ ZVAL_LONG(fetch_type, 3); PHALCON_CALL_METHOD_PARAMS_1_NORETURN(pdo_statement, "setfetchmode", fetch_type, PH_NO_CHECK); phalcon_update_property_long(this_ptr, SL("_fetchMode"), 3 TSRMLS_CC); + } else { + if (fetch_mode == 4) { + ZVAL_LONG(fetch_type, 5); + PHALCON_CALL_METHOD_PARAMS_1_NORETURN(pdo_statement, "setfetchmode", fetch_type, PH_NO_CHECK); + phalcon_update_property_long(this_ptr, SL("_fetchMode"), 5 TSRMLS_CC); + } } } } @@ -14536,23 +14699,6 @@ PHP_METHOD(Phalcon_Text, uncamelize){ RETURN_CCTOR(uncamelized); } -PHP_METHOD(Phalcon_Text, x){ - - zval *a, *b, *x; - - PHALCON_MM_GROW(); - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz", &a, &b) == FAILURE) { - PHALCON_MM_RESTORE(); - RETURN_NULL(); - } - - PHALCON_INIT_VAR(x); - PHALCON_CALL_USER_FUNC_ARRAY(x, a, b); - - RETURN_CCTOR(x); -} - @@ -17626,6 +17772,7 @@ PHP_METHOD(Phalcon_Config, __construct){ uint hash_index_len; ulong hash_num; int hash_type; + int eval_int; PHALCON_MM_GROW(); @@ -17658,10 +17805,15 @@ PHP_METHOD(Phalcon_Config, __construct){ PHALCON_GET_FOREACH_VALUE(value); if (Z_TYPE_P(value) == IS_ARRAY) { - PHALCON_INIT_NVAR(config_value); - object_init_ex(config_value, phalcon_config_ce); - PHALCON_CALL_METHOD_PARAMS_1_NORETURN(config_value, "__construct", value, PH_CHECK); - phalcon_update_property_zval_zval(this_ptr, key, config_value TSRMLS_CC); + eval_int = phalcon_array_isset_long(value, 0); + if (!eval_int) { + PHALCON_INIT_NVAR(config_value); + object_init_ex(config_value, phalcon_config_ce); + PHALCON_CALL_METHOD_PARAMS_1_NORETURN(config_value, "__construct", value, PH_CHECK); + phalcon_update_property_zval_zval(this_ptr, key, config_value TSRMLS_CC); + } else { + phalcon_update_property_zval_zval(this_ptr, key, value TSRMLS_CC); + } } else { phalcon_update_property_zval_zval(this_ptr, key, value TSRMLS_CC); } @@ -17680,6 +17832,24 @@ PHP_METHOD(Phalcon_Config, __construct){ PHALCON_MM_RESTORE(); } +PHP_METHOD(Phalcon_Config, __set_state){ + + zval *data, *config; + + PHALCON_MM_GROW(); + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &data) == FAILURE) { + PHALCON_MM_RESTORE(); + RETURN_NULL(); + } + + PHALCON_INIT_VAR(config); + object_init_ex(config, phalcon_config_ce); + PHALCON_CALL_METHOD_PARAMS_1_NORETURN(config, "__construct", data, PH_CHECK); + + RETURN_CTOR(config); +} + @@ -20074,6 +20244,7 @@ PHP_METHOD(Phalcon_Mvc_Micro, handle){ zval *event_name = NULL, *status = NULL, *service, *router, *matched_route; zval *handlers, *route_id, *handler = NULL, *params, *returned_value = NULL; zval *not_found_handler; + zval *r0 = NULL; int eval_int; PHALCON_MM_GROW(); @@ -20165,7 +20336,10 @@ PHP_METHOD(Phalcon_Mvc_Micro, handle){ PHALCON_INIT_VAR(not_found_handler); phalcon_read_property(¬_found_handler, this_ptr, SL("_notFoundHandler"), PH_NOISY_CC); - if (phalcon_is_callable(not_found_handler TSRMLS_CC)) { + + PHALCON_INIT_VAR(r0); + PHALCON_CALL_FUNC_PARAMS_1(r0, "is_callable", not_found_handler); + if (!zend_is_true(r0)) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_micro_exception_ce, "The Not-Found handler is not callable or is not defined"); return; } @@ -35297,17 +35471,8 @@ PHP_METHOD(Phalcon_Mvc_Router_Route, reConfigure){ zval *pattern, *paths = NULL, *double_colon, *parts, *part_zero; zval *controller_name, *route_paths = NULL, *part_one; - zval *one, *zero, *first, *have_bracket, *sharp, *escaped_sharp; - zval *pcre_pattern = NULL, *matches, *match_position; - zval *set_order, *names_pattern, *have_variables = NULL; - zval *match = NULL, *match_zero = NULL, *match_one = NULL, *match_two = NULL; - zval *replace_pattern = NULL, *new_pcre_pattern = NULL; + zval *one, *zero, *first, *have_bracket, *pcre_pattern = NULL; zval *compiled_pattern = NULL; - zval *r0 = NULL; - zval *p0[] = { NULL, NULL, NULL, NULL }; - HashTable *ah0; - HashPosition hp0; - zval **hd; int eval_int; PHALCON_MM_GROW(); @@ -35368,83 +35533,8 @@ PHP_METHOD(Phalcon_Mvc_Router_Route, reConfigure){ PHALCON_INIT_VAR(have_bracket); phalcon_fast_strpos_str(have_bracket, pattern, SL("{") TSRMLS_CC); if (PHALCON_IS_NOT_FALSE(have_bracket)) { - PHALCON_INIT_VAR(sharp); - ZVAL_STRING(sharp, "#", 1); - - PHALCON_INIT_VAR(escaped_sharp); - ZVAL_STRING(escaped_sharp, "\\#", 1); - PHALCON_INIT_VAR(pcre_pattern); - phalcon_fast_str_replace(pcre_pattern, sharp, escaped_sharp, pattern TSRMLS_CC); - - PHALCON_INIT_VAR(matches); - - PHALCON_INIT_VAR(match_position); - ZVAL_LONG(match_position, 1); - - PHALCON_INIT_VAR(set_order); - ZVAL_LONG(set_order, 2); - - PHALCON_INIT_VAR(names_pattern); - ZVAL_STRING(names_pattern, "#{([a-zA-Z][a-zA-Z0-9\\_\\-]*)(:([^}]+))*}#", 1); - p0[0] = names_pattern; - p0[1] = pcre_pattern; - Z_SET_ISREF_P(matches); - p0[2] = matches; - p0[3] = set_order; - - PHALCON_INIT_VAR(r0); - PHALCON_CALL_FUNC_PARAMS(r0, "preg_match_all", 4, p0); - Z_UNSET_ISREF_P(p0[2]); - PHALCON_CPY_WRT(have_variables, r0); - 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); - - 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(match); - - PHALCON_INIT_NVAR(match_zero); - phalcon_array_fetch_long(&match_zero, match, 0, PH_NOISY_CC); - - PHALCON_INIT_NVAR(match_one); - phalcon_array_fetch_long(&match_one, match, 1, PH_NOISY_CC); - eval_int = phalcon_array_isset_long(match, 3); - if (eval_int) { - PHALCON_INIT_NVAR(match_two); - phalcon_array_fetch_long(&match_two, match, 3, PH_NOISY_CC); - - PHALCON_INIT_NVAR(replace_pattern); - PHALCON_CONCAT_SVS(replace_pattern, "(", match_two, ")"); - } else { - PHALCON_INIT_NVAR(replace_pattern); - ZVAL_STRING(replace_pattern, "([^/]*)", 1); - } - - PHALCON_INIT_NVAR(new_pcre_pattern); - phalcon_fast_str_replace(new_pcre_pattern, match_zero, replace_pattern, pcre_pattern TSRMLS_CC); - PHALCON_CPY_WRT(pcre_pattern, new_pcre_pattern); - phalcon_array_update_zval(&route_paths, match_one, &match_position, PH_COPY | PH_SEPARATE TSRMLS_CC); - PHALCON_SEPARATE(match_position); - increment_function(match_position); - - zend_hash_move_forward_ex(ah0, &hp0); - goto ph_cycle_start_0; - - ph_cycle_end_0: - if(0){} - - } + phalcon_extract_named_params(pcre_pattern, pattern, route_paths); } else { PHALCON_CPY_WRT(pcre_pattern, pattern); } @@ -35824,7 +35914,7 @@ PHP_METHOD(Phalcon_Mvc_Url, get){ ZVAL_LONG(set_order, 2); PHALCON_INIT_VAR(names_pattern); - ZVAL_STRING(names_pattern, "#{([a-zA-Z][a-zA-Z0-9\\_\\-]+)(:([^}]+))*}#", 1); + 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); @@ -36485,7 +36575,7 @@ PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, _filter){ PHALCON_INIT_VAR(name); phalcon_array_fetch_string(&name, filter, SL("name"), PH_NOISY_CC); if (PHALCON_COMPARE_STRING(name, "length")) { - PHALCON_CONCAT_SVS(code, "$this->count(", left, ")"); + PHALCON_CONCAT_SVS(code, "$this->length(", left, ")"); ZVAL_BOOL(exists, 1); } @@ -42527,11 +42617,11 @@ PHP_METHOD(Phalcon_Mvc_View, _engineRender){ zval *engines, *view_path, *silence, *must_clean; zval *cache, *not_exists = NULL, *view_params, *views_dir; zval *base_path, *views_dir_path, *events_manager; - zval *render_level, *cache_level, *is_started; - zval *key = NULL, *view_options, *cache_options, *cached_view; - zval *is_fresh, *engine = NULL, *extension = NULL, *view_engine_path = NULL; - zval *event_name = NULL, *status = NULL, *exception_message; - zval *r0 = NULL; + zval *render_level, *cache_level, *enter_cache; + zval *is_started, *key = NULL, *view_options, *cache_options; + zval *cached_view, *is_fresh, *engine = NULL, *extension = NULL; + zval *view_engine_path = NULL, *event_name = NULL, *status = NULL; + zval *exception_message; HashTable *ah0; HashPosition hp0; zval **hd; @@ -42572,9 +42662,9 @@ PHP_METHOD(Phalcon_Mvc_View, _engineRender){ PHALCON_INIT_VAR(cache_level); phalcon_read_property(&cache_level, this_ptr, SL("_cacheLevel"), PH_NOISY_CC); - PHALCON_INIT_VAR(r0); - is_smaller_or_equal_function(r0, cache_level, render_level TSRMLS_CC); - if (zend_is_true(r0)) { + PHALCON_INIT_VAR(enter_cache); + is_smaller_or_equal_function(enter_cache, cache_level, render_level TSRMLS_CC); + if (zend_is_true(enter_cache)) { PHALCON_INIT_VAR(is_started); PHALCON_CALL_METHOD(is_started, cache, "isstarted", PH_NO_CHECK); if (PHALCON_IS_FALSE(is_started)) { @@ -42713,8 +42803,8 @@ PHP_METHOD(Phalcon_Mvc_View, registerEngines){ PHP_METHOD(Phalcon_Mvc_View, render){ zval *controller_name, *action_name, *params = NULL; - zval *layouts_dir = NULL, *engines, *pick_view, *render_view = NULL; - zval *render_controller = NULL, *pick_view_action; + zval *disabled, *layouts_dir = NULL, *engines, *pick_view; + zval *render_view = NULL, *render_controller = NULL, *pick_view_action; zval *cache = NULL, *cache_level, *events_manager, *event_name = NULL; zval *status, *contents, *must_clean, *silence = NULL; zval *render_level, *enter_level = NULL, *templates_before; @@ -42739,6 +42829,13 @@ PHP_METHOD(Phalcon_Mvc_View, render){ array_init(params); } + PHALCON_INIT_VAR(disabled); + phalcon_read_property(&disabled, this_ptr, SL("_disabled"), PH_NOISY_CC); + if (PHALCON_IS_NOT_FALSE(disabled)) { + PHALCON_MM_RESTORE(); + RETURN_FALSE; + } + PHALCON_INIT_VAR(layouts_dir); phalcon_read_property(&layouts_dir, this_ptr, SL("_layoutsDir"), PH_NOISY_CC); if (!zend_is_true(layouts_dir)) { @@ -42921,9 +43018,13 @@ PHP_METHOD(Phalcon_Mvc_View, render){ if (PHALCON_IS_TRUE(is_started)) { PHALCON_INIT_VAR(is_fresh); PHALCON_CALL_METHOD(is_fresh, cache, "isfresh", PH_NO_CHECK); - if (PHALCON_IS_TRUE(is_started)) { + if (PHALCON_IS_TRUE(is_fresh)) { PHALCON_CALL_METHOD_NORETURN(cache, "save", PH_NO_CHECK); + } else { + PHALCON_CALL_METHOD_NORETURN(cache, "stop", PH_NO_CHECK); } + } else { + PHALCON_CALL_METHOD_NORETURN(cache, "stop", PH_NO_CHECK); } } } @@ -43208,7 +43309,26 @@ PHP_METHOD(Phalcon_Mvc_View, getActiveRenderPath){ PHP_METHOD(Phalcon_Mvc_View, disable){ - phalcon_update_property_long(this_ptr, SL("_renderLevel"), 0 TSRMLS_CC); + phalcon_update_property_bool(this_ptr, SL("_disabled"), 1 TSRMLS_CC); + +} + +PHP_METHOD(Phalcon_Mvc_View, enable){ + + + phalcon_update_property_bool(this_ptr, SL("_disabled"), 0 TSRMLS_CC); + +} + +PHP_METHOD(Phalcon_Mvc_View, reset){ + + + phalcon_update_property_bool(this_ptr, SL("_disabled"), 0 TSRMLS_CC); + phalcon_update_property_bool(this_ptr, SL("_engines"), 0 TSRMLS_CC); + phalcon_update_property_null(this_ptr, SL("_cache") TSRMLS_CC); + phalcon_update_property_long(this_ptr, SL("_renderLevel"), 5 TSRMLS_CC); + phalcon_update_property_long(this_ptr, SL("_cacheLevel"), 0 TSRMLS_CC); + phalcon_update_property_null(this_ptr, SL("_content") TSRMLS_CC); } @@ -45958,6 +46078,11 @@ PHP_METHOD(Phalcon_Mvc_Model, _getOrCreateResultset){ PHALCON_INIT_VAR(resultset); PHALCON_CALL_METHOD_PARAMS_2(resultset, cache, "get", key, lifetime, PH_NO_CHECK); if (Z_TYPE_P(resultset) != IS_NULL) { + if (Z_TYPE_P(resultset) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "The cache didn't return a valid resultset"); + return; + } + PHALCON_INIT_VAR(is_fresh); ZVAL_BOOL(is_fresh, 0); PHALCON_CALL_METHOD_PARAMS_1_NORETURN(resultset, "setisfresh", is_fresh, PH_NO_CHECK); @@ -49312,7 +49437,7 @@ PHP_METHOD(Phalcon_Version, _getVersion){ array_init(version); add_next_index_long(version, 0); add_next_index_long(version, 6); - add_next_index_long(version, 0); + add_next_index_long(version, 1); add_next_index_long(version, 4); add_next_index_long(version, 0); @@ -52902,17 +53027,7 @@ PHP_METHOD(Phalcon_DI, _factory){ } } } else { - if (phalcon_is_callable(service TSRMLS_CC)) { - if (Z_TYPE_P(parameters) == IS_ARRAY) { - PHALCON_INIT_NVAR(instance); - PHALCON_CALL_USER_FUNC_ARRAY(instance, service, parameters); - } else { - PHALCON_INIT_NVAR(instance); - PHALCON_CALL_USER_FUNC(instance, service); - } - } else { - ZVAL_BOOL(found, 0); - } + ZVAL_BOOL(found, 0); } } else { if (Z_TYPE_P(service) == IS_OBJECT) { @@ -56036,6 +56151,7 @@ PHP_MINIT_FUNCTION(phalcon){ zend_declare_class_constant_long(phalcon_db_ce, SL("FETCH_ASSOC"), 1 TSRMLS_CC); zend_declare_class_constant_long(phalcon_db_ce, SL("FETCH_BOTH"), 2 TSRMLS_CC); zend_declare_class_constant_long(phalcon_db_ce, SL("FETCH_NUM"), 3 TSRMLS_CC); + zend_declare_class_constant_long(phalcon_db_ce, SL("FETCH_OBJ"), 4 TSRMLS_CC); PHALCON_REGISTER_CLASS(Phalcon, Logger, logger, phalcon_logger_method_entry, ZEND_ACC_EXPLICIT_ABSTRACT_CLASS); zend_declare_class_constant_long(phalcon_logger_ce, SL("SPECIAL"), 9 TSRMLS_CC); @@ -56327,6 +56443,7 @@ PHP_MINIT_FUNCTION(phalcon){ zend_declare_property_null(phalcon_mvc_view_ce, SL("_cache"), ZEND_ACC_PROTECTED TSRMLS_CC); zend_declare_property_long(phalcon_mvc_view_ce, SL("_cacheLevel"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); zend_declare_property_null(phalcon_mvc_view_ce, SL("_activeRenderPath"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_bool(phalcon_mvc_view_ce, SL("_disabled"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); zend_declare_class_constant_long(phalcon_mvc_view_ce, SL("LEVEL_MAIN_LAYOUT"), 5 TSRMLS_CC); zend_declare_class_constant_long(phalcon_mvc_view_ce, SL("LEVEL_AFTER_TEMPLATE"), 4 TSRMLS_CC); zend_declare_class_constant_long(phalcon_mvc_view_ce, SL("LEVEL_LAYOUT"), 3 TSRMLS_CC); diff --git a/build/phalcon.h b/build/phalcon.h index 441afd409f3..faa56f9bf84 100644 --- a/build/phalcon.h +++ b/build/phalcon.h @@ -200,7 +200,6 @@ PHP_METHOD(Phalcon_DI, reset); PHP_METHOD(Phalcon_Text, camelize); PHP_METHOD(Phalcon_Text, uncamelize); -PHP_METHOD(Phalcon_Text, x); PHP_METHOD(Phalcon_Mvc_Router_Route, __construct); @@ -303,6 +302,8 @@ PHP_METHOD(Phalcon_Mvc_View, setContent); PHP_METHOD(Phalcon_Mvc_View, getContent); PHP_METHOD(Phalcon_Mvc_View, getActiveRenderPath); PHP_METHOD(Phalcon_Mvc_View, disable); +PHP_METHOD(Phalcon_Mvc_View, enable); +PHP_METHOD(Phalcon_Mvc_View, reset); PHP_METHOD(Phalcon_Mvc_Collection, __construct); PHP_METHOD(Phalcon_Mvc_Collection, setId); @@ -752,6 +753,7 @@ PHP_METHOD(Phalcon_Cache_Frontend_Data, afterRetrieve); PHP_METHOD(Phalcon_Cache_Backend, __construct); PHP_METHOD(Phalcon_Cache_Backend, start); +PHP_METHOD(Phalcon_Cache_Backend, stop); PHP_METHOD(Phalcon_Cache_Backend, getFrontend); PHP_METHOD(Phalcon_Cache_Backend, isFresh); PHP_METHOD(Phalcon_Cache_Backend, isStarted); @@ -961,6 +963,7 @@ PHP_METHOD(Phalcon_Db_Index, __set_state); PHP_METHOD(Phalcon_Db_Result_Pdo, __construct); PHP_METHOD(Phalcon_Db_Result_Pdo, execute); +PHP_METHOD(Phalcon_Db_Result_Pdo, fetch); PHP_METHOD(Phalcon_Db_Result_Pdo, fetchArray); PHP_METHOD(Phalcon_Db_Result_Pdo, fetchAll); PHP_METHOD(Phalcon_Db_Result_Pdo, numRows); @@ -1166,6 +1169,7 @@ PHP_METHOD(Phalcon_Flash, warning); PHP_METHOD(Phalcon_Flash, outputMessage); PHP_METHOD(Phalcon_Config, __construct); +PHP_METHOD(Phalcon_Config, __set_state); PHP_METHOD(Phalcon_Filter, __construct); PHP_METHOD(Phalcon_Filter, add); @@ -1368,11 +1372,6 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_text_uncamelize, 0, 0, 1) ZEND_ARG_INFO(0, str) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_text_x, 0, 0, 2) - ZEND_ARG_INFO(0, a) - ZEND_ARG_INFO(0, b) -ZEND_END_ARG_INFO() - ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_mvc_router_route___construct, 0, 0, 1) ZEND_ARG_INFO(0, pattern) ZEND_ARG_INFO(0, paths) @@ -2516,6 +2515,10 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_cache_backend_start, 0, 0, 1) ZEND_ARG_INFO(0, keyName) ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_cache_backend_stop, 0, 0, 0) + ZEND_ARG_INFO(0, stopBuffer) +ZEND_END_ARG_INFO() + ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_cache_backend_mongo___construct, 0, 0, 1) ZEND_ARG_INFO(0, frontendObject) ZEND_ARG_INFO(0, backendOptions) @@ -3446,6 +3449,10 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_config___construct, 0, 0, 0) ZEND_ARG_INFO(0, arrayConfig) ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_config___set_state, 0, 0, 1) + ZEND_ARG_INFO(0, data) +ZEND_END_ARG_INFO() + ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_filter_add, 0, 0, 2) ZEND_ARG_INFO(0, name) ZEND_ARG_INFO(0, handler) @@ -3675,7 +3682,6 @@ PHALCON_INIT_FUNCS(phalcon_di_method_entry){ PHALCON_INIT_FUNCS(phalcon_text_method_entry){ PHP_ME(Phalcon_Text, camelize, arginfo_phalcon_text_camelize, ZEND_ACC_STATIC|ZEND_ACC_PUBLIC) PHP_ME(Phalcon_Text, uncamelize, arginfo_phalcon_text_uncamelize, ZEND_ACC_STATIC|ZEND_ACC_PUBLIC) - PHP_ME(Phalcon_Text, x, arginfo_phalcon_text_x, ZEND_ACC_STATIC|ZEND_ACC_PUBLIC) PHP_FE_END }; @@ -3790,6 +3796,8 @@ PHALCON_INIT_FUNCS(phalcon_mvc_view_method_entry){ PHP_ME(Phalcon_Mvc_View, getContent, NULL, ZEND_ACC_PUBLIC) PHP_ME(Phalcon_Mvc_View, getActiveRenderPath, NULL, ZEND_ACC_PUBLIC) PHP_ME(Phalcon_Mvc_View, disable, NULL, ZEND_ACC_PUBLIC) + PHP_ME(Phalcon_Mvc_View, enable, NULL, ZEND_ACC_PUBLIC) + PHP_ME(Phalcon_Mvc_View, reset, NULL, ZEND_ACC_PUBLIC) PHP_FE_END }; @@ -4362,6 +4370,7 @@ PHALCON_INIT_FUNCS(phalcon_cache_frontend_data_method_entry){ PHALCON_INIT_FUNCS(phalcon_cache_backend_method_entry){ PHP_ME(Phalcon_Cache_Backend, __construct, arginfo_phalcon_cache_backend___construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR) PHP_ME(Phalcon_Cache_Backend, start, arginfo_phalcon_cache_backend_start, ZEND_ACC_PUBLIC) + PHP_ME(Phalcon_Cache_Backend, stop, arginfo_phalcon_cache_backend_stop, ZEND_ACC_PUBLIC) PHP_ME(Phalcon_Cache_Backend, getFrontend, NULL, ZEND_ACC_PUBLIC) PHP_ME(Phalcon_Cache_Backend, isFresh, NULL, ZEND_ACC_PUBLIC) PHP_ME(Phalcon_Cache_Backend, isStarted, NULL, ZEND_ACC_PUBLIC) @@ -4642,6 +4651,7 @@ PHALCON_INIT_FUNCS(phalcon_db_index_method_entry){ PHALCON_INIT_FUNCS(phalcon_db_result_pdo_method_entry){ PHP_ME(Phalcon_Db_Result_Pdo, __construct, arginfo_phalcon_db_result_pdo___construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR) PHP_ME(Phalcon_Db_Result_Pdo, execute, NULL, ZEND_ACC_PUBLIC) + PHP_ME(Phalcon_Db_Result_Pdo, fetch, NULL, ZEND_ACC_PUBLIC) PHP_ME(Phalcon_Db_Result_Pdo, fetchArray, NULL, ZEND_ACC_PUBLIC) PHP_ME(Phalcon_Db_Result_Pdo, fetchAll, NULL, ZEND_ACC_PUBLIC) PHP_ME(Phalcon_Db_Result_Pdo, numRows, NULL, ZEND_ACC_PUBLIC) @@ -4881,6 +4891,7 @@ PHALCON_INIT_FUNCS(phalcon_flash_method_entry){ PHALCON_INIT_FUNCS(phalcon_config_method_entry){ PHP_ME(Phalcon_Config, __construct, arginfo_phalcon_config___construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR) + PHP_ME(Phalcon_Config, __set_state, arginfo_phalcon_config___set_state, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) PHP_FE_END }; diff --git a/ext/cache/backend.c b/ext/cache/backend.c index f42d4a2b6f5..eac0273846a 100755 --- a/ext/cache/backend.c +++ b/ext/cache/backend.c @@ -36,6 +36,7 @@ #include "kernel/array.h" #include "kernel/object.h" #include "kernel/fcall.h" +#include "kernel/operators.h" /** * Phalcon\Cache\Backend @@ -91,7 +92,7 @@ PHP_METHOD(Phalcon_Cache_Backend, __construct){ } /** - * Starts a cache. The $keyname allow to identify the created fragment + * Starts a cache. The $keyname allows to identify the created fragment * * @param int|string $keyName * @return mixed @@ -131,6 +132,38 @@ PHP_METHOD(Phalcon_Cache_Backend, start){ RETURN_CCTOR(existing_cache); } +/** + * Stops the frontend without store any cached content + * + * @param boolean $stopBuffer + */ +PHP_METHOD(Phalcon_Cache_Backend, stop){ + + zval *stop_buffer = NULL, *front_end; + + PHALCON_MM_GROW(); + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|z", &stop_buffer) == FAILURE) { + PHALCON_MM_RESTORE(); + RETURN_NULL(); + } + + if (!stop_buffer) { + PHALCON_INIT_NVAR(stop_buffer); + ZVAL_BOOL(stop_buffer, 1); + } + + PHALCON_INIT_VAR(front_end); + phalcon_read_property(&front_end, this_ptr, SL("_frontendObject"), PH_NOISY_CC); + if (PHALCON_IS_TRUE(stop_buffer)) { + PHALCON_CALL_METHOD_NORETURN(front_end, "stop", PH_NO_CHECK); + } + + phalcon_update_property_bool(this_ptr, SL("_started"), 0 TSRMLS_CC); + + PHALCON_MM_RESTORE(); +} + /** * Returns front-end instance adapter related to the back-end * @@ -166,7 +199,7 @@ PHP_METHOD(Phalcon_Cache_Backend, isFresh){ } /** - * Checks whether the cache has started buffering or not + * Checks whether the cache has starting buffering or not * * @return boolean */ diff --git a/ext/cache/backend/apc.c b/ext/cache/backend/apc.c index d7da92616c6..2815ed1d0a2 100644 --- a/ext/cache/backend/apc.c +++ b/ext/cache/backend/apc.c @@ -119,7 +119,7 @@ PHP_METHOD(Phalcon_Cache_Backend_Apc, get){ } /** - * Stores cached content into the file backend + * Stores cached content into the APC backend and stops the frontend * * @param string $keyName * @param string $content diff --git a/ext/cache/backend/file.c b/ext/cache/backend/file.c index d1408b0f245..9b548640b95 100644 --- a/ext/cache/backend/file.c +++ b/ext/cache/backend/file.c @@ -195,7 +195,7 @@ PHP_METHOD(Phalcon_Cache_Backend_File, get){ } /** - * Stores cached content into the file backend + * Stores cached content into the file backend and stops the frontend * * @param int|string $keyName * @param string $content diff --git a/ext/cache/backend/memcache.c b/ext/cache/backend/memcache.c index abf7a1111ee..2c399bc0429 100644 --- a/ext/cache/backend/memcache.c +++ b/ext/cache/backend/memcache.c @@ -225,7 +225,7 @@ PHP_METHOD(Phalcon_Cache_Backend_Memcache, get){ } /** - * Stores cached content into the Memcached backend + * Stores cached content into the Memcached backend and stops the frontend * * @param int|string $keyName * @param string $content diff --git a/ext/cache/backend/mongo.c b/ext/cache/backend/mongo.c index 118c0e24ef2..fbc39b066d8 100644 --- a/ext/cache/backend/mongo.c +++ b/ext/cache/backend/mongo.c @@ -274,7 +274,7 @@ PHP_METHOD(Phalcon_Cache_Backend_Mongo, get){ } /** - * Stores cached content into the Mongo backend + * Stores cached content into the Mongo backend and stops the frontend * * @param int|string $keyName * @param string $content diff --git a/ext/cache/frontend/base64.c b/ext/cache/frontend/base64.c index 9b0cc8956fc..22c3287278c 100644 --- a/ext/cache/frontend/base64.c +++ b/ext/cache/frontend/base64.c @@ -103,7 +103,7 @@ PHP_METHOD(Phalcon_Cache_Frontend_Base64, __construct){ } /** - * Returns cache lifetime + * Returns the cache lifetime * * @return integer */ diff --git a/ext/config.c b/ext/config.c index 1fdcda2de7a..8664eed634b 100755 --- a/ext/config.c +++ b/ext/config.c @@ -32,6 +32,7 @@ #include "kernel/main.h" #include "kernel/memory.h" +#include "kernel/array.h" #include "kernel/fcall.h" #include "kernel/object.h" #include "kernel/exception.h" @@ -65,7 +66,6 @@ * Phalcon\Config constructor * * @param array $arrayConfig - * @return Phalcon\Config */ PHP_METHOD(Phalcon_Config, __construct){ @@ -77,6 +77,7 @@ PHP_METHOD(Phalcon_Config, __construct){ uint hash_index_len; ulong hash_num; int hash_type; + int eval_int; PHALCON_MM_GROW(); @@ -109,10 +110,15 @@ PHP_METHOD(Phalcon_Config, __construct){ PHALCON_GET_FOREACH_VALUE(value); if (Z_TYPE_P(value) == IS_ARRAY) { - PHALCON_INIT_NVAR(config_value); - object_init_ex(config_value, phalcon_config_ce); - PHALCON_CALL_METHOD_PARAMS_1_NORETURN(config_value, "__construct", value, PH_CHECK); - phalcon_update_property_zval_zval(this_ptr, key, config_value TSRMLS_CC); + eval_int = phalcon_array_isset_long(value, 0); + if (!eval_int) { + PHALCON_INIT_NVAR(config_value); + object_init_ex(config_value, phalcon_config_ce); + PHALCON_CALL_METHOD_PARAMS_1_NORETURN(config_value, "__construct", value, PH_CHECK); + phalcon_update_property_zval_zval(this_ptr, key, config_value TSRMLS_CC); + } else { + phalcon_update_property_zval_zval(this_ptr, key, value TSRMLS_CC); + } } else { phalcon_update_property_zval_zval(this_ptr, key, value TSRMLS_CC); } @@ -131,3 +137,26 @@ PHP_METHOD(Phalcon_Config, __construct){ PHALCON_MM_RESTORE(); } +/** + * Restores the state of a Phalcon\Config object + * + * @return Phalcon\Config + */ +PHP_METHOD(Phalcon_Config, __set_state){ + + zval *data, *config; + + PHALCON_MM_GROW(); + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &data) == FAILURE) { + PHALCON_MM_RESTORE(); + RETURN_NULL(); + } + + PHALCON_INIT_VAR(config); + object_init_ex(config, phalcon_config_ce); + PHALCON_CALL_METHOD_PARAMS_1_NORETURN(config, "__construct", data, PH_CHECK); + + RETURN_CTOR(config); +} + diff --git a/ext/config/adapter/ini.c b/ext/config/adapter/ini.c index ba805c41314..6618c8b1431 100755 --- a/ext/config/adapter/ini.c +++ b/ext/config/adapter/ini.c @@ -75,7 +75,6 @@ * Phalcon\Config\Adapter\Ini constructor * * @param string $filePath - * @return Phalcon\Config\Adapter\Ini */ PHP_METHOD(Phalcon_Config_Adapter_Ini, __construct){ diff --git a/ext/db.c b/ext/db.c index 55be9937b72..532eb4f8550 100755 --- a/ext/db.c +++ b/ext/db.c @@ -67,7 +67,7 @@ * * $result = $connection->query("SELECT * FROM robots LIMIT 5"); * $result->setFetchMode(Phalcon\Db::FETCH_NUM); - * while($robot = $result->fetchArray()){ + * while($robot = $result->fetch()){ * print_r($robot); * } * @@ -797,7 +797,7 @@ PHP_METHOD(Phalcon_Db, sharedLock){ } /** - * Creates a table using MySQL SQL + * Creates a table * * @param string $tableName * @param string $schemaName @@ -987,7 +987,7 @@ PHP_METHOD(Phalcon_Db, dropColumn){ * * @param string $tableName * @param string $schemaName - * @param DbIndex $index + * @param Phalcon\Db\Index $index * @return boolean */ PHP_METHOD(Phalcon_Db, addIndex){ diff --git a/ext/db/result/pdo.c b/ext/db/result/pdo.c index e7f96e7f400..6043ab719e8 100644 --- a/ext/db/result/pdo.c +++ b/ext/db/result/pdo.c @@ -130,6 +130,35 @@ PHP_METHOD(Phalcon_Db_Result_Pdo, execute){ RETURN_CCTOR(status); } +/** + * Fetches an array/object of strings that corresponds to the fetched row, or FALSE if there are no more rows. + * This method is affected by the active fetch flag set using Phalcon\Db\Result\Pdo::setFetchMode + * + * + * $result = $connection->query("SELECT * FROM robots ORDER BY name"); + * $result->setFetchMode(Phalcon\Db::FETCH_OBJ); + * while($robot = $result->fetch()){ + * echo $robot->name; + * } + * + * + * @return mixed + */ +PHP_METHOD(Phalcon_Db_Result_Pdo, fetch){ + + zval *pdo_statement, *row; + + PHALCON_MM_GROW(); + + PHALCON_INIT_VAR(pdo_statement); + phalcon_read_property(&pdo_statement, this_ptr, SL("_pdoStatement"), PH_NOISY_CC); + + PHALCON_INIT_VAR(row); + PHALCON_CALL_METHOD(row, pdo_statement, "fetch", PH_NO_CHECK); + + RETURN_CCTOR(row); +} + /** * Returns an array of strings that corresponds to the fetched row, or FALSE if there are no more rows. * This method is affected by the active fetch flag set using Phalcon\Db\Result\Pdo::setFetchMode @@ -142,7 +171,7 @@ PHP_METHOD(Phalcon_Db_Result_Pdo, execute){ * } * * - * @return boolean + * @return mixed */ PHP_METHOD(Phalcon_Db_Result_Pdo, fetchArray){ @@ -245,7 +274,7 @@ PHP_METHOD(Phalcon_Db_Result_Pdo, numRows){ PHALCON_CALL_METHOD_PARAMS_3(result, connection, "query", sql, bind_params, bind_types, PH_NO_CHECK); PHALCON_INIT_VAR(row); - PHALCON_CALL_METHOD(row, result, "fetcharray", PH_NO_CHECK); + PHALCON_CALL_METHOD(row, result, "fetch", PH_NO_CHECK); PHALCON_INIT_NVAR(row_count); phalcon_array_fetch_long(&row_count, row, 0, PH_NOISY_CC); @@ -271,7 +300,7 @@ PHP_METHOD(Phalcon_Db_Result_Pdo, numRows){ * * $result = $connection->query("SELECT * FROM robots ORDER BY name"); * $result->dataSeek(2); // Move to third row on result - * $row = $result->fetchArray(); // Fetch third row + * $row = $result->fetch(); // Fetch third row * * * @param int $number @@ -320,7 +349,7 @@ PHP_METHOD(Phalcon_Db_Result_Pdo, dataSeek){ } /** - * Changes the fetching mode affecting Phalcon\Db\Result\Pdo::fetchArray + * Changes the fetching mode affecting Phalcon\Db\Result\Pdo::fetch() * * * //Return array with integer indexes @@ -331,6 +360,9 @@ PHP_METHOD(Phalcon_Db_Result_Pdo, dataSeek){ * * //Return associative array together with integer indexes * $result->setFetchMode(Phalcon\Db::FETCH_BOTH); + * + * //Return an object + * $result->setFetchMode(Phalcon\Db::FETCH_OBJ); * * * @param int $fetchMode @@ -338,7 +370,7 @@ PHP_METHOD(Phalcon_Db_Result_Pdo, dataSeek){ PHP_METHOD(Phalcon_Db_Result_Pdo, setFetchMode){ long fetch_mode; - zval *pdo_statement = NULL, *fetch_type = NULL; + zval *pdo_statement, *fetch_type; PHALCON_MM_GROW(); @@ -365,6 +397,12 @@ PHP_METHOD(Phalcon_Db_Result_Pdo, setFetchMode){ ZVAL_LONG(fetch_type, 3); PHALCON_CALL_METHOD_PARAMS_1_NORETURN(pdo_statement, "setfetchmode", fetch_type, PH_NO_CHECK); phalcon_update_property_long(this_ptr, SL("_fetchMode"), 3 TSRMLS_CC); + } else { + if (fetch_mode == 4) { + ZVAL_LONG(fetch_type, 5); + PHALCON_CALL_METHOD_PARAMS_1_NORETURN(pdo_statement, "setfetchmode", fetch_type, PH_NO_CHECK); + phalcon_update_property_long(this_ptr, SL("_fetchMode"), 5 TSRMLS_CC); + } } } } diff --git a/ext/di.c b/ext/di.c index b8d1f853138..1ef688aad1c 100644 --- a/ext/di.c +++ b/ext/di.c @@ -218,17 +218,7 @@ PHP_METHOD(Phalcon_DI, _factory){ } } } else { - if (phalcon_is_callable(service TSRMLS_CC)) { - if (Z_TYPE_P(parameters) == IS_ARRAY) { - PHALCON_INIT_NVAR(instance); - PHALCON_CALL_USER_FUNC_ARRAY(instance, service, parameters); - } else { - PHALCON_INIT_NVAR(instance); - PHALCON_CALL_USER_FUNC(instance, service); - } - } else { - ZVAL_BOOL(found, 0); - } + ZVAL_BOOL(found, 0); } } else { if (Z_TYPE_P(service) == IS_OBJECT) { diff --git a/ext/kernel/string.c b/ext/kernel/string.c index 4d3909904fa..0290786d3fe 100644 --- a/ext/kernel/string.c +++ b/ext/kernel/string.c @@ -448,4 +448,120 @@ void phalcon_fast_str_replace(zval *return_value, zval *search, zval *replace, z zval_dtor(search); } +} + +/** + * Extracts parameters from a string + * An initialized zval array must be passed as second parameter + */ +void phalcon_extract_named_params(zval *return_value, zval *str, zval *matches){ + + unsigned int i, j, bracket_count = 0; + unsigned int intermediate, length, number_matches = 0; + int variable_length, regexp_length, not_valid; + char *cursor, *cursor_var, *marker, ch; + char *item, *variable = NULL, *regexp; + smart_str route_str = {0}; + + if (Z_TYPE_P(str) != IS_STRING) { + ZVAL_BOOL(return_value, 0); + return; + } + + if (Z_STRLEN_P(str) <= 0) { + ZVAL_BOOL(return_value, 0); + return; + } + + cursor = Z_STRVAL_P(str); + for (i = 0; i 0) { + if (bracket_count == 0) { + + number_matches++; + + length = cursor - marker - 1; + item = estrndup(marker + 1, length); + cursor_var = item; + marker = item; + for (j=0; j= 'a' && ch <='z') || (ch >= 'A' && ch <='Z'))){ + not_valid = 1; + break; + } + if ((ch >= 'a' && ch <='z') || (ch >= 'A' && ch <='Z') || (ch >= '0' && ch <='9') || ch == ':') { + if (ch == ':') { + regexp_length = length - j - 1; + variable_length = cursor_var - marker; + variable = estrndup(marker, variable_length); + regexp = estrndup(cursor_var+1, regexp_length); + break; + } + } else { + not_valid = 1; + break; + } + cursor_var++; + } + + if (!not_valid) { + { + zval *tmp; + ALLOC_INIT_ZVAL(tmp); + ZVAL_LONG(tmp, number_matches); + + if (variable) { + smart_str_appendc(&route_str, '('); + smart_str_appendl(&route_str, regexp, regexp_length); + smart_str_appendc(&route_str, ')'); + zend_hash_update(Z_ARRVAL_P(matches), variable, variable_length+1, &tmp, sizeof(zval *), NULL); + efree(regexp); + efree(variable); + } else { + smart_str_appendl(&route_str, "([^/]*)", strlen("([^/]*)")); + zend_hash_update(Z_ARRVAL_P(matches), item, length+1, &tmp, sizeof(zval *), NULL); + } + } + } else { + smart_str_appendc(&route_str, '{'); + smart_str_appendl(&route_str, item, length); + smart_str_appendc(&route_str, '}'); + } + + efree(item); + + } + variable = NULL; + } + } else { + if (bracket_count > 0) { + intermediate++; + } else { + smart_str_appendc(&route_str, ch); + } + } + } + cursor++; + } + smart_str_0(&route_str); + + if (route_str.len) { + RETURN_STRINGL(route_str.c, route_str.len, 0); + } else { + smart_str_free(&route_str); + RETURN_EMPTY_STRING(); + } + } \ No newline at end of file diff --git a/ext/kernel/string.h b/ext/kernel/string.h index e8454fa3ddb..8ce52f8acd9 100644 --- a/ext/kernel/string.h +++ b/ext/kernel/string.h @@ -34,3 +34,6 @@ extern void phalcon_fast_str_replace(zval *return_value, zval *search, zval *rep /** Camelize/Uncamelize */ extern void phalcon_camelize(zval *return_value, zval *str TSRMLS_DC); extern void phalcon_uncamelize(zval *return_value, zval *str TSRMLS_DC); + +/** Extract named parameters */ +extern void phalcon_extract_named_params(zval *return_value, zval *str, zval *matches); diff --git a/ext/mvc/micro.c b/ext/mvc/micro.c index 8043364b218..a767422b262 100644 --- a/ext/mvc/micro.c +++ b/ext/mvc/micro.c @@ -38,7 +38,6 @@ #include "kernel/object.h" #include "kernel/array.h" #include "kernel/operators.h" -#include "kernel/file.h" /** * Phalcon\Mvc\Micro @@ -530,6 +529,7 @@ PHP_METHOD(Phalcon_Mvc_Micro, handle){ zval *event_name = NULL, *status = NULL, *service, *router, *matched_route; zval *handlers, *route_id, *handler = NULL, *params, *returned_value = NULL; zval *not_found_handler; + zval *r0 = NULL; int eval_int; PHALCON_MM_GROW(); @@ -621,7 +621,10 @@ PHP_METHOD(Phalcon_Mvc_Micro, handle){ PHALCON_INIT_VAR(not_found_handler); phalcon_read_property(¬_found_handler, this_ptr, SL("_notFoundHandler"), PH_NOISY_CC); - if (phalcon_is_callable(not_found_handler TSRMLS_CC)) { + + PHALCON_INIT_VAR(r0); + PHALCON_CALL_FUNC_PARAMS_1(r0, "is_callable", not_found_handler); + if (!zend_is_true(r0)) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_micro_exception_ce, "The Not-Found handler is not callable or is not defined"); return; } diff --git a/ext/mvc/model.c b/ext/mvc/model.c index c9e00c836ba..c303fbe33ea 100755 --- a/ext/mvc/model.c +++ b/ext/mvc/model.c @@ -459,6 +459,11 @@ PHP_METHOD(Phalcon_Mvc_Model, _getOrCreateResultset){ PHALCON_INIT_VAR(resultset); PHALCON_CALL_METHOD_PARAMS_2(resultset, cache, "get", key, lifetime, PH_NO_CHECK); if (Z_TYPE_P(resultset) != IS_NULL) { + if (Z_TYPE_P(resultset) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "The cache didn't return a valid resultset"); + return; + } + PHALCON_INIT_VAR(is_fresh); ZVAL_BOOL(is_fresh, 0); PHALCON_CALL_METHOD_PARAMS_1_NORETURN(resultset, "setisfresh", is_fresh, PH_NO_CHECK); diff --git a/ext/mvc/router/route.c b/ext/mvc/router/route.c index c4f4460e6bb..d3ee54cda37 100644 --- a/ext/mvc/router/route.c +++ b/ext/mvc/router/route.c @@ -209,17 +209,8 @@ PHP_METHOD(Phalcon_Mvc_Router_Route, reConfigure){ zval *pattern, *paths = NULL, *double_colon, *parts, *part_zero; zval *controller_name, *route_paths = NULL, *part_one; - zval *one, *zero, *first, *have_bracket, *sharp, *escaped_sharp; - zval *pcre_pattern = NULL, *matches, *match_position; - zval *set_order, *names_pattern, *have_variables = NULL; - zval *match = NULL, *match_zero = NULL, *match_one = NULL, *match_two = NULL; - zval *replace_pattern = NULL, *new_pcre_pattern = NULL; + zval *one, *zero, *first, *have_bracket, *pcre_pattern = NULL; zval *compiled_pattern = NULL; - zval *r0 = NULL; - zval *p0[] = { NULL, NULL, NULL, NULL }; - HashTable *ah0; - HashPosition hp0; - zval **hd; int eval_int; PHALCON_MM_GROW(); @@ -280,83 +271,8 @@ PHP_METHOD(Phalcon_Mvc_Router_Route, reConfigure){ PHALCON_INIT_VAR(have_bracket); phalcon_fast_strpos_str(have_bracket, pattern, SL("{") TSRMLS_CC); if (PHALCON_IS_NOT_FALSE(have_bracket)) { - PHALCON_INIT_VAR(sharp); - ZVAL_STRING(sharp, "#", 1); - - PHALCON_INIT_VAR(escaped_sharp); - ZVAL_STRING(escaped_sharp, "\\#", 1); - PHALCON_INIT_VAR(pcre_pattern); - phalcon_fast_str_replace(pcre_pattern, sharp, escaped_sharp, pattern TSRMLS_CC); - - PHALCON_INIT_VAR(matches); - - PHALCON_INIT_VAR(match_position); - ZVAL_LONG(match_position, 1); - - PHALCON_INIT_VAR(set_order); - ZVAL_LONG(set_order, 2); - - PHALCON_INIT_VAR(names_pattern); - ZVAL_STRING(names_pattern, "#{([a-zA-Z][a-zA-Z0-9\\_\\-]*)(:([^}]+))*}#", 1); - p0[0] = names_pattern; - p0[1] = pcre_pattern; - Z_SET_ISREF_P(matches); - p0[2] = matches; - p0[3] = set_order; - - PHALCON_INIT_VAR(r0); - PHALCON_CALL_FUNC_PARAMS(r0, "preg_match_all", 4, p0); - Z_UNSET_ISREF_P(p0[2]); - PHALCON_CPY_WRT(have_variables, r0); - 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); - - 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(match); - - PHALCON_INIT_NVAR(match_zero); - phalcon_array_fetch_long(&match_zero, match, 0, PH_NOISY_CC); - - PHALCON_INIT_NVAR(match_one); - phalcon_array_fetch_long(&match_one, match, 1, PH_NOISY_CC); - eval_int = phalcon_array_isset_long(match, 3); - if (eval_int) { - PHALCON_INIT_NVAR(match_two); - phalcon_array_fetch_long(&match_two, match, 3, PH_NOISY_CC); - - PHALCON_INIT_NVAR(replace_pattern); - PHALCON_CONCAT_SVS(replace_pattern, "(", match_two, ")"); - } else { - PHALCON_INIT_NVAR(replace_pattern); - ZVAL_STRING(replace_pattern, "([^/]*)", 1); - } - - PHALCON_INIT_NVAR(new_pcre_pattern); - phalcon_fast_str_replace(new_pcre_pattern, match_zero, replace_pattern, pcre_pattern TSRMLS_CC); - PHALCON_CPY_WRT(pcre_pattern, new_pcre_pattern); - phalcon_array_update_zval(&route_paths, match_one, &match_position, PH_COPY | PH_SEPARATE TSRMLS_CC); - PHALCON_SEPARATE(match_position); - increment_function(match_position); - - zend_hash_move_forward_ex(ah0, &hp0); - goto ph_cycle_start_0; - - ph_cycle_end_0: - if(0){} - - } + phalcon_extract_named_params(pcre_pattern, pattern, route_paths); } else { PHALCON_CPY_WRT(pcre_pattern, pattern); } diff --git a/ext/mvc/url.c b/ext/mvc/url.c index a4a8e44c962..64fb02b4e12 100755 --- a/ext/mvc/url.c +++ b/ext/mvc/url.c @@ -327,7 +327,7 @@ PHP_METHOD(Phalcon_Mvc_Url, get){ ZVAL_LONG(set_order, 2); PHALCON_INIT_VAR(names_pattern); - ZVAL_STRING(names_pattern, "#{([a-zA-Z][a-zA-Z0-9\\_\\-]+)(:([^}]+))*}#", 1); + 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); diff --git a/ext/mvc/view.c b/ext/mvc/view.c index 67dfd367f9b..e0ba40fba56 100755 --- a/ext/mvc/view.c +++ b/ext/mvc/view.c @@ -515,11 +515,11 @@ PHP_METHOD(Phalcon_Mvc_View, _engineRender){ zval *engines, *view_path, *silence, *must_clean; zval *cache, *not_exists = NULL, *view_params, *views_dir; zval *base_path, *views_dir_path, *events_manager; - zval *render_level, *cache_level, *is_started; - zval *key = NULL, *view_options, *cache_options, *cached_view; - zval *is_fresh, *engine = NULL, *extension = NULL, *view_engine_path = NULL; - zval *event_name = NULL, *status = NULL, *exception_message; - zval *r0 = NULL; + zval *render_level, *cache_level, *enter_cache; + zval *is_started, *key = NULL, *view_options, *cache_options; + zval *cached_view, *is_fresh, *engine = NULL, *extension = NULL; + zval *view_engine_path = NULL, *event_name = NULL, *status = NULL; + zval *exception_message; HashTable *ah0; HashPosition hp0; zval **hd; @@ -560,9 +560,9 @@ PHP_METHOD(Phalcon_Mvc_View, _engineRender){ PHALCON_INIT_VAR(cache_level); phalcon_read_property(&cache_level, this_ptr, SL("_cacheLevel"), PH_NOISY_CC); - PHALCON_INIT_VAR(r0); - is_smaller_or_equal_function(r0, cache_level, render_level TSRMLS_CC); - if (zend_is_true(r0)) { + PHALCON_INIT_VAR(enter_cache); + is_smaller_or_equal_function(enter_cache, cache_level, render_level TSRMLS_CC); + if (zend_is_true(enter_cache)) { PHALCON_INIT_VAR(is_started); PHALCON_CALL_METHOD(is_started, cache, "isstarted", PH_NO_CHECK); if (PHALCON_IS_FALSE(is_started)) { @@ -728,8 +728,8 @@ PHP_METHOD(Phalcon_Mvc_View, registerEngines){ PHP_METHOD(Phalcon_Mvc_View, render){ zval *controller_name, *action_name, *params = NULL; - zval *layouts_dir = NULL, *engines, *pick_view, *render_view = NULL; - zval *render_controller = NULL, *pick_view_action; + zval *disabled, *layouts_dir = NULL, *engines, *pick_view; + zval *render_view = NULL, *render_controller = NULL, *pick_view_action; zval *cache = NULL, *cache_level, *events_manager, *event_name = NULL; zval *status, *contents, *must_clean, *silence = NULL; zval *render_level, *enter_level = NULL, *templates_before; @@ -754,6 +754,13 @@ PHP_METHOD(Phalcon_Mvc_View, render){ array_init(params); } + PHALCON_INIT_VAR(disabled); + phalcon_read_property(&disabled, this_ptr, SL("_disabled"), PH_NOISY_CC); + if (PHALCON_IS_NOT_FALSE(disabled)) { + PHALCON_MM_RESTORE(); + RETURN_FALSE; + } + PHALCON_INIT_VAR(layouts_dir); phalcon_read_property(&layouts_dir, this_ptr, SL("_layoutsDir"), PH_NOISY_CC); if (!zend_is_true(layouts_dir)) { @@ -936,9 +943,13 @@ PHP_METHOD(Phalcon_Mvc_View, render){ if (PHALCON_IS_TRUE(is_started)) { PHALCON_INIT_VAR(is_fresh); PHALCON_CALL_METHOD(is_fresh, cache, "isfresh", PH_NO_CHECK); - if (PHALCON_IS_TRUE(is_started)) { + if (PHALCON_IS_TRUE(is_fresh)) { PHALCON_CALL_METHOD_NORETURN(cache, "save", PH_NO_CHECK); + } else { + PHALCON_CALL_METHOD_NORETURN(cache, "stop", PH_NO_CHECK); } + } else { + PHALCON_CALL_METHOD_NORETURN(cache, "stop", PH_NO_CHECK); } } } @@ -1289,13 +1300,40 @@ PHP_METHOD(Phalcon_Mvc_View, getActiveRenderPath){ } /** - * Disable view. Don't show any view or template + * Disables the auto-rendering process * */ PHP_METHOD(Phalcon_Mvc_View, disable){ - phalcon_update_property_long(this_ptr, SL("_renderLevel"), 0 TSRMLS_CC); + phalcon_update_property_bool(this_ptr, SL("_disabled"), 1 TSRMLS_CC); + +} + +/** + * Enables the auto-rendering process + * + */ +PHP_METHOD(Phalcon_Mvc_View, enable){ + + + phalcon_update_property_bool(this_ptr, SL("_disabled"), 0 TSRMLS_CC); + +} + +/** + * Resets the view component to its factory default values + * + */ +PHP_METHOD(Phalcon_Mvc_View, reset){ + + + phalcon_update_property_bool(this_ptr, SL("_disabled"), 0 TSRMLS_CC); + phalcon_update_property_bool(this_ptr, SL("_engines"), 0 TSRMLS_CC); + phalcon_update_property_null(this_ptr, SL("_cache") TSRMLS_CC); + phalcon_update_property_long(this_ptr, SL("_renderLevel"), 5 TSRMLS_CC); + phalcon_update_property_long(this_ptr, SL("_cacheLevel"), 0 TSRMLS_CC); + phalcon_update_property_null(this_ptr, SL("_content") TSRMLS_CC); } diff --git a/ext/mvc/view/engine/volt/compiler.c b/ext/mvc/view/engine/volt/compiler.c index 633b6d202d6..ac22cdcb52f 100644 --- a/ext/mvc/view/engine/volt/compiler.c +++ b/ext/mvc/view/engine/volt/compiler.c @@ -232,7 +232,7 @@ PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, _filter){ PHALCON_INIT_VAR(name); phalcon_array_fetch_string(&name, filter, SL("name"), PH_NOISY_CC); if (PHALCON_COMPARE_STRING(name, "length")) { - PHALCON_CONCAT_SVS(code, "$this->count(", left, ")"); + PHALCON_CONCAT_SVS(code, "$this->length(", left, ")"); ZVAL_BOOL(exists, 1); } diff --git a/ext/phalcon.c b/ext/phalcon.c index 167644d151a..a1e1e3d2132 100755 --- a/ext/phalcon.c +++ b/ext/phalcon.c @@ -396,6 +396,7 @@ PHP_MINIT_FUNCTION(phalcon){ zend_declare_class_constant_long(phalcon_db_ce, SL("FETCH_ASSOC"), 1 TSRMLS_CC); zend_declare_class_constant_long(phalcon_db_ce, SL("FETCH_BOTH"), 2 TSRMLS_CC); zend_declare_class_constant_long(phalcon_db_ce, SL("FETCH_NUM"), 3 TSRMLS_CC); + zend_declare_class_constant_long(phalcon_db_ce, SL("FETCH_OBJ"), 4 TSRMLS_CC); PHALCON_REGISTER_CLASS(Phalcon, Logger, logger, phalcon_logger_method_entry, ZEND_ACC_EXPLICIT_ABSTRACT_CLASS); zend_declare_class_constant_long(phalcon_logger_ce, SL("SPECIAL"), 9 TSRMLS_CC); @@ -687,6 +688,7 @@ PHP_MINIT_FUNCTION(phalcon){ zend_declare_property_null(phalcon_mvc_view_ce, SL("_cache"), ZEND_ACC_PROTECTED TSRMLS_CC); zend_declare_property_long(phalcon_mvc_view_ce, SL("_cacheLevel"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); zend_declare_property_null(phalcon_mvc_view_ce, SL("_activeRenderPath"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_bool(phalcon_mvc_view_ce, SL("_disabled"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); zend_declare_class_constant_long(phalcon_mvc_view_ce, SL("LEVEL_MAIN_LAYOUT"), 5 TSRMLS_CC); zend_declare_class_constant_long(phalcon_mvc_view_ce, SL("LEVEL_AFTER_TEMPLATE"), 4 TSRMLS_CC); zend_declare_class_constant_long(phalcon_mvc_view_ce, SL("LEVEL_LAYOUT"), 3 TSRMLS_CC); diff --git a/ext/phalcon.h b/ext/phalcon.h index 6c9846330af..fd5d3a1575f 100755 --- a/ext/phalcon.h +++ b/ext/phalcon.h @@ -200,7 +200,6 @@ PHP_METHOD(Phalcon_DI, reset); PHP_METHOD(Phalcon_Text, camelize); PHP_METHOD(Phalcon_Text, uncamelize); -PHP_METHOD(Phalcon_Text, x); PHP_METHOD(Phalcon_Mvc_Router_Route, __construct); @@ -303,6 +302,8 @@ PHP_METHOD(Phalcon_Mvc_View, setContent); PHP_METHOD(Phalcon_Mvc_View, getContent); PHP_METHOD(Phalcon_Mvc_View, getActiveRenderPath); PHP_METHOD(Phalcon_Mvc_View, disable); +PHP_METHOD(Phalcon_Mvc_View, enable); +PHP_METHOD(Phalcon_Mvc_View, reset); PHP_METHOD(Phalcon_Mvc_Collection, __construct); PHP_METHOD(Phalcon_Mvc_Collection, setId); @@ -752,6 +753,7 @@ PHP_METHOD(Phalcon_Cache_Frontend_Data, afterRetrieve); PHP_METHOD(Phalcon_Cache_Backend, __construct); PHP_METHOD(Phalcon_Cache_Backend, start); +PHP_METHOD(Phalcon_Cache_Backend, stop); PHP_METHOD(Phalcon_Cache_Backend, getFrontend); PHP_METHOD(Phalcon_Cache_Backend, isFresh); PHP_METHOD(Phalcon_Cache_Backend, isStarted); @@ -961,6 +963,7 @@ PHP_METHOD(Phalcon_Db_Index, __set_state); PHP_METHOD(Phalcon_Db_Result_Pdo, __construct); PHP_METHOD(Phalcon_Db_Result_Pdo, execute); +PHP_METHOD(Phalcon_Db_Result_Pdo, fetch); PHP_METHOD(Phalcon_Db_Result_Pdo, fetchArray); PHP_METHOD(Phalcon_Db_Result_Pdo, fetchAll); PHP_METHOD(Phalcon_Db_Result_Pdo, numRows); @@ -1166,6 +1169,7 @@ PHP_METHOD(Phalcon_Flash, warning); PHP_METHOD(Phalcon_Flash, outputMessage); PHP_METHOD(Phalcon_Config, __construct); +PHP_METHOD(Phalcon_Config, __set_state); PHP_METHOD(Phalcon_Filter, __construct); PHP_METHOD(Phalcon_Filter, add); @@ -1368,11 +1372,6 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_text_uncamelize, 0, 0, 1) ZEND_ARG_INFO(0, str) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_text_x, 0, 0, 2) - ZEND_ARG_INFO(0, a) - ZEND_ARG_INFO(0, b) -ZEND_END_ARG_INFO() - ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_mvc_router_route___construct, 0, 0, 1) ZEND_ARG_INFO(0, pattern) ZEND_ARG_INFO(0, paths) @@ -2516,6 +2515,10 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_cache_backend_start, 0, 0, 1) ZEND_ARG_INFO(0, keyName) ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_cache_backend_stop, 0, 0, 0) + ZEND_ARG_INFO(0, stopBuffer) +ZEND_END_ARG_INFO() + ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_cache_backend_mongo___construct, 0, 0, 1) ZEND_ARG_INFO(0, frontendObject) ZEND_ARG_INFO(0, backendOptions) @@ -3446,6 +3449,10 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_config___construct, 0, 0, 0) ZEND_ARG_INFO(0, arrayConfig) ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_config___set_state, 0, 0, 1) + ZEND_ARG_INFO(0, data) +ZEND_END_ARG_INFO() + ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_filter_add, 0, 0, 2) ZEND_ARG_INFO(0, name) ZEND_ARG_INFO(0, handler) @@ -3675,7 +3682,6 @@ PHALCON_INIT_FUNCS(phalcon_di_method_entry){ PHALCON_INIT_FUNCS(phalcon_text_method_entry){ PHP_ME(Phalcon_Text, camelize, arginfo_phalcon_text_camelize, ZEND_ACC_STATIC|ZEND_ACC_PUBLIC) PHP_ME(Phalcon_Text, uncamelize, arginfo_phalcon_text_uncamelize, ZEND_ACC_STATIC|ZEND_ACC_PUBLIC) - PHP_ME(Phalcon_Text, x, arginfo_phalcon_text_x, ZEND_ACC_STATIC|ZEND_ACC_PUBLIC) PHP_FE_END }; @@ -3790,6 +3796,8 @@ PHALCON_INIT_FUNCS(phalcon_mvc_view_method_entry){ PHP_ME(Phalcon_Mvc_View, getContent, NULL, ZEND_ACC_PUBLIC) PHP_ME(Phalcon_Mvc_View, getActiveRenderPath, NULL, ZEND_ACC_PUBLIC) PHP_ME(Phalcon_Mvc_View, disable, NULL, ZEND_ACC_PUBLIC) + PHP_ME(Phalcon_Mvc_View, enable, NULL, ZEND_ACC_PUBLIC) + PHP_ME(Phalcon_Mvc_View, reset, NULL, ZEND_ACC_PUBLIC) PHP_FE_END }; @@ -4362,6 +4370,7 @@ PHALCON_INIT_FUNCS(phalcon_cache_frontend_data_method_entry){ PHALCON_INIT_FUNCS(phalcon_cache_backend_method_entry){ PHP_ME(Phalcon_Cache_Backend, __construct, arginfo_phalcon_cache_backend___construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR) PHP_ME(Phalcon_Cache_Backend, start, arginfo_phalcon_cache_backend_start, ZEND_ACC_PUBLIC) + PHP_ME(Phalcon_Cache_Backend, stop, arginfo_phalcon_cache_backend_stop, ZEND_ACC_PUBLIC) PHP_ME(Phalcon_Cache_Backend, getFrontend, NULL, ZEND_ACC_PUBLIC) PHP_ME(Phalcon_Cache_Backend, isFresh, NULL, ZEND_ACC_PUBLIC) PHP_ME(Phalcon_Cache_Backend, isStarted, NULL, ZEND_ACC_PUBLIC) @@ -4642,6 +4651,7 @@ PHALCON_INIT_FUNCS(phalcon_db_index_method_entry){ PHALCON_INIT_FUNCS(phalcon_db_result_pdo_method_entry){ PHP_ME(Phalcon_Db_Result_Pdo, __construct, arginfo_phalcon_db_result_pdo___construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR) PHP_ME(Phalcon_Db_Result_Pdo, execute, NULL, ZEND_ACC_PUBLIC) + PHP_ME(Phalcon_Db_Result_Pdo, fetch, NULL, ZEND_ACC_PUBLIC) PHP_ME(Phalcon_Db_Result_Pdo, fetchArray, NULL, ZEND_ACC_PUBLIC) PHP_ME(Phalcon_Db_Result_Pdo, fetchAll, NULL, ZEND_ACC_PUBLIC) PHP_ME(Phalcon_Db_Result_Pdo, numRows, NULL, ZEND_ACC_PUBLIC) @@ -4881,6 +4891,7 @@ PHALCON_INIT_FUNCS(phalcon_flash_method_entry){ PHALCON_INIT_FUNCS(phalcon_config_method_entry){ PHP_ME(Phalcon_Config, __construct, arginfo_phalcon_config___construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR) + PHP_ME(Phalcon_Config, __set_state, arginfo_phalcon_config___set_state, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) PHP_FE_END }; diff --git a/ext/php_phalcon.h b/ext/php_phalcon.h index 91c801a9293..703593b8003 100755 --- a/ext/php_phalcon.h +++ b/ext/php_phalcon.h @@ -20,7 +20,7 @@ #ifndef PHP_PHALCON_H #define PHP_PHALCON_H 1 -#define PHP_PHALCON_VERSION "0.6.0" +#define PHP_PHALCON_VERSION "0.6.1" #define PHP_PHALCON_EXTNAME "phalcon" #define PHALCON_MAX_MEMORY_STACK 48 @@ -79,4 +79,4 @@ extern zend_module_entry phalcon_module_entry; # define PHALCON_FASTCALL __fastcall #else # define PHALCON_FASTCALL -#endif \ No newline at end of file +#endif diff --git a/ext/text.c b/ext/text.c index 606187b7a90..1ff4a381250 100644 --- a/ext/text.c +++ b/ext/text.c @@ -96,20 +96,3 @@ PHP_METHOD(Phalcon_Text, uncamelize){ RETURN_CCTOR(uncamelized); } -PHP_METHOD(Phalcon_Text, x){ - - zval *a, *b, *x; - - PHALCON_MM_GROW(); - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz", &a, &b) == FAILURE) { - PHALCON_MM_RESTORE(); - RETURN_NULL(); - } - - PHALCON_INIT_VAR(x); - PHALCON_CALL_USER_FUNC_ARRAY(x, a, b); - - RETURN_CCTOR(x); -} - diff --git a/ext/version.c b/ext/version.c index 4fa29e2c2d5..620bd66e9d3 100644 --- a/ext/version.c +++ b/ext/version.c @@ -65,7 +65,7 @@ PHP_METHOD(Phalcon_Version, _getVersion){ array_init(version); add_next_index_long(version, 0); add_next_index_long(version, 6); - add_next_index_long(version, 0); + add_next_index_long(version, 1); add_next_index_long(version, 4); add_next_index_long(version, 0); diff --git a/unit-tests/ConfigTest.php b/unit-tests/ConfigTest.php index 9f9ee8ee883..0764383efd2 100755 --- a/unit-tests/ConfigTest.php +++ b/unit-tests/ConfigTest.php @@ -84,4 +84,38 @@ public function testStandarConfig() $this->_compareConfig($this->_config, $config); } + public function testStandardConfigSimpleArray() + { + + $expectedConfig = Phalcon\Config::__set_state(array( + 'database' => Phalcon\Config::__set_state(array( + 'adapter' => 'Mysql', + 'host' => 'localhost', + 'username' => 'scott', + 'password' => 'cheetah', + 'name' => 'test_db', + )), + 'other' => array( + 0 => 1, + 1 => 2, + 2 => 3, + 3 => 4, + ), + )); + + $settings = array( + "database" => array( + "adapter" => "Mysql", + "host" => "localhost", + "username" => "scott", + "password" => "cheetah", + "name" => "test_db", + ), + "other" => array(1, 2, 3, 4) + ); + $config = new Phalcon\Config($settings); + + $this->assertEquals($config, $expectedConfig); + } + } diff --git a/unit-tests/DbTest.php b/unit-tests/DbTest.php index d7b6150c4ef..950a03756e9 100755 --- a/unit-tests/DbTest.php +++ b/unit-tests/DbTest.php @@ -95,11 +95,11 @@ protected function _executeTests($connection) $this->assertEquals(get_class($result), 'Phalcon\Db\Result\Pdo'); for ($i=0; $i<3; $i++) { - $row = $result->fetchArray(); + $row = $result->fetch(); $this->assertEquals(count($row), 22); } - $row = $result->fetchArray(); + $row = $result->fetch(); $this->assertEquals($row, false); $this->assertEquals($result->numRows(), 3); @@ -107,26 +107,40 @@ protected function _executeTests($connection) $result = $connection->query("SELECT * FROM personas LIMIT 5"); $this->assertTrue(is_object($result)); - while ($row = $result->fetchArray()) { + while ($row = $result->fetch()) { $number++; } $this->assertEquals($number, 5); $result = $connection->query("SELECT * FROM personas LIMIT 5"); $result->setFetchMode(Phalcon\Db::FETCH_NUM); - $row = $result->fetchArray(); + $row = $result->fetch(); + $this->assertTrue(is_array($row)); $this->assertEquals(count($row), 11); + $this->assertTrue(isset($row[0])); + $this->assertFalse(isset($row['cedula'])); + $this->assertFalse(isset($row->cedula)); $result = $connection->query("SELECT * FROM personas LIMIT 5"); $result->setFetchMode(Phalcon\Db::FETCH_ASSOC); - $row = $result->fetchArray(); + $row = $result->fetch(); + $this->assertTrue(is_array($row)); $this->assertEquals(count($row), 11); + $this->assertFalse(isset($row[0])); + $this->assertTrue(isset($row['cedula'])); + $this->assertFalse(isset($row->cedula)); + + $result = $connection->query("SELECT * FROM personas LIMIT 5"); + $result->setFetchMode(Phalcon\Db::FETCH_OBJ); + $row = $result->fetch(); + $this->assertTrue(is_object($row)); + $this->assertTrue(isset($row->cedula)); $result = $connection->query("SELECT * FROM personas LIMIT 5"); $result->setFetchMode(Phalcon\Db::FETCH_BOTH); $result->dataSeek(4); - $row = $result->fetchArray(); - $row = $result->fetchArray(); + $row = $result->fetch(); + $row = $result->fetch(); $this->assertEquals($row, false); $result = $connection->execute("DELETE FROM prueba"); diff --git a/unit-tests/MicroMvcTest.php b/unit-tests/MicroMvcTest.php index 8f2bce99172..9921897ccf3 100644 --- a/unit-tests/MicroMvcTest.php +++ b/unit-tests/MicroMvcTest.php @@ -79,4 +79,35 @@ public function testMicroClass() $this->assertEquals($handler->getTrace(), array('find', 'save')); } -} \ No newline at end of file + /** + * Tests the notFound + * + * @issue T169 + * @author Nikos Dimopoulos + * @since 2012-11-06 + */ + public function testMicroNotFound_T169() + { + + $handler = new RestHandler($this); + $app = new \Phalcon\Mvc\Micro(); + + $app->get('/api/site', array($handler, 'find')); + $app->post('/api/site/save', array($handler, 'save')); + + $flag = false; + + $app->notFound(function () use (&$flag) { + $flag = true; + }); + + $_SERVER['REQUEST_METHOD'] = 'GET'; + $_GET['_url'] = '/fourohfour'; + + $app->handle(); + + $this->assertTrue($flag); + } + +} + diff --git a/unit-tests/ModelsResultsetCacheTest.php b/unit-tests/ModelsResultsetCacheTest.php index 37bf5f67226..e751fc58c3c 100644 --- a/unit-tests/ModelsResultsetCacheTest.php +++ b/unit-tests/ModelsResultsetCacheTest.php @@ -102,11 +102,17 @@ protected function _testCacheDefaultDI($di) )); }); - $robots = Robots::find(array('cache' => array('key' => 'some'), 'order' => 'id')); + $robots = Robots::find(array( + 'cache' => array('key' => 'some'), + 'order' => 'id' + )); $this->assertEquals(count($robots), 3); $this->assertTrue($robots->isFresh()); - $robots = Robots::find(array('cache' => array('key' => 'some'), 'order' => 'id')); + $robots = Robots::find(array( + 'cache' => array('key' => 'some'), + 'order' => 'id' + )); $this->assertEquals(count($robots), 3); $this->assertFalse($robots->isFresh()); @@ -134,11 +140,25 @@ protected function _testCacheOtherService($di) )); }); - $robots = Robots::find(array('cache' => array('key' => 'other-some', 'lifetime' => 60, 'service' => 'otherCache'), 'order' => 'id')); + $robots = Robots::find(array( + 'cache' => array( + 'key' => 'other-some', + 'lifetime' => 60, + 'service' => 'otherCache' + ), + 'order' => 'id' + )); $this->assertEquals(count($robots), 3); $this->assertTrue($robots->isFresh()); - $robots = Robots::find(array('cache' => array('key' => 'other-some', 'lifetime' => 60, 'service' => 'otherCache'), 'order' => 'id')); + $robots = Robots::find(array( + 'cache' => array( + 'key' => 'other-some', + 'lifetime' => 60, + 'service' => 'otherCache' + ), + 'order' => 'id' + )); $this->assertEquals(count($robots), 3); $this->assertFalse($robots->isFresh()); diff --git a/unit-tests/RouterMvcTest.php b/unit-tests/RouterMvcTest.php index 653c6d21522..feaf6217202 100644 --- a/unit-tests/RouterMvcTest.php +++ b/unit-tests/RouterMvcTest.php @@ -93,6 +93,12 @@ public function testRouter() 'action' => 'show', 'params' => array('language' => 'en', 'file' => 'translate.adapter') ), + array( + 'uri' => '/named-manual/en/translate.adapter.html', + 'controller' => 'manual', + 'action' => 'show', + 'params' => array('language' => 'en', 'file' => 'translate.adapter') + ), array( 'uri' => '/posts/1999/s/le-nice-title', 'controller' => 'posts', @@ -155,6 +161,11 @@ public function testRouter() 'file' => 2 )); + $router->add('/named-manual/{language:[a-z]{2}}/{file:[a-z\.]+}\.html', array( + 'controller' => 'manual', + 'action' => 'show', + )); + $router->add('/very/static/route', array( 'controller' => 'static', 'action' => 'route' diff --git a/unit-tests/ViewCacheTest.php b/unit-tests/ViewCacheTest.php index f64e39f911d..e530615dd3b 100644 --- a/unit-tests/ViewCacheTest.php +++ b/unit-tests/ViewCacheTest.php @@ -45,29 +45,46 @@ public function testCacheDI() )); }); + $date = date("r"); + $content = ''.$date.''.PHP_EOL; + $view = new Phalcon\Mvc\View(); $view->setDI($di); - $view->setViewsDir('unit-tests/views/'); + $view->setVar("date", $date); + //First hit + $view->start(); $view->cache(true); + $view->render('test8', 'index'); + $view->finish(); + $this->assertEquals($view->getContent(), $content); - $date = date("r"); - - $content = ''.$date.''.PHP_EOL; - - $view->setVar("date", $date); + $view->reset(); + //Second hit $view->start(); $view->cache(true); $view->render('test8', 'index'); $view->finish(); $this->assertEquals($view->getContent(), $content); + $view->reset(); + sleep(1); $view->setVar("date", date("r")); + //Third hit after 1 second + $view->start(); + $view->cache(true); + $view->render('test8', 'index'); + $view->finish(); + $this->assertEquals($view->getContent(), $content); + + $view->reset(); + + //Four hit $view->start(); $view->cache(true); $view->render('test8', 'index'); @@ -116,6 +133,8 @@ public function testViewOptions() $view->finish(); $this->assertEquals($view->getContent(), $content); + $view->reset(); + sleep(1); $view->setVar("date", date("r")); diff --git a/unit-tests/ViewEnginesVoltTest.php b/unit-tests/ViewEnginesVoltTest.php index 655ce725023..f6b86f5099f 100644 --- a/unit-tests/ViewEnginesVoltTest.php +++ b/unit-tests/ViewEnginesVoltTest.php @@ -646,7 +646,7 @@ public function testVoltCompiler() } $compilation = $volt->compileString('{{ ("hello" ~ "lol")|e|length }}'); - $this->assertEquals($compilation, 'count($this->escaper->escapeHtml((\'hello\' . \'lol\'))); ?>'); + $this->assertEquals($compilation, 'length($this->escaper->escapeHtml((\'hello\' . \'lol\'))); ?>'); //if statement $compilation = $volt->compileString('{% if a==b %} hello {% endif %}'); diff --git a/unit-tests/logs/test.log b/unit-tests/logs/test.log index cb045e21e3b..7f8306f2f59 100644 --- a/unit-tests/logs/test.log +++ b/unit-tests/logs/test.log @@ -1 +1 @@ -[Wed, 17 Oct 12 18:56:37 +0300][DEBUG] Hello 1 +[Thu, 08 Nov 12 12:00:46 -0500][DEBUG] Hello 1 diff --git a/unit-tests/manual-unit.php b/unit-tests/manual-unit.php index 5354bd97f1c..e053046b9e9 100644 --- a/unit-tests/manual-unit.php +++ b/unit-tests/manual-unit.php @@ -152,6 +152,6 @@ public static function main($className) } catch(Exception $e){ echo $e->getMessage(), PHP_EOL; - echo $e->getTraceAsString(), PHP_EOL; - //print_r($e->getTrace()); + //echo $e->getTraceAsString(), PHP_EOL; + print_r($e->getTrace()); }