/** * Executes the validation * * @param Phalcon\Validation $validator * @param string $attribute * @return boolean */ PHP_METHOD(Phalcon_Validation_Validator_Between, validate){ zval *validator, *attribute, *value, *option = NULL, *minimum; zval *maximum, *valid = NULL, *type, *message_str = NULL, *message; PHALCON_MM_GROW(); phalcon_fetch_params(1, 2, 0, &validator, &attribute); PHALCON_INIT_VAR(value); phalcon_call_method_p1(value, validator, "getvalue", attribute); PHALCON_INIT_VAR(option); ZVAL_STRING(option, "minimum", 1); PHALCON_INIT_VAR(minimum); phalcon_call_method_p1(minimum, this_ptr, "getoption", option); PHALCON_INIT_NVAR(option); ZVAL_STRING(option, "maximum", 1); PHALCON_INIT_VAR(maximum); phalcon_call_method_p1(maximum, this_ptr, "getoption", option); PHALCON_INIT_VAR(valid); is_smaller_or_equal_function(valid, minimum, value TSRMLS_CC); if (zend_is_true(valid)) { is_smaller_or_equal_function(valid, value, maximum TSRMLS_CC); } if (PHALCON_IS_FALSE(valid)) { PHALCON_INIT_VAR(type); ZVAL_STRING(type, "Between", 1); PHALCON_INIT_NVAR(option); ZVAL_STRING(option, "message", 1); PHALCON_INIT_VAR(message_str); phalcon_call_method_p1(message_str, this_ptr, "getoption", option); if (!zend_is_true(message_str)) { PHALCON_INIT_NVAR(message_str); PHALCON_CONCAT_VS(message_str, attribute, " is not between a valid range"); } PHALCON_INIT_VAR(message); object_init_ex(message, phalcon_validation_message_ce); phalcon_call_method_p3_noret(message, "__construct", message_str, attribute, type); phalcon_call_method_p1_noret(validator, "appendmessage", message); RETURN_MM_FALSE; } RETURN_MM_TRUE; }
/** * Executes the validation * * @param int $value * @param int $minimum * @param int $maximum * @return boolean */ PHP_METHOD(Phalcon_Validation_Validator_Between, valid){ zval *value, *minimum = NULL, *maximum = NULL, valid = {}; phalcon_fetch_params(0, 3, 0, &value, &minimum, &maximum); is_smaller_or_equal_function(&valid, minimum, value); if (zend_is_true(&valid)) { is_smaller_or_equal_function(&valid, value, maximum); } if (PHALCON_IS_FALSE(&valid)) { RETURN_FALSE; } RETURN_TRUE; }
/** * Executes the validation * * @param string $value * @return boolean */ PHP_METHOD(Phalcon_Validation_Validator_Between, valid){ zval *value, *minimum = NULL, *maximum = NULL, *valid; PHALCON_MM_GROW(); phalcon_fetch_params(1, 3, 0, &value, &minimum, &maximum); PHALCON_INIT_VAR(valid); is_smaller_or_equal_function(valid, minimum, value TSRMLS_CC); if (zend_is_true(valid)) { is_smaller_or_equal_function(valid, value, maximum TSRMLS_CC); } if (PHALCON_IS_FALSE(valid)) { RETURN_MM_FALSE; } RETURN_MM_TRUE; }
/** * Returns a slice of the resultset to show in the pagination * * @return stdClass */ PHP_METHOD(Phalcon_Paginator_Adapter_Model, getPaginate){ zval *v0 = NULL, *v1 = NULL, *v2 = NULL, *v3 = NULL, *v4 = NULL, *v5 = NULL, *v6 = NULL; zval *v7 = NULL, *v8 = NULL, *v9 = NULL, *v10 = NULL; zval *t0 = NULL, *t1 = NULL, *t2 = NULL, *t3 = NULL, *t4 = NULL, *t5 = NULL, *t6 = NULL; zval *t7 = NULL, *t8 = NULL, *t9 = NULL, *t10 = NULL, *t11 = NULL, *t12 = NULL; zval *r0 = NULL, *r1 = NULL, *r2 = NULL, *r3 = NULL, *r4 = NULL, *r5 = NULL, *r6 = NULL; zval *r7 = NULL, *r8 = NULL, *r9 = NULL, *r10 = NULL, *r11 = NULL, *r12 = NULL, *r13 = NULL; zval *r14 = NULL, *r15 = NULL, *r16 = NULL, *r17 = NULL, *r18 = NULL, *r19 = NULL, *r20 = NULL; zval *r21 = NULL, *r22 = NULL, *r23 = NULL, *r24 = NULL, *r25 = NULL, *r26 = NULL, *r27 = NULL; zval *r28 = NULL; zval *i0 = NULL, *i1 = NULL, *i2 = NULL; zval *a0 = NULL; zval *p2[] = { NULL }, *p3[] = { NULL }, *p4[] = { NULL }, *p5[] = { NULL }; PHALCON_MM_GROW(); PHALCON_ALLOC_ZVAL_MM(t0); phalcon_read_property(&t0, this_ptr, "_limitRows", sizeof("_limitRows")-1, PHALCON_NOISY_FETCH TSRMLS_CC); PHALCON_CPY_WRT(v0, t0); PHALCON_ALLOC_ZVAL_MM(t1); phalcon_read_property(&t1, this_ptr, "_config", sizeof("_config")-1, PHALCON_NOISY_FETCH TSRMLS_CC); PHALCON_ALLOC_ZVAL_MM(r0); phalcon_array_fetch_string(&r0, t1, "data", strlen("data"), PHALCON_NOISY_FETCH TSRMLS_CC); PHALCON_CPY_WRT(v1, r0); PHALCON_ALLOC_ZVAL_MM(t2); phalcon_read_property(&t2, this_ptr, "_page", sizeof("_page")-1, PHALCON_NOISY_FETCH TSRMLS_CC); PHALCON_CPY_WRT(v2, t2); if (Z_TYPE_P(v2) == IS_NULL) { PHALCON_INIT_VAR(v2); ZVAL_LONG(v2, 1); } PHALCON_ALLOC_ZVAL_MM(r1); PHALCON_CALL_FUNC_PARAMS_1(r1, "count", v1, 0x008); PHALCON_CPY_WRT(v3, r1); PHALCON_ALLOC_ZVAL_MM(i0); object_init(i0); PHALCON_CPY_WRT(v4, i0); PHALCON_INIT_VAR(t3); ZVAL_LONG(t3, 1); PHALCON_ALLOC_ZVAL_MM(r2); sub_function(r2, v2, t3 TSRMLS_CC); PHALCON_ALLOC_ZVAL_MM(r3); mul_function(r3, v0, r2 TSRMLS_CC); PHALCON_CPY_WRT(v5, r3); PHALCON_ALLOC_ZVAL_MM(r4); PHALCON_INIT_VAR(t4); ZVAL_LONG(t4, 1); PHALCON_ALLOC_ZVAL_MM(r5); sub_function(r5, v3, t4 TSRMLS_CC); PHALCON_ALLOC_ZVAL_MM(r6); div_function(r6, r5, v0 TSRMLS_CC); Z_ADDREF_P(r6); PHALCON_CALL_FUNC_PARAMS_1(r4, "ceil", r6, 0x00D); Z_DELREF_P(r6); PHALCON_CPY_WRT(v6, r4); if (Z_TYPE_P(v1) != IS_OBJECT) { PHALCON_ALLOC_ZVAL_MM(i1); object_init_ex(i1, phalcon_paginator_exception_class_entry); PHALCON_INIT_VAR(p2[0]); ZVAL_STRING(p2[0], "Invalid data for paginator", 1); PHALCON_CALL_METHOD_PARAMS_NORETURN(i1, "__construct", 1, p2, PHALCON_CALL_CHECK); zend_throw_exception_object(i1 TSRMLS_CC); Z_ADDREF_P(i1); PHALCON_MM_RESTORE(); return; } if (Z_TYPE_P(v2) == IS_NULL) { PHALCON_INIT_VAR(v2); ZVAL_LONG(v2, 0); } PHALCON_INIT_VAR(t5); ZVAL_LONG(t5, 0); PHALCON_INIT_VAR(r7); is_smaller_function(r7, v5, t5 TSRMLS_CC); if (zend_is_true(r7)) { PHALCON_ALLOC_ZVAL_MM(i2); object_init_ex(i2, phalcon_paginator_exception_class_entry); PHALCON_INIT_VAR(p3[0]); ZVAL_STRING(p3[0], "The start page number is zero or less", 1); PHALCON_CALL_METHOD_PARAMS_NORETURN(i2, "__construct", 1, p3, PHALCON_CALL_CHECK); zend_throw_exception_object(i2 TSRMLS_CC); Z_ADDREF_P(i2); PHALCON_MM_RESTORE(); return; } PHALCON_INIT_VAR(a0); array_init(a0); phalcon_update_property_zval(v4, "items", strlen("items"), a0 TSRMLS_CC); PHALCON_INIT_VAR(t6); ZVAL_LONG(t6, 0); PHALCON_INIT_VAR(r8); is_smaller_function(r8, t6, v3 TSRMLS_CC); if (zend_is_true(r8)) { PHALCON_INIT_VAR(r9); is_smaller_or_equal_function(r9, v5, v3 TSRMLS_CC); if (zend_is_true(r9)) { Z_ADDREF_P(v5); p4[0] = v5; PHALCON_CALL_METHOD_PARAMS_NORETURN(v1, "seek", 1, p4, PHALCON_CALL_DEFAULT); Z_DELREF_P(p4[0]); } else { PHALCON_INIT_VAR(p5[0]); ZVAL_LONG(p5[0], 1); PHALCON_CALL_METHOD_PARAMS_NORETURN(v1, "seek", 1, p5, PHALCON_CALL_DEFAULT); PHALCON_INIT_VAR(v2); ZVAL_LONG(v2, 1); } PHALCON_INIT_VAR(v7); ZVAL_LONG(v7, 1); ws_e435_0: PHALCON_INIT_VAR(r10); PHALCON_CALL_METHOD(r10, v1, "valid", PHALCON_CALL_DEFAULT); if (!zend_is_true(r10)) { goto we_e435_0; } PHALCON_INIT_VAR(r11); PHALCON_CALL_METHOD(r11, v1, "current", PHALCON_CALL_DEFAULT); PHALCON_INIT_VAR(t7); phalcon_read_property(&t7, v4, "items", sizeof("items")-1, PHALCON_NOISY_FETCH TSRMLS_CC); Z_ADDREF_P(r11); phalcon_array_append(t7, r11 TSRMLS_CC); phalcon_update_property_zval(v4, "items", strlen("items"), t7 TSRMLS_CC); PHALCON_INIT_VAR(r12); is_smaller_or_equal_function(r12, v0, v7 TSRMLS_CC); if (zend_is_true(r12)) { goto we_e435_0; } PHALCON_SEPARATE(v7); increment_function(v7); goto ws_e435_0; we_e435_0: if(0) { }; } phalcon_update_property_long(v4, "first", strlen("first"), 1 TSRMLS_CC); PHALCON_ALLOC_ZVAL_MM(r13); phalcon_add_function(r13, v5, v0 TSRMLS_CC); PHALCON_INIT_VAR(r14); is_smaller_function(r14, r13, v3 TSRMLS_CC); if (zend_is_true(r14)) { PHALCON_INIT_VAR(t8); ZVAL_LONG(t8, 1); PHALCON_ALLOC_ZVAL_MM(r15); phalcon_add_function(r15, v2, t8 TSRMLS_CC); PHALCON_CPY_WRT(v8, r15); } else { PHALCON_ALLOC_ZVAL_MM(r16); phalcon_add_function(r16, v5, v0 TSRMLS_CC); PHALCON_ALLOC_ZVAL_MM(r17); is_equal_function(r17, r16, v3 TSRMLS_CC); if (zend_is_true(r17)) { PHALCON_CPY_WRT(v8, v3); } else { PHALCON_ALLOC_ZVAL_MM(r18); PHALCON_ALLOC_ZVAL_MM(r19); div_function(r19, v3, v0 TSRMLS_CC); PHALCON_CALL_FUNC_PARAMS_1(r18, "intval", r19, 0x00E); PHALCON_INIT_VAR(t9); ZVAL_LONG(t9, 1); PHALCON_ALLOC_ZVAL_MM(r20); phalcon_add_function(r20, r18, t9 TSRMLS_CC); PHALCON_CPY_WRT(v8, r20); } } PHALCON_INIT_VAR(r21); is_smaller_function(r21, v6, v8 TSRMLS_CC); if (zend_is_true(r21)) { PHALCON_CPY_WRT(v8, v6); } phalcon_update_property_zval(v4, "next", strlen("next"), v8 TSRMLS_CC); PHALCON_INIT_VAR(t10); ZVAL_LONG(t10, 1); PHALCON_INIT_VAR(r22); is_smaller_function(r22, t10, v2 TSRMLS_CC); if (zend_is_true(r22)) { PHALCON_INIT_VAR(t11); ZVAL_LONG(t11, 1); PHALCON_ALLOC_ZVAL_MM(r23); sub_function(r23, v2, t11 TSRMLS_CC); PHALCON_CPY_WRT(v9, r23); } else { PHALCON_INIT_VAR(v9); ZVAL_LONG(v9, 1); } phalcon_update_property_zval(v4, "before", strlen("before"), v9 TSRMLS_CC); phalcon_update_property_zval(v4, "current", strlen("current"), v2 TSRMLS_CC); PHALCON_ALLOC_ZVAL_MM(r24); mod_function(r24, v3, v0 TSRMLS_CC); if (zend_is_true(r24)) { PHALCON_ALLOC_ZVAL_MM(r25); PHALCON_ALLOC_ZVAL_MM(r26); div_function(r26, v3, v0 TSRMLS_CC); PHALCON_CALL_FUNC_PARAMS_1(r25, "intval", r26, 0x00E); PHALCON_INIT_VAR(t12); ZVAL_LONG(t12, 1); PHALCON_ALLOC_ZVAL_MM(r27); phalcon_add_function(r27, r25, t12 TSRMLS_CC); PHALCON_CPY_WRT(v10, r27); } else { PHALCON_ALLOC_ZVAL_MM(r28); div_function(r28, v3, v0 TSRMLS_CC); PHALCON_CPY_WRT(v10, r28); } phalcon_update_property_zval(v4, "last", strlen("last"), v10 TSRMLS_CC); phalcon_update_property_zval(v4, "total_pages", strlen("total_pages"), v10 TSRMLS_CC); PHALCON_RETURN_CTOR(v4); }
/** * Returns a slice of the resultset to show in the pagination * * @return stdClass */ PHP_METHOD(Phalcon_Paginator_Adapter_Model, getPaginate){ zval *show = NULL, *config = NULL, *items = NULL, *page_number = NULL, *zero = NULL, *one = NULL; zval *smaller = NULL, *n = NULL, *page = NULL, *last_show_page = NULL, *start = NULL; zval *last_page = NULL, *possible_pages = NULL, *total_pages = NULL; zval *compare = NULL, *page_items = NULL, *i = NULL, *valid = NULL, *current = NULL, *maximum_pages = NULL; zval *next = NULL, *additional_page = NULL, *before = NULL, *remainder = NULL; zval *pages_total = NULL; zval *r0 = NULL; zval *t0 = NULL; PHALCON_MM_GROW(); PHALCON_INIT_VAR(show); phalcon_read_property(&show, this_ptr, SL("_limitRows"), PH_NOISY_CC); PHALCON_INIT_VAR(config); phalcon_read_property(&config, this_ptr, SL("_config"), PH_NOISY_CC); PHALCON_INIT_VAR(items); phalcon_array_fetch_string(&items, config, SL("data"), PH_NOISY_CC); PHALCON_INIT_VAR(page_number); phalcon_read_property(&page_number, this_ptr, SL("_page"), PH_NOISY_CC); if (Z_TYPE_P(page_number) == IS_NULL) { PHALCON_INIT_VAR(page_number); ZVAL_LONG(page_number, 1); } PHALCON_INIT_VAR(zero); ZVAL_LONG(zero, 0); PHALCON_INIT_VAR(one); ZVAL_LONG(one, 1); PHALCON_INIT_VAR(smaller); is_smaller_function(smaller, show, zero TSRMLS_CC); if (Z_TYPE_P(smaller) == IS_BOOL && Z_BVAL_P(smaller)) { PHALCON_THROW_EXCEPTION_STR(phalcon_paginator_exception_ce, "The start page number is zero or less"); return; } PHALCON_INIT_VAR(n); phalcon_fast_count(n, items TSRMLS_CC); PHALCON_INIT_VAR(page); object_init(page); PHALCON_INIT_VAR(last_show_page); sub_function(last_show_page, page_number, one TSRMLS_CC); PHALCON_INIT_VAR(start); mul_function(start, show, last_show_page TSRMLS_CC); PHALCON_INIT_VAR(last_page); sub_function(last_page, n, one TSRMLS_CC); PHALCON_INIT_VAR(possible_pages); div_function(possible_pages, last_page, show TSRMLS_CC); PHALCON_INIT_VAR(total_pages); PHALCON_CALL_FUNC_PARAMS_1(total_pages, "ceil", possible_pages); if (Z_TYPE_P(items) != IS_OBJECT) { PHALCON_THROW_EXCEPTION_STR(phalcon_paginator_exception_ce, "Invalid data for paginator"); return; } if (Z_TYPE_P(page_number) == IS_NULL) { PHALCON_INIT_VAR(page_number); ZVAL_LONG(page_number, 0); } PHALCON_INIT_VAR(compare); is_smaller_function(compare, start, zero TSRMLS_CC); if (Z_TYPE_P(compare) == IS_BOOL && Z_BVAL_P(compare)) { PHALCON_THROW_EXCEPTION_STR(phalcon_paginator_exception_ce, "The start page number is zero or less"); return; } PHALCON_INIT_VAR(page_items); array_init(page_items); PHALCON_INIT_VAR(compare); is_smaller_function(compare, zero, n TSRMLS_CC); if (Z_TYPE_P(compare) == IS_BOOL && Z_BVAL_P(compare)) { PHALCON_INIT_VAR(compare); is_smaller_or_equal_function(compare, start, n TSRMLS_CC); if (Z_TYPE_P(compare) == IS_BOOL && Z_BVAL_P(compare)) { PHALCON_CALL_METHOD_PARAMS_1_NORETURN(items, "seek", start, PH_NO_CHECK); } else { PHALCON_CALL_METHOD_PARAMS_1_NORETURN(items, "seek", one, PH_NO_CHECK); PHALCON_INIT_VAR(page_number); ZVAL_LONG(page_number, 1); } PHALCON_INIT_VAR(i); ZVAL_LONG(i, 1); ws_e435_0: PHALCON_INIT_VAR(r0); PHALCON_CALL_METHOD(r0, items, "valid", PH_NO_CHECK); PHALCON_CPY_WRT(valid, r0); if (Z_TYPE_P(valid) != IS_BOOL || (Z_TYPE_P(valid) == IS_BOOL && !Z_BVAL_P(valid))) { goto we_e435_0; } PHALCON_INIT_VAR(current); PHALCON_CALL_METHOD(current, items, "current", PH_NO_CHECK); phalcon_array_append(&page_items, current, PH_SEPARATE TSRMLS_CC); PHALCON_INIT_VAR(compare); is_smaller_or_equal_function(compare, show, i TSRMLS_CC); if (Z_TYPE_P(compare) == IS_BOOL && Z_BVAL_P(compare)) { goto we_e435_0; } PHALCON_SEPARATE(i); increment_function(i); goto ws_e435_0; we_e435_0: if(0){} } phalcon_update_property_zval(page, SL("items"), page_items TSRMLS_CC); phalcon_update_property_long(page, SL("first"), 1 TSRMLS_CC); PHALCON_INIT_VAR(maximum_pages); phalcon_add_function(maximum_pages, start, show TSRMLS_CC); PHALCON_INIT_VAR(compare); is_smaller_function(compare, maximum_pages, n TSRMLS_CC); if (Z_TYPE_P(compare) == IS_BOOL && Z_BVAL_P(compare)) { PHALCON_INIT_VAR(t0); ZVAL_LONG(t0, 1); PHALCON_INIT_VAR(next); phalcon_add_function(next, page_number, t0 TSRMLS_CC); } else { PHALCON_INIT_VAR(compare); is_equal_function(compare, maximum_pages, n TSRMLS_CC); if (Z_TYPE_P(compare) == IS_BOOL && Z_BVAL_P(compare)) { PHALCON_CPY_WRT(next, n); } else { PHALCON_INIT_VAR(possible_pages); div_function(possible_pages, n, show TSRMLS_CC); PHALCON_INIT_VAR(additional_page); phalcon_add_function(additional_page, possible_pages, one TSRMLS_CC); PHALCON_INIT_VAR(next); PHALCON_CALL_FUNC_PARAMS_1(next, "intval", additional_page); } } PHALCON_INIT_VAR(compare); is_smaller_function(compare, total_pages, next TSRMLS_CC); if (Z_TYPE_P(compare) == IS_BOOL && Z_BVAL_P(compare)) { PHALCON_CPY_WRT(next, total_pages); } phalcon_update_property_zval(page, SL("next"), next TSRMLS_CC); PHALCON_INIT_VAR(compare); is_smaller_function(compare, one, page_number TSRMLS_CC); if (Z_TYPE_P(compare) == IS_BOOL && Z_BVAL_P(compare)) { PHALCON_INIT_VAR(before); sub_function(before, page_number, one TSRMLS_CC); } else { PHALCON_INIT_VAR(before); ZVAL_LONG(before, 1); } phalcon_update_property_zval(page, SL("before"), before TSRMLS_CC); phalcon_update_property_zval(page, SL("current"), page_number TSRMLS_CC); PHALCON_INIT_VAR(remainder); mod_function(remainder, n, show TSRMLS_CC); PHALCON_INIT_VAR(possible_pages); div_function(possible_pages, n, show TSRMLS_CC); if (!phalcon_compare_strict_long(remainder, 0 TSRMLS_CC)) { PHALCON_INIT_VAR(next); phalcon_add_function(next, possible_pages, one TSRMLS_CC); PHALCON_INIT_VAR(pages_total); PHALCON_CALL_FUNC_PARAMS_1(pages_total, "intval", possible_pages); } else { PHALCON_CPY_WRT(pages_total, possible_pages); } phalcon_update_property_zval(page, SL("last"), pages_total TSRMLS_CC); phalcon_update_property_zval(page, SL("total_pages"), pages_total TSRMLS_CC); RETURN_CTOR(page); }
/** * Executes render process from request data * * @param string $controllerName * @param string $actionName * @param array $params */ PHP_METHOD(Phalcon_View, render){ zval *controller_name = NULL, *action_name = NULL, *params = NULL; zval *layouts_dir = NULL, *engines = NULL, *pick_view = NULL, *render_view = NULL; zval *render_controller = NULL, *silence = NULL, *render_level = NULL; zval *templates_before = NULL, *template_before = NULL; zval *templates_after = NULL, *template_after = NULL; zval *a0 = NULL; zval *t0 = NULL, *t1 = NULL, *t2 = NULL, *t3 = NULL, *t4 = NULL, *t5 = NULL, *t6 = NULL; zval *t7 = NULL, *t8 = NULL, *t9 = NULL, *t10 = NULL; zval *r0 = NULL, *r1 = NULL, *r2 = NULL, *r3 = NULL, *r4 = NULL, *r5 = NULL, *r6 = NULL; zval *r7 = NULL, *r8 = NULL, *r9 = NULL, *r10 = NULL, *r11 = NULL, *r12 = NULL, *r13 = NULL; zval *r14 = NULL; HashTable *ah0, *ah1; HashPosition hp0, hp1; zval **hd; int eval_int; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz|z", &controller_name, &action_name, ¶ms) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } if (!params) { PHALCON_INIT_VAR(a0); array_init(a0); PHALCON_CPY_WRT(params, a0); } PHALCON_ALLOC_ZVAL_MM(t0); phalcon_read_property(&t0, this_ptr, "_layoutsDir", sizeof("_layoutsDir")-1, PHALCON_NOISY TSRMLS_CC); PHALCON_CPY_WRT(layouts_dir, t0); if (!zend_is_true(layouts_dir)) { PHALCON_INIT_VAR(layouts_dir); ZVAL_STRING(layouts_dir, "layouts/", 1); } phalcon_update_property_zval(this_ptr, "_controllerName", strlen("_controllerName"), controller_name TSRMLS_CC); phalcon_update_property_zval(this_ptr, "_actionName", strlen("_actionName"), action_name TSRMLS_CC); phalcon_update_property_zval(this_ptr, "_params", strlen("_params"), params TSRMLS_CC); phalcon_update_property_bool(this_ptr, "_initEngines", strlen("_initEngines"), 0 TSRMLS_CC); PHALCON_ALLOC_ZVAL_MM(r0); PHALCON_CALL_METHOD(r0, this_ptr, "_loadtemplateengines", PHALCON_NO_CHECK); PHALCON_CPY_WRT(engines, r0); PHALCON_ALLOC_ZVAL_MM(t1); phalcon_read_property(&t1, this_ptr, "_pickView", sizeof("_pickView")-1, PHALCON_NOISY TSRMLS_CC); PHALCON_CPY_WRT(pick_view, t1); if (!zend_is_true(pick_view)) { PHALCON_ALLOC_ZVAL_MM(r1); PHALCON_CONCAT_VSV(r1, controller_name, "/", action_name); PHALCON_CPY_WRT(render_view, r1); PHALCON_CPY_WRT(render_controller, controller_name); } else { PHALCON_ALLOC_ZVAL_MM(r2); phalcon_array_fetch_long(&r2, pick_view, 0, PHALCON_NOISY TSRMLS_CC); PHALCON_CPY_WRT(render_view, r2); eval_int = phalcon_array_isset_long(pick_view, 1); if (eval_int) { PHALCON_ALLOC_ZVAL_MM(r3); phalcon_array_fetch_long(&r3, pick_view, 1, PHALCON_NOISY TSRMLS_CC); PHALCON_CPY_WRT(render_controller, r3); } else { PHALCON_CPY_WRT(render_controller, controller_name); } } PHALCON_INIT_VAR(silence); ZVAL_BOOL(silence, 1); PHALCON_ALLOC_ZVAL_MM(t2); phalcon_read_property(&t2, this_ptr, "_renderLevel", sizeof("_renderLevel")-1, PHALCON_NOISY TSRMLS_CC); PHALCON_CPY_WRT(render_level, t2); if (zend_is_true(render_level)) { PHALCON_ALLOC_ZVAL_MM(r4); PHALCON_CALL_FUNC(r4, "ob_get_contents", 0x015); phalcon_update_property_zval(this_ptr, "_content", strlen("_content"), r4 TSRMLS_CC); PHALCON_INIT_VAR(t3); ZVAL_LONG(t3, 1); PHALCON_INIT_VAR(r5); is_smaller_or_equal_function(r5, t3, render_level TSRMLS_CC); if (zend_is_true(r5)) { PHALCON_CALL_METHOD_PARAMS_3_NORETURN(this_ptr, "_enginerender", engines, render_view, silence, PHALCON_NO_CHECK); } PHALCON_INIT_VAR(t4); ZVAL_LONG(t4, 2); PHALCON_INIT_VAR(r6); is_smaller_or_equal_function(r6, t4, render_level TSRMLS_CC); if (zend_is_true(r6)) { PHALCON_ALLOC_ZVAL_MM(t5); phalcon_read_property(&t5, this_ptr, "_templatesBefore", sizeof("_templatesBefore")-1, PHALCON_NOISY TSRMLS_CC); PHALCON_CPY_WRT(templates_before, t5); if (zend_is_true(templates_before)) { PHALCON_INIT_VAR(silence); ZVAL_BOOL(silence, 0); if (Z_TYPE_P(templates_before) == IS_ARRAY) { if (phalcon_valid_foreach(templates_before TSRMLS_CC)) { ah0 = Z_ARRVAL_P(templates_before); zend_hash_internal_pointer_reset_ex(ah0, &hp0); fes_b0d8_2: if(zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) != SUCCESS){ goto fee_b0d8_2; } PHALCON_INIT_VAR(template_before); ZVAL_ZVAL(template_before, *hd, 1, 0); PHALCON_INIT_VAR(r7); PHALCON_CONCAT_VV(r7, layouts_dir, template_before); PHALCON_CALL_METHOD_PARAMS_3_NORETURN(this_ptr, "_enginerender", engines, r7, silence, PHALCON_NO_CHECK); zend_hash_move_forward_ex(ah0, &hp0); goto fes_b0d8_2; fee_b0d8_2: if(0){} } else { return; } } else { PHALCON_ALLOC_ZVAL_MM(r8); PHALCON_CONCAT_VV(r8, layouts_dir, template_before); PHALCON_CALL_METHOD_PARAMS_3_NORETURN(this_ptr, "_enginerender", engines, r8, silence, PHALCON_NO_CHECK); } PHALCON_INIT_VAR(silence); ZVAL_BOOL(silence, 1); } } PHALCON_INIT_VAR(t6); ZVAL_LONG(t6, 3); PHALCON_INIT_VAR(r9); is_smaller_or_equal_function(r9, t6, render_level TSRMLS_CC); if (zend_is_true(r9)) { PHALCON_ALLOC_ZVAL_MM(r10); PHALCON_CONCAT_VV(r10, layouts_dir, render_controller); PHALCON_CALL_METHOD_PARAMS_3_NORETURN(this_ptr, "_enginerender", engines, r10, silence, PHALCON_NO_CHECK); } PHALCON_INIT_VAR(t7); ZVAL_LONG(t7, 4); PHALCON_INIT_VAR(r11); is_smaller_or_equal_function(r11, t7, render_level TSRMLS_CC); if (zend_is_true(r11)) { PHALCON_ALLOC_ZVAL_MM(t8); phalcon_read_property(&t8, this_ptr, "_templatesAfter", sizeof("_templatesAfter")-1, PHALCON_NOISY TSRMLS_CC); PHALCON_CPY_WRT(templates_after, t8); if (zend_is_true(templates_after)) { PHALCON_INIT_VAR(silence); ZVAL_BOOL(silence, 0); if (Z_TYPE_P(templates_after) == IS_ARRAY) { if (phalcon_valid_foreach(templates_after TSRMLS_CC)) { ah1 = Z_ARRVAL_P(templates_after); zend_hash_internal_pointer_reset_ex(ah1, &hp1); fes_b0d8_3: if(zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) != SUCCESS){ goto fee_b0d8_3; } PHALCON_INIT_VAR(template_after); ZVAL_ZVAL(template_after, *hd, 1, 0); PHALCON_INIT_VAR(r12); PHALCON_CONCAT_VV(r12, layouts_dir, template_after); PHALCON_CALL_METHOD_PARAMS_3_NORETURN(this_ptr, "_enginerender", engines, r12, silence, PHALCON_NO_CHECK); zend_hash_move_forward_ex(ah1, &hp1); goto fes_b0d8_3; fee_b0d8_3: if(0){} } else { return; } } else { PHALCON_ALLOC_ZVAL_MM(r13); PHALCON_CONCAT_VV(r13, layouts_dir, templates_after); PHALCON_CALL_METHOD_PARAMS_3_NORETURN(this_ptr, "_enginerender", engines, r13, silence, PHALCON_NO_CHECK); } PHALCON_INIT_VAR(silence); ZVAL_BOOL(silence, 1); } } PHALCON_INIT_VAR(t9); ZVAL_LONG(t9, 5); PHALCON_INIT_VAR(r14); is_smaller_or_equal_function(r14, t9, render_level TSRMLS_CC); if (zend_is_true(r14)) { PHALCON_ALLOC_ZVAL_MM(t10); phalcon_read_property(&t10, this_ptr, "_mainView", sizeof("_mainView")-1, PHALCON_NOISY TSRMLS_CC); PHALCON_CALL_METHOD_PARAMS_3_NORETURN(this_ptr, "_enginerender", engines, t10, silence, PHALCON_NO_CHECK); } } PHALCON_MM_RESTORE(); }
/** * Rebuild the list of access from the inherit lists * */ PHP_METHOD(Phalcon_Acl_Adapter_Memory, _rebuildAccessList){ zval *roles, *number_roles, *pow_roles, *two, *middle_roles; zval *middle, *roles_names, *roles_inherits; zval *changed = NULL, *i, *internal_access = NULL, *one = NULL, *role_name = NULL; zval *role_inherit = NULL, *inherit_internal = NULL, *access = NULL; zval *resource_name = NULL, *value = NULL, *name = NULL; zval *r0 = NULL, *r1 = NULL, *r2 = NULL, *r3 = NULL, *r4 = NULL; HashTable *ah0, *ah1, *ah2, *ah3; HashPosition hp0, hp1, hp2, hp3; zval **hd; PHALCON_MM_GROW(); PHALCON_OBS_VAR(roles); phalcon_read_property(&roles, this_ptr, SL("_roles"), PH_NOISY_CC); PHALCON_INIT_VAR(number_roles); phalcon_fast_count(number_roles, roles TSRMLS_CC); PHALCON_INIT_VAR(pow_roles); Z_LVAL_P(pow_roles) = Z_LVAL_P(number_roles) * Z_LVAL_P(number_roles); PHALCON_INIT_VAR(two); ZVAL_LONG(two, 2); PHALCON_INIT_VAR(middle_roles); div_function(middle_roles, pow_roles, two TSRMLS_CC); PHALCON_INIT_VAR(middle); PHALCON_CALL_FUNC_PARAMS_1(middle, "ceil", middle_roles); PHALCON_OBS_VAR(roles_names); phalcon_read_property(&roles_names, this_ptr, SL("_rolesNames"), PH_NOISY_CC); PHALCON_OBS_VAR(roles_inherits); phalcon_read_property(&roles_inherits, this_ptr, SL("_roleInherits"), PH_NOISY_CC); PHALCON_INIT_VAR(changed); ZVAL_BOOL(changed, 1); PHALCON_INIT_VAR(i); ZVAL_LONG(i, 0); while (1) { PHALCON_INIT_NVAR(r0); is_smaller_or_equal_function(r0, i, middle TSRMLS_CC); if (!zend_is_true(r0)) { break; } PHALCON_OBS_NVAR(internal_access); phalcon_read_property(&internal_access, this_ptr, SL("_access"), PH_NOISY_CC); if (!phalcon_is_iterable(roles_names, &ah0, &hp0, 0, 0 TSRMLS_CC)) { return; } while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { PHALCON_GET_FOREACH_KEY(role_name, ah0, hp0); PHALCON_GET_FOREACH_VALUE(one); if (phalcon_array_isset(roles_inherits, role_name)) { PHALCON_OBS_NVAR(r1); phalcon_array_fetch(&r1, roles_inherits, role_name, PH_NOISY_CC); if (!phalcon_is_iterable(r1, &ah1, &hp1, 0, 0 TSRMLS_CC)) { return; } while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { PHALCON_GET_FOREACH_VALUE(role_inherit); if (phalcon_array_isset(internal_access, role_inherit)) { PHALCON_OBS_NVAR(inherit_internal); phalcon_array_fetch(&inherit_internal, internal_access, role_inherit, PH_NOISY_CC); if (!phalcon_is_iterable(inherit_internal, &ah2, &hp2, 0, 0 TSRMLS_CC)) { return; } while (zend_hash_get_current_data_ex(ah2, (void**) &hd, &hp2) == SUCCESS) { PHALCON_GET_FOREACH_KEY(resource_name, ah2, hp2); PHALCON_GET_FOREACH_VALUE(access); if (!phalcon_is_iterable(access, &ah3, &hp3, 0, 0 TSRMLS_CC)) { return; } while (zend_hash_get_current_data_ex(ah3, (void**) &hd, &hp3) == SUCCESS) { PHALCON_GET_FOREACH_KEY(name, ah3, hp3); PHALCON_GET_FOREACH_VALUE(value); if (phalcon_array_isset(internal_access, role_name)) { PHALCON_OBS_NVAR(r2); phalcon_array_fetch(&r2, internal_access, role_name, PH_NOISY_CC); if (phalcon_array_isset(r2, resource_name)) { PHALCON_OBS_NVAR(r3); phalcon_array_fetch(&r3, internal_access, role_name, PH_NOISY_CC); PHALCON_OBS_NVAR(r4); phalcon_array_fetch(&r4, r3, resource_name, PH_NOISY_CC); if (phalcon_array_isset(r4, name)) { zend_hash_move_forward_ex(ah3, &hp3); continue; } } } phalcon_array_update_zval_zval_zval_multi_3(&internal_access, role_name, resource_name, name, &value, 0 TSRMLS_CC); PHALCON_INIT_NVAR(changed); ZVAL_BOOL(changed, 1); zend_hash_move_forward_ex(ah3, &hp3); } zend_hash_move_forward_ex(ah2, &hp2); } } zend_hash_move_forward_ex(ah1, &hp1); } } zend_hash_move_forward_ex(ah0, &hp0); } if (zend_is_true(changed)) { phalcon_update_property_zval(this_ptr, SL("_access"), internal_access TSRMLS_CC); } PHALCON_SEPARATE(i); increment_function(i); } PHALCON_MM_RESTORE(); }
/** * Executes render process from dispatching data * *<code> * $view->start(); * //Shows recent posts view (app/views/posts/recent.phtml) * $view->render('posts', 'recent'); * $view->finish(); *</code> * * @param string $controllerName * @param string $actionName * @param array $params */ PHP_METHOD(Phalcon_Mvc_View, render){ zval *controller_name = NULL, *action_name = NULL, *params = NULL; zval *layouts_dir = NULL, *engines = NULL, *pick_view = NULL, *render_view = NULL; zval *render_controller = NULL, *pick_view_action = NULL; zval *cache = NULL, *cache_level = NULL, *events_manager = NULL, *event_name = NULL; zval *status = NULL, *contents = NULL, *must_clean = NULL, *silence = NULL; zval *render_level = NULL, *enter_level = NULL, *templates_before = NULL; zval *template_before = NULL, *view_temp_path = NULL, *templates_after = NULL; zval *template_after = NULL, *main_view = NULL, *is_started = NULL; zval *is_fresh = NULL; zval *t0 = NULL, *t1 = NULL, *t2 = NULL, *t3 = NULL, *t4 = NULL; HashTable *ah0, *ah1; HashPosition hp0, hp1; zval **hd; int eval_int; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz|z", &controller_name, &action_name, ¶ms) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } if (!params) { PHALCON_INIT_VAR(params); array_init(params); } PHALCON_INIT_VAR(layouts_dir); phalcon_read_property(&layouts_dir, this_ptr, SL("_layoutsDir"), PH_NOISY_CC); if (!zend_is_true(layouts_dir)) { PHALCON_INIT_VAR(layouts_dir); ZVAL_STRING(layouts_dir, "layouts/", 1); } phalcon_update_property_zval(this_ptr, SL("_controllerName"), controller_name TSRMLS_CC); phalcon_update_property_zval(this_ptr, SL("_actionName"), action_name TSRMLS_CC); phalcon_update_property_zval(this_ptr, SL("_params"), params TSRMLS_CC); PHALCON_INIT_VAR(engines); PHALCON_CALL_METHOD(engines, this_ptr, "_loadtemplateengines", PH_NO_CHECK); PHALCON_INIT_VAR(pick_view); phalcon_read_property(&pick_view, this_ptr, SL("_pickView"), PH_NOISY_CC); if (Z_TYPE_P(pick_view) == IS_NULL) { PHALCON_INIT_VAR(render_view); PHALCON_CONCAT_VSV(render_view, controller_name, "/", action_name); PHALCON_CPY_WRT(render_controller, controller_name); } else { PHALCON_INIT_VAR(render_view); phalcon_array_fetch_long(&render_view, pick_view, 0, PH_NOISY_CC); eval_int = phalcon_array_isset_long(pick_view, 1); if (eval_int) { PHALCON_INIT_VAR(pick_view_action); phalcon_array_fetch_long(&pick_view_action, pick_view, 1, PH_NOISY_CC); PHALCON_CPY_WRT(render_controller, pick_view_action); } else { PHALCON_CPY_WRT(render_controller, controller_name); } } PHALCON_INIT_VAR(cache); ZVAL_NULL(cache); PHALCON_INIT_VAR(cache_level); phalcon_read_property(&cache_level, this_ptr, SL("_cacheLevel"), PH_NOISY_CC); if (zend_is_true(cache_level)) { PHALCON_INIT_VAR(cache); PHALCON_CALL_METHOD(cache, this_ptr, "getcache", PH_NO_CHECK); } PHALCON_INIT_VAR(events_manager); phalcon_read_property(&events_manager, this_ptr, SL("_eventsManager"), PH_NOISY_CC); if (Z_TYPE_P(events_manager) == IS_OBJECT) { PHALCON_INIT_VAR(event_name); ZVAL_STRING(event_name, "view:beforeRender", 1); PHALCON_INIT_VAR(status); PHALCON_CALL_METHOD_PARAMS_2(status, events_manager, "fire", event_name, this_ptr, PH_NO_CHECK); if (Z_TYPE_P(status) == IS_BOOL && !Z_BVAL_P(status)) { PHALCON_MM_RESTORE(); RETURN_FALSE; } } PHALCON_INIT_VAR(contents); PHALCON_CALL_FUNC(contents, "ob_get_contents"); phalcon_update_property_zval(this_ptr, SL("_content"), contents TSRMLS_CC); PHALCON_INIT_VAR(must_clean); ZVAL_BOOL(must_clean, 1); PHALCON_INIT_VAR(silence); ZVAL_BOOL(silence, 1); PHALCON_INIT_VAR(render_level); phalcon_read_property(&render_level, this_ptr, SL("_renderLevel"), PH_NOISY_CC); if (zend_is_true(render_level)) { PHALCON_INIT_VAR(t0); ZVAL_LONG(t0, 1); PHALCON_INIT_VAR(enter_level); is_smaller_or_equal_function(enter_level, t0, render_level TSRMLS_CC); if (Z_TYPE_P(enter_level) == IS_BOOL && Z_BVAL_P(enter_level)) { PHALCON_CALL_METHOD_PARAMS_5_NORETURN(this_ptr, "_enginerender", engines, render_view, silence, must_clean, cache, PH_NO_CHECK); } PHALCON_INIT_VAR(t1); ZVAL_LONG(t1, 2); PHALCON_INIT_VAR(enter_level); is_smaller_or_equal_function(enter_level, t1, render_level TSRMLS_CC); if (Z_TYPE_P(enter_level) == IS_BOOL && Z_BVAL_P(enter_level)) { PHALCON_INIT_VAR(templates_before); phalcon_read_property(&templates_before, this_ptr, SL("_templatesBefore"), PH_NOISY_CC); if (Z_TYPE_P(templates_before) == IS_ARRAY) { PHALCON_INIT_VAR(silence); ZVAL_BOOL(silence, 0); if (!phalcon_valid_foreach(templates_before TSRMLS_CC)) { return; } ah0 = Z_ARRVAL_P(templates_before); zend_hash_internal_pointer_reset_ex(ah0, &hp0); fes_ecde_2: if(zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) != SUCCESS){ goto fee_ecde_2; } PHALCON_INIT_VAR(template_before); ZVAL_ZVAL(template_before, *hd, 1, 0); PHALCON_INIT_VAR(view_temp_path); PHALCON_CONCAT_VV(view_temp_path, layouts_dir, template_before); PHALCON_CALL_METHOD_PARAMS_5_NORETURN(this_ptr, "_enginerender", engines, view_temp_path, silence, must_clean, cache, PH_NO_CHECK); zend_hash_move_forward_ex(ah0, &hp0); goto fes_ecde_2; fee_ecde_2: PHALCON_INIT_VAR(silence); ZVAL_BOOL(silence, 1); } } PHALCON_INIT_VAR(t2); ZVAL_LONG(t2, 3); PHALCON_INIT_VAR(enter_level); is_smaller_or_equal_function(enter_level, t2, render_level TSRMLS_CC); if (Z_TYPE_P(enter_level) == IS_BOOL && Z_BVAL_P(enter_level)) { PHALCON_INIT_VAR(view_temp_path); PHALCON_CONCAT_VV(view_temp_path, layouts_dir, render_controller); PHALCON_CALL_METHOD_PARAMS_5_NORETURN(this_ptr, "_enginerender", engines, view_temp_path, silence, must_clean, cache, PH_NO_CHECK); } PHALCON_INIT_VAR(t3); ZVAL_LONG(t3, 4); PHALCON_INIT_VAR(enter_level); is_smaller_or_equal_function(enter_level, t3, render_level TSRMLS_CC); if (Z_TYPE_P(enter_level) == IS_BOOL && Z_BVAL_P(enter_level)) { PHALCON_INIT_VAR(templates_after); phalcon_read_property(&templates_after, this_ptr, SL("_templatesAfter"), PH_NOISY_CC); if (Z_TYPE_P(templates_after) == IS_ARRAY) { PHALCON_INIT_VAR(silence); ZVAL_BOOL(silence, 0); if (!phalcon_valid_foreach(templates_after TSRMLS_CC)) { return; } ah1 = Z_ARRVAL_P(templates_after); zend_hash_internal_pointer_reset_ex(ah1, &hp1); fes_ecde_3: if(zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) != SUCCESS){ goto fee_ecde_3; } PHALCON_INIT_VAR(template_after); ZVAL_ZVAL(template_after, *hd, 1, 0); PHALCON_INIT_VAR(view_temp_path); PHALCON_CONCAT_VV(view_temp_path, layouts_dir, template_after); PHALCON_CALL_METHOD_PARAMS_5_NORETURN(this_ptr, "_enginerender", engines, view_temp_path, silence, must_clean, cache, PH_NO_CHECK); zend_hash_move_forward_ex(ah1, &hp1); goto fes_ecde_3; fee_ecde_3: PHALCON_INIT_VAR(silence); ZVAL_BOOL(silence, 1); } } PHALCON_INIT_VAR(t4); ZVAL_LONG(t4, 5); PHALCON_INIT_VAR(enter_level); is_smaller_or_equal_function(enter_level, t4, render_level TSRMLS_CC); if (Z_TYPE_P(enter_level) == IS_BOOL && Z_BVAL_P(enter_level)) { PHALCON_INIT_VAR(main_view); phalcon_read_property(&main_view, this_ptr, SL("_mainView"), PH_NOISY_CC); PHALCON_CALL_METHOD_PARAMS_5_NORETURN(this_ptr, "_enginerender", engines, main_view, silence, must_clean, cache, PH_NO_CHECK); } if (Z_TYPE_P(cache) == IS_OBJECT) { PHALCON_INIT_VAR(is_started); PHALCON_CALL_METHOD(is_started, cache, "isstarted", PH_NO_CHECK); if (zend_is_true(is_started)) { PHALCON_INIT_VAR(is_fresh); PHALCON_CALL_METHOD(is_fresh, cache, "isfresh", PH_NO_CHECK); if (zend_is_true(is_fresh)) { PHALCON_CALL_METHOD_NORETURN(cache, "save", PH_NO_CHECK); } } } } if (Z_TYPE_P(events_manager) == IS_OBJECT) { PHALCON_INIT_VAR(event_name); ZVAL_STRING(event_name, "view:afterRender", 1); PHALCON_CALL_METHOD_PARAMS_2_NORETURN(events_manager, "fire", event_name, this_ptr, PH_NO_CHECK); } PHALCON_MM_RESTORE(); }
/** * Checks whether view exists on registered extensions and render it * * @param array $engines * @param string $viewPath * @param boolean $silence * @param boolean $mustClean * @param Phalcon\Cache\Backend $cache */ PHP_METHOD(Phalcon_Mvc_View, _engineRender){ zval *engines = NULL, *view_path = NULL, *silence = NULL, *must_clean = NULL; zval *cache = NULL, *not_exists = NULL, *view_params = NULL, *views_dir = NULL; zval *base_path = NULL, *views_dir_path = NULL, *events_manager = NULL; zval *render_level = NULL, *cache_level = NULL, *is_started = NULL; zval *key = NULL, *view_options = NULL, *cache_options = NULL, *cached_view = NULL; zval *is_fresh = NULL, *engine = NULL, *extension = NULL, *view_engine_path = NULL; zval *event_name = NULL, *status = NULL, *exception_message = NULL; zval *exception = NULL; zval *r0 = NULL; HashTable *ah0; HashPosition hp0; zval **hd; char *hash_index; uint hash_index_len; ulong hash_num; int hash_type; int eval_int; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zzzzz", &engines, &view_path, &silence, &must_clean, &cache) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } PHALCON_INIT_VAR(not_exists); ZVAL_BOOL(not_exists, 1); PHALCON_INIT_VAR(view_params); phalcon_read_property(&view_params, this_ptr, SL("_viewParams"), PH_NOISY_CC); PHALCON_INIT_VAR(views_dir); phalcon_read_property(&views_dir, this_ptr, SL("_viewsDir"), PH_NOISY_CC); PHALCON_INIT_VAR(base_path); phalcon_read_property(&base_path, this_ptr, SL("_basePath"), PH_NOISY_CC); PHALCON_INIT_VAR(views_dir_path); PHALCON_CONCAT_VVV(views_dir_path, base_path, views_dir, view_path); PHALCON_INIT_VAR(events_manager); phalcon_read_property(&events_manager, this_ptr, SL("_eventsManager"), PH_NOISY_CC); if (Z_TYPE_P(cache) == IS_OBJECT) { PHALCON_INIT_VAR(render_level); phalcon_read_property(&render_level, this_ptr, SL("_renderLevel"), PH_NOISY_CC); PHALCON_INIT_VAR(cache_level); phalcon_read_property(&cache_level, this_ptr, SL("_cacheLevel"), PH_NOISY_CC); PHALCON_ALLOC_ZVAL_MM(r0); is_smaller_or_equal_function(r0, cache_level, render_level TSRMLS_CC); if (zend_is_true(r0)) { PHALCON_INIT_VAR(is_started); PHALCON_CALL_METHOD(is_started, cache, "isstarted", PH_NO_CHECK); if (!zend_is_true(is_started)) { PHALCON_INIT_VAR(key); ZVAL_NULL(key); PHALCON_INIT_VAR(view_options); phalcon_read_property(&view_options, this_ptr, SL("_options"), PH_NOISY_CC); eval_int = phalcon_array_isset_string(view_options, SL("cache")+1); if (eval_int) { PHALCON_INIT_VAR(cache_options); phalcon_array_fetch_string(&cache_options, view_options, SL("cache"), PH_NOISY_CC); if (Z_TYPE_P(cache_options) == IS_ARRAY) { eval_int = phalcon_array_isset_string(cache_options, SL("key")+1); if (eval_int) { PHALCON_INIT_VAR(key); phalcon_array_fetch_string(&key, cache_options, SL("key"), PH_NOISY_CC); } } } if (Z_TYPE_P(key) == IS_NULL) { PHALCON_INIT_VAR(key); PHALCON_CALL_FUNC_PARAMS_1(key, "md5", view_path); } PHALCON_INIT_VAR(cached_view); PHALCON_CALL_METHOD_PARAMS_1(cached_view, cache, "start", key, PH_NO_CHECK); if (Z_TYPE_P(cached_view) != IS_NULL) { phalcon_update_property_zval(this_ptr, SL("_content"), cached_view TSRMLS_CC); PHALCON_MM_RESTORE(); RETURN_NULL(); } } PHALCON_INIT_VAR(is_fresh); PHALCON_CALL_METHOD(is_fresh, cache, "isfresh", PH_NO_CHECK); if (!zend_is_true(is_fresh)) { PHALCON_MM_RESTORE(); RETURN_NULL(); } } } if (!phalcon_valid_foreach(engines TSRMLS_CC)) { return; } ah0 = Z_ARRVAL_P(engines); zend_hash_internal_pointer_reset_ex(ah0, &hp0); fes_ecde_1: if(zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) != SUCCESS){ goto fee_ecde_1; } PHALCON_INIT_VAR(extension); PHALCON_GET_FOREACH_KEY(extension, ah0, hp0); PHALCON_INIT_VAR(engine); ZVAL_ZVAL(engine, *hd, 1, 0); PHALCON_INIT_VAR(view_engine_path); PHALCON_CONCAT_VV(view_engine_path, views_dir_path, extension); if (phalcon_file_exists(view_engine_path TSRMLS_CC) == SUCCESS) { if (Z_TYPE_P(events_manager) == IS_OBJECT) { phalcon_update_property_zval(this_ptr, SL("_activeRenderPath"), view_engine_path TSRMLS_CC); PHALCON_INIT_VAR(event_name); ZVAL_STRING(event_name, "view:beforeRenderView", 1); PHALCON_INIT_VAR(status); PHALCON_CALL_METHOD_PARAMS_2(status, events_manager, "fire", event_name, this_ptr, PH_NO_CHECK); if (Z_TYPE_P(status) == IS_BOOL && !Z_BVAL_P(status)) { zend_hash_move_forward_ex(ah0, &hp0); goto fes_ecde_1; } } PHALCON_CALL_METHOD_PARAMS_3_NORETURN(engine, "render", view_engine_path, view_params, must_clean, PH_NO_CHECK); PHALCON_INIT_VAR(not_exists); ZVAL_BOOL(not_exists, 0); if (Z_TYPE_P(events_manager) == IS_OBJECT) { phalcon_update_property_zval(this_ptr, SL("_activeRenderPath"), view_engine_path TSRMLS_CC); PHALCON_INIT_VAR(event_name); ZVAL_STRING(event_name, "view:afterRenderView", 1); PHALCON_INIT_VAR(status); PHALCON_CALL_METHOD_PARAMS_2(status, events_manager, "fire", event_name, this_ptr, PH_NO_CHECK); if (Z_TYPE_P(status) == IS_BOOL && !Z_BVAL_P(status)) { zend_hash_move_forward_ex(ah0, &hp0); goto fes_ecde_1; } } goto fee_ecde_1; } zend_hash_move_forward_ex(ah0, &hp0); goto fes_ecde_1; fee_ecde_1: if (Z_TYPE_P(not_exists) == IS_BOOL && Z_BVAL_P(not_exists)) { if (!zend_is_true(silence)) { PHALCON_INIT_VAR(exception_message); PHALCON_CONCAT_SVS(exception_message, "View '", views_dir_path, "' was not found in the views directory"); PHALCON_INIT_VAR(exception); object_init_ex(exception, phalcon_mvc_view_exception_ce); PHALCON_CALL_METHOD_PARAMS_1_NORETURN(exception, "__construct", exception_message, PH_CHECK); phalcon_throw_exception(exception TSRMLS_CC); return; } } PHALCON_MM_RESTORE(); }
/** * Executes the validation * * @param string $file * @param int $minsize * @param int $maxsize * @param array $mimes * @param int $minwidth * @param int $maxwidth * @param int $minheight * @param int $maxheight * @return boolean */ PHP_METHOD(Phalcon_Validation_Validator_File, valid) { zval *value, *minsize = NULL, *maxsize = NULL, *mimes = NULL, *minwidth = NULL, *maxwidth = NULL, *minheight = NULL, *maxheight = NULL; zval file = {}, size = {}, *constant, finfo = {}, pathname = {}, mime = {}, image = {}, imageinfo = {}, width = {}, height = {}, valid = {}; zend_class_entry *imagick_ce; phalcon_fetch_params(0, 1, 7, &value, &minsize, &maxsize, &mimes, &minwidth, &maxwidth, &minheight, &maxheight); if (Z_TYPE_P(value) == IS_STRING) { object_init_ex(&file, spl_ce_SplFileInfo); if (phalcon_has_constructor(&file)) { PHALCON_CALL_METHODW(NULL, &file, "__construct", value); } } else if (Z_TYPE_P(value) == IS_OBJECT && instanceof_function_ex(Z_OBJCE_P(value), spl_ce_SplFileInfo, 0)) { PHALCON_CPY_WRT(&file, value); } if (Z_TYPE(file) <= IS_NULL) { phalcon_update_property_str(getThis(), SL("_type"), SL("TypeUnknow")); RETURN_FALSE; } if (!minsize) { minsize = &PHALCON_GLOBAL(z_null); } if (!maxsize) { maxsize = &PHALCON_GLOBAL(z_null); } if (!mimes) { mimes = &PHALCON_GLOBAL(z_null); } if (!minwidth) { minwidth = &PHALCON_GLOBAL(z_null); } if (!maxwidth) { maxwidth = &PHALCON_GLOBAL(z_null); } if (!minheight) { minheight = &PHALCON_GLOBAL(z_null); } if (!maxheight) { maxheight = &PHALCON_GLOBAL(z_null); } PHALCON_CALL_METHODW(&valid, &file, "isfile"); if (!zend_is_true(&valid)) { phalcon_update_property_str(getThis(), SL("_type"), SL("FileValid")); RETURN_FALSE; } PHALCON_CALL_METHODW(&size, &file, "getsize"); if (!PHALCON_IS_EMPTY(minsize)) { is_smaller_or_equal_function(&valid, minsize, &size); if (!zend_is_true(&valid)) { phalcon_update_property_str(getThis(), SL("_type"), SL("TooSmall")); RETURN_FALSE; } } if (!PHALCON_IS_EMPTY(maxsize)) { is_smaller_or_equal_function(&valid, &size, maxsize); if (!zend_is_true(&valid)) { phalcon_update_property_str(getThis(), SL("_type"), SL("TooLarge")); RETURN_FALSE; } } PHALCON_CALL_METHODW(&pathname, &file, "getpathname"); if (Z_TYPE_P(mimes) == IS_ARRAY) { if ((constant = zend_get_constant_str(SL("FILEINFO_MIME_TYPE"))) == NULL) { PHALCON_THROW_EXCEPTION_STRW(phalcon_validation_exception_ce, "Undefined constant `FILEINFO_MIME_TYPE`"); return; } PHALCON_CALL_FUNCTIONW(&finfo, "finfo_open", constant); if (Z_TYPE(finfo) != IS_RESOURCE) { PHALCON_THROW_EXCEPTION_STRW(phalcon_validation_exception_ce, "Opening fileinfo database failed"); return; } PHALCON_CALL_FUNCTIONW(&mime, "finfo_file", &finfo, &pathname); PHALCON_CALL_FUNCTIONW(NULL, "finfo_close", &finfo); if (!phalcon_fast_in_array(&mime, mimes)) { phalcon_update_property_str(getThis(), SL("_type"), SL("MimeValid")); RETURN_FALSE; } } if (phalcon_class_str_exists(SL("imagick"), 0) != NULL) { imagick_ce = phalcon_fetch_str_class(SL("Imagick"), ZEND_FETCH_CLASS_AUTO); object_init_ex(&image, imagick_ce); PHALCON_CALL_METHODW(NULL, &image, "__construct", &pathname); PHALCON_CALL_METHODW(&width, &image, "getImageWidth"); PHALCON_CALL_METHODW(&height, &image, "getImageHeight"); } else if (phalcon_function_exists_ex(SL("getimagesize")) != FAILURE) { PHALCON_CALL_FUNCTIONW(&imageinfo, "getimagesize", &pathname); if (!phalcon_array_isset_fetch_long(&width, &imageinfo, 0)) { ZVAL_LONG(&width, -1); } if (!phalcon_array_isset_fetch_long(&height, &imageinfo, 1)) { ZVAL_LONG(&height, -1); } } else { ZVAL_LONG(&width, -1); ZVAL_LONG(&height, -1); } if (!PHALCON_IS_EMPTY(minwidth)) { is_smaller_or_equal_function(&valid, minwidth, &width); if (!zend_is_true(&valid)) { phalcon_update_property_str(getThis(), SL("_type"), SL("TooNarrow")); RETURN_FALSE; } } if (!PHALCON_IS_EMPTY(maxwidth)) { is_smaller_or_equal_function(&valid, &width, maxwidth); if (!zend_is_true(&valid)) { phalcon_update_property_str(getThis(), SL("_type"), SL("TooWide")); RETURN_FALSE; } } if (!PHALCON_IS_EMPTY(minheight)) { is_smaller_or_equal_function(&valid, minheight, &height); if (!zend_is_true(&valid)) { phalcon_update_property_str(getThis(), SL("_type"), SL("TooShort")); RETURN_FALSE; } } if (!PHALCON_IS_EMPTY(maxheight)) { is_smaller_or_equal_function(&valid, &height, maxheight); if (!zend_is_true(&valid)) { phalcon_update_property_str(getThis(), SL("_type"), SL("TooLong")); RETURN_FALSE; } } RETURN_TRUE; }
/** * Returns a slice of the resultset to show in the pagination * * @return stdClass */ PHP_METHOD(Phalcon_Paginator_Adapter_Model, getPaginate){ zval *one, *zero, *show, *config, *items, *page_number = NULL; zval *smaller, *n, *page, *last_show_page, *start; zval *last_page, *possible_pages = NULL, *total_pages; zval *compare = NULL, *page_items, *i, *valid = NULL, *current = NULL, *maximum_pages; zval *next = NULL, *additional_page, *before = NULL, *remainder; zval *pages_total = NULL; zval *r0 = NULL; PHALCON_MM_GROW(); PHALCON_INIT_VAR(one); ZVAL_LONG(one, 1); PHALCON_INIT_VAR(zero); ZVAL_LONG(zero, 0); PHALCON_OBS_VAR(show); phalcon_read_property(&show, this_ptr, SL("_limitRows"), PH_NOISY_CC); PHALCON_OBS_VAR(config); phalcon_read_property(&config, this_ptr, SL("_config"), PH_NOISY_CC); PHALCON_OBS_VAR(items); phalcon_array_fetch_string(&items, config, SL("data"), PH_NOISY_CC); PHALCON_OBS_VAR(page_number); phalcon_read_property(&page_number, this_ptr, SL("_page"), PH_NOISY_CC); if (Z_TYPE_P(page_number) == IS_NULL) { PHALCON_CPY_WRT(page_number, one); } PHALCON_INIT_VAR(smaller); is_smaller_function(smaller, show, zero TSRMLS_CC); if (PHALCON_IS_TRUE(smaller)) { PHALCON_THROW_EXCEPTION_STR(phalcon_paginator_exception_ce, "The start page number is zero or less"); return; } PHALCON_INIT_VAR(n); phalcon_fast_count(n, items TSRMLS_CC); PHALCON_INIT_VAR(page); object_init(page); PHALCON_INIT_VAR(last_show_page); sub_function(last_show_page, page_number, one TSRMLS_CC); PHALCON_INIT_VAR(start); mul_function(start, show, last_show_page TSRMLS_CC); PHALCON_INIT_VAR(last_page); sub_function(last_page, n, one TSRMLS_CC); PHALCON_INIT_VAR(possible_pages); div_function(possible_pages, last_page, show TSRMLS_CC); PHALCON_INIT_VAR(total_pages); PHALCON_CALL_FUNC_PARAMS_1(total_pages, "ceil", possible_pages); if (Z_TYPE_P(items) != IS_OBJECT) { PHALCON_THROW_EXCEPTION_STR(phalcon_paginator_exception_ce, "Invalid data for paginator"); return; } if (Z_TYPE_P(page_number) == IS_NULL) { PHALCON_CPY_WRT(page_number, zero); } PHALCON_INIT_VAR(compare); is_smaller_function(compare, start, zero TSRMLS_CC); if (PHALCON_IS_TRUE(compare)) { PHALCON_THROW_EXCEPTION_STR(phalcon_paginator_exception_ce, "The start page number is zero or less"); return; } PHALCON_INIT_VAR(page_items); array_init(page_items); is_smaller_function(compare, zero, n TSRMLS_CC); if (PHALCON_IS_TRUE(compare)) { /** * Seek to the desired position */ is_smaller_or_equal_function(compare, start, n TSRMLS_CC); if (PHALCON_IS_TRUE(compare)) { PHALCON_CALL_METHOD_PARAMS_1_NORETURN(items, "seek", start); } else { PHALCON_CALL_METHOD_PARAMS_1_NORETURN(items, "seek", one); PHALCON_CPY_WRT(page_number, one); } /** * The record must be iterable */ PHALCON_INIT_VAR(i); ZVAL_LONG(i, 1); while (1) { PHALCON_INIT_NVAR(r0); PHALCON_CALL_METHOD(r0, items, "valid"); PHALCON_CPY_WRT(valid, r0); if (PHALCON_IS_NOT_FALSE(valid)) { } else { break; } PHALCON_INIT_NVAR(current); PHALCON_CALL_METHOD(current, items, "current"); phalcon_array_append(&page_items, current, PH_SEPARATE TSRMLS_CC); PHALCON_INIT_NVAR(compare); is_smaller_or_equal_function(compare, show, i TSRMLS_CC); if (PHALCON_IS_TRUE(compare)) { break; } PHALCON_SEPARATE(i); increment_function(i); } } phalcon_update_property_zval(page, SL("items"), page_items TSRMLS_CC); phalcon_update_property_zval(page, SL("first"), one TSRMLS_CC); PHALCON_INIT_VAR(maximum_pages); phalcon_add_function(maximum_pages, start, show TSRMLS_CC); is_smaller_function(compare, maximum_pages, n TSRMLS_CC); if (PHALCON_IS_TRUE(compare)) { PHALCON_INIT_VAR(next); phalcon_add_function(next, page_number, one TSRMLS_CC); } else { is_equal_function(compare, maximum_pages, n TSRMLS_CC); if (PHALCON_IS_TRUE(compare)) { PHALCON_CPY_WRT(next, n); } else { div_function(possible_pages, n, show TSRMLS_CC); PHALCON_INIT_VAR(additional_page); phalcon_add_function(additional_page, possible_pages, one TSRMLS_CC); PHALCON_INIT_NVAR(next); PHALCON_CALL_FUNC_PARAMS_1(next, "intval", additional_page); } } is_smaller_function(compare, total_pages, next TSRMLS_CC); if (PHALCON_IS_TRUE(compare)) { PHALCON_CPY_WRT(next, total_pages); } phalcon_update_property_zval(page, SL("next"), next TSRMLS_CC); is_smaller_function(compare, one, page_number TSRMLS_CC); if (PHALCON_IS_TRUE(compare)) { PHALCON_INIT_VAR(before); sub_function(before, page_number, one TSRMLS_CC); } else { PHALCON_CPY_WRT(before, one); } phalcon_update_property_zval(page, SL("before"), before TSRMLS_CC); phalcon_update_property_zval(page, SL("current"), page_number TSRMLS_CC); PHALCON_INIT_VAR(remainder); mod_function(remainder, n, show TSRMLS_CC); div_function(possible_pages, n, show TSRMLS_CC); if (!PHALCON_IS_LONG(remainder, 0)) { PHALCON_INIT_NVAR(next); phalcon_add_function(next, possible_pages, one TSRMLS_CC); PHALCON_INIT_VAR(pages_total); PHALCON_CALL_FUNC_PARAMS_1(pages_total, "intval", next); } else { PHALCON_CPY_WRT(pages_total, possible_pages); } phalcon_update_property_zval(page, SL("last"), pages_total TSRMLS_CC); phalcon_update_property_zval(page, SL("total_pages"), pages_total TSRMLS_CC); RETURN_CTOR(page); }
/** * Executes render process from dispatching data * *<code> * $view->start(); * //Shows recent posts view (app/views/posts/recent.phtml) * $view->render('posts', 'recent'); * $view->finish(); *</code> * * @param string $controllerName * @param string $actionName * @param array $params */ PHP_METHOD(Phalcon_Mvc_View, render){ zval *controller_name, *action_name, *params = NULL; zval *disabled, *contents = NULL, *layouts_dir = NULL, *layout; zval *layout_name = NULL, *engines, *pick_view, *render_view = NULL; zval *pick_view_action, *cache = NULL, *cache_level; zval *events_manager, *event_name = NULL, *status, *must_clean; zval *silence = NULL, *disabled_levels, *render_level; zval *enter_level = NULL, *templates_before, *template_before = NULL; zval *view_temp_path = NULL, *templates_after, *template_after = NULL; zval *main_view, *is_started, *is_fresh; zval *t0 = NULL, *t1 = NULL, *t2 = NULL, *t3 = NULL, *t4 = NULL; HashTable *ah0, *ah1; HashPosition hp0, hp1; zval **hd; PHALCON_MM_GROW(); phalcon_fetch_params(1, 2, 1, &controller_name, &action_name, ¶ms); if (!params) { PHALCON_INIT_VAR(params); } /** * If the view is disabled we simply update the buffer from any output produced in * the controller */ PHALCON_OBS_VAR(disabled); phalcon_read_property_this(&disabled, this_ptr, SL("_disabled"), PH_NOISY_CC); if (PHALCON_IS_NOT_FALSE(disabled)) { PHALCON_INIT_VAR(contents); PHALCON_CALL_FUNC(contents, "ob_get_contents"); phalcon_update_property_this(this_ptr, SL("_content"), contents TSRMLS_CC); RETURN_MM_FALSE; } phalcon_update_property_this(this_ptr, SL("_controllerName"), controller_name TSRMLS_CC); phalcon_update_property_this(this_ptr, SL("_actionName"), action_name TSRMLS_CC); phalcon_update_property_this(this_ptr, SL("_params"), params TSRMLS_CC); /** * Check if there is a layouts directory set */ PHALCON_OBS_VAR(layouts_dir); phalcon_read_property_this(&layouts_dir, this_ptr, SL("_layoutsDir"), PH_NOISY_CC); if (!zend_is_true(layouts_dir)) { PHALCON_INIT_NVAR(layouts_dir); ZVAL_STRING(layouts_dir, "layouts/", 1); } /** * Check if the user has defined a custom layout */ PHALCON_OBS_VAR(layout); phalcon_read_property_this(&layout, this_ptr, SL("_layout"), PH_NOISY_CC); if (zend_is_true(layout)) { PHALCON_CPY_WRT(layout_name, layout); } else { PHALCON_CPY_WRT(layout_name, controller_name); } /** * Load the template engines */ PHALCON_INIT_VAR(engines); PHALCON_CALL_METHOD(engines, this_ptr, "_loadtemplateengines"); /** * Check if the user has picked a view diferent than the automatic */ PHALCON_OBS_VAR(pick_view); phalcon_read_property_this(&pick_view, this_ptr, SL("_pickView"), PH_NOISY_CC); if (Z_TYPE_P(pick_view) == IS_NULL) { PHALCON_INIT_VAR(render_view); PHALCON_CONCAT_VSV(render_view, controller_name, "/", action_name); } else { /** * The 'picked' view is an array, where the first element is controller and the * second the action */ PHALCON_OBS_NVAR(render_view); phalcon_array_fetch_long(&render_view, pick_view, 0, PH_NOISY_CC); if (phalcon_array_isset_long(pick_view, 1)) { PHALCON_OBS_VAR(pick_view_action); phalcon_array_fetch_long(&pick_view_action, pick_view, 1, PH_NOISY_CC); PHALCON_CPY_WRT(layout_name, pick_view_action); } } PHALCON_INIT_VAR(cache); /** * Start the cache if there is a cache level enabled */ PHALCON_OBS_VAR(cache_level); phalcon_read_property_this(&cache_level, this_ptr, SL("_cacheLevel"), PH_NOISY_CC); if (zend_is_true(cache_level)) { PHALCON_CALL_METHOD(cache, this_ptr, "getcache"); } PHALCON_OBS_VAR(events_manager); phalcon_read_property_this(&events_manager, this_ptr, SL("_eventsManager"), PH_NOISY_CC); /** * Create a virtual symbol table */ phalcon_create_symbol_table(TSRMLS_C); /** * Call beforeRender if there is an events manager */ if (Z_TYPE_P(events_manager) == IS_OBJECT) { PHALCON_INIT_VAR(event_name); ZVAL_STRING(event_name, "view:beforeRender", 1); PHALCON_INIT_VAR(status); PHALCON_CALL_METHOD_PARAMS_2(status, events_manager, "fire", event_name, this_ptr); if (PHALCON_IS_FALSE(status)) { RETURN_MM_FALSE; } } /** * Get the current content in the buffer maybe some output from the controller */ PHALCON_INIT_NVAR(contents); PHALCON_CALL_FUNC(contents, "ob_get_contents"); phalcon_update_property_this(this_ptr, SL("_content"), contents TSRMLS_CC); PHALCON_INIT_VAR(must_clean); ZVAL_BOOL(must_clean, 1); PHALCON_INIT_VAR(silence); ZVAL_BOOL(silence, 1); /** * Disabled levels allow to avoid an specific level of rendering */ PHALCON_OBS_VAR(disabled_levels); phalcon_read_property_this(&disabled_levels, this_ptr, SL("_disabledLevels"), PH_NOISY_CC); /** * Render level will tell use when to stop */ PHALCON_OBS_VAR(render_level); phalcon_read_property_this(&render_level, this_ptr, SL("_renderLevel"), PH_NOISY_CC); if (zend_is_true(render_level)) { /** * Inserts view related to action */ PHALCON_INIT_VAR(t0); ZVAL_LONG(t0, 1); PHALCON_INIT_VAR(enter_level); is_smaller_or_equal_function(enter_level, t0, render_level TSRMLS_CC); if (PHALCON_IS_TRUE(enter_level)) { if (!phalcon_array_isset_long(disabled_levels, 1)) { PHALCON_CALL_METHOD_PARAMS_5_NORETURN(this_ptr, "_enginerender", engines, render_view, silence, must_clean, cache); } } /** * Inserts templates before layout */ PHALCON_INIT_VAR(t1); ZVAL_LONG(t1, 2); PHALCON_INIT_NVAR(enter_level); is_smaller_or_equal_function(enter_level, t1, render_level TSRMLS_CC); if (PHALCON_IS_TRUE(enter_level)) { if (!phalcon_array_isset_long(disabled_levels, 2)) { PHALCON_OBS_VAR(templates_before); phalcon_read_property_this(&templates_before, this_ptr, SL("_templatesBefore"), PH_NOISY_CC); /** * Templates before must be an array */ if (Z_TYPE_P(templates_before) == IS_ARRAY) { ZVAL_BOOL(silence, 0); if (!phalcon_is_iterable(templates_before, &ah0, &hp0, 0, 0 TSRMLS_CC)) { return; } while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { PHALCON_GET_FOREACH_VALUE(template_before); PHALCON_INIT_NVAR(view_temp_path); PHALCON_CONCAT_VV(view_temp_path, layouts_dir, template_before); PHALCON_CALL_METHOD_PARAMS_5_NORETURN(this_ptr, "_enginerender", engines, view_temp_path, silence, must_clean, cache); zend_hash_move_forward_ex(ah0, &hp0); } ZVAL_BOOL(silence, 1); } } } /** * Inserts controller layout */ PHALCON_INIT_VAR(t2); ZVAL_LONG(t2, 3); PHALCON_INIT_NVAR(enter_level); is_smaller_or_equal_function(enter_level, t2, render_level TSRMLS_CC); if (PHALCON_IS_TRUE(enter_level)) { if (!phalcon_array_isset_long(disabled_levels, 3)) { PHALCON_INIT_NVAR(view_temp_path); PHALCON_CONCAT_VV(view_temp_path, layouts_dir, layout_name); PHALCON_CALL_METHOD_PARAMS_5_NORETURN(this_ptr, "_enginerender", engines, view_temp_path, silence, must_clean, cache); } } /** * Inserts templates after layout */ PHALCON_INIT_VAR(t3); ZVAL_LONG(t3, 4); PHALCON_INIT_NVAR(enter_level); is_smaller_or_equal_function(enter_level, t3, render_level TSRMLS_CC); if (PHALCON_IS_TRUE(enter_level)) { if (!phalcon_array_isset_long(disabled_levels, 4)) { /** * Templates after must be an array */ PHALCON_OBS_VAR(templates_after); phalcon_read_property_this(&templates_after, this_ptr, SL("_templatesAfter"), PH_NOISY_CC); if (Z_TYPE_P(templates_after) == IS_ARRAY) { ZVAL_BOOL(silence, 0); if (!phalcon_is_iterable(templates_after, &ah1, &hp1, 0, 0 TSRMLS_CC)) { return; } while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { PHALCON_GET_FOREACH_VALUE(template_after); PHALCON_INIT_NVAR(view_temp_path); PHALCON_CONCAT_VV(view_temp_path, layouts_dir, template_after); PHALCON_CALL_METHOD_PARAMS_5_NORETURN(this_ptr, "_enginerender", engines, view_temp_path, silence, must_clean, cache); zend_hash_move_forward_ex(ah1, &hp1); } ZVAL_BOOL(silence, 1); } } } /** * Inserts main view */ PHALCON_INIT_VAR(t4); ZVAL_LONG(t4, 5); PHALCON_INIT_NVAR(enter_level); is_smaller_or_equal_function(enter_level, t4, render_level TSRMLS_CC); if (PHALCON_IS_TRUE(enter_level)) { if (!phalcon_array_isset_long(disabled_levels, 5)) { PHALCON_OBS_VAR(main_view); phalcon_read_property_this(&main_view, this_ptr, SL("_mainView"), PH_NOISY_CC); PHALCON_CALL_METHOD_PARAMS_5_NORETURN(this_ptr, "_enginerender", engines, main_view, silence, must_clean, cache); } } /** * Store the data in the cache */ if (Z_TYPE_P(cache) == IS_OBJECT) { PHALCON_INIT_VAR(is_started); PHALCON_CALL_METHOD(is_started, cache, "isstarted"); if (PHALCON_IS_TRUE(is_started)) { PHALCON_INIT_VAR(is_fresh); PHALCON_CALL_METHOD(is_fresh, cache, "isfresh"); if (PHALCON_IS_TRUE(is_fresh)) { PHALCON_CALL_METHOD_NORETURN(cache, "save"); } else { PHALCON_CALL_METHOD_NORETURN(cache, "stop"); } } else { PHALCON_CALL_METHOD_NORETURN(cache, "stop"); } } } /** * Call afterRender event */ if (Z_TYPE_P(events_manager) == IS_OBJECT) { PHALCON_INIT_NVAR(event_name); ZVAL_STRING(event_name, "view:afterRender", 1); PHALCON_CALL_METHOD_PARAMS_2_NORETURN(events_manager, "fire", event_name, this_ptr); } RETURN_MM_NULL(); }
/** * Checks whether view exists on registered extensions and render it * * @param array $engines * @param string $viewPath * @param boolean $silence * @param boolean $mustClean * @param Phalcon\Cache\BackendInterface $cache */ 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, *enter_cache; zval *is_started, *key = NULL, *lifetime = NULL, *view_options; zval *cache_options, *cached_view, *is_fresh; zval *engine = NULL, *extension = NULL, *view_engine_path = NULL; zval *event_name = NULL, *status = NULL, *exception_message; HashTable *ah0; HashPosition hp0; zval **hd; PHALCON_MM_GROW(); phalcon_fetch_params(1, 5, 0, &engines, &view_path, &silence, &must_clean, &cache); PHALCON_INIT_VAR(not_exists); ZVAL_BOOL(not_exists, 1); PHALCON_OBS_VAR(view_params); phalcon_read_property_this(&view_params, this_ptr, SL("_viewParams"), PH_NOISY_CC); PHALCON_OBS_VAR(views_dir); phalcon_read_property_this(&views_dir, this_ptr, SL("_viewsDir"), PH_NOISY_CC); PHALCON_OBS_VAR(base_path); phalcon_read_property_this(&base_path, this_ptr, SL("_basePath"), PH_NOISY_CC); PHALCON_INIT_VAR(views_dir_path); PHALCON_CONCAT_VVV(views_dir_path, base_path, views_dir, view_path); PHALCON_OBS_VAR(events_manager); phalcon_read_property_this(&events_manager, this_ptr, SL("_eventsManager"), PH_NOISY_CC); if (Z_TYPE_P(cache) == IS_OBJECT) { PHALCON_OBS_VAR(render_level); phalcon_read_property_this(&render_level, this_ptr, SL("_renderLevel"), PH_NOISY_CC); PHALCON_OBS_VAR(cache_level); phalcon_read_property_this(&cache_level, this_ptr, SL("_cacheLevel"), PH_NOISY_CC); /** * Evaluate if we need to enter in 'cache' mode */ PHALCON_INIT_VAR(enter_cache); is_smaller_or_equal_function(enter_cache, cache_level, render_level TSRMLS_CC); if (zend_is_true(enter_cache)) { /** * Check if the cache is started, the first time a cache is started we start the * cache */ PHALCON_INIT_VAR(is_started); PHALCON_CALL_METHOD(is_started, cache, "isstarted"); if (PHALCON_IS_FALSE(is_started)) { PHALCON_INIT_VAR(key); PHALCON_INIT_VAR(lifetime); PHALCON_OBS_VAR(view_options); phalcon_read_property_this(&view_options, this_ptr, SL("_options"), PH_NOISY_CC); /** * Check if the user has defined a different options to the default */ if (Z_TYPE_P(view_options) == IS_ARRAY) { if (phalcon_array_isset_string(view_options, SS("cache"))) { PHALCON_OBS_VAR(cache_options); phalcon_array_fetch_string(&cache_options, view_options, SL("cache"), PH_NOISY_CC); if (Z_TYPE_P(cache_options) == IS_ARRAY) { if (phalcon_array_isset_string(cache_options, SS("key"))) { PHALCON_OBS_NVAR(key); phalcon_array_fetch_string(&key, cache_options, SL("key"), PH_NOISY_CC); } if (phalcon_array_isset_string(cache_options, SS("lifetime"))) { PHALCON_OBS_NVAR(lifetime); phalcon_array_fetch_string(&lifetime, cache_options, SL("lifetime"), PH_NOISY_CC); } } } } /** * If a cache key is not set we create one using a md5 */ if (Z_TYPE_P(key) == IS_NULL) { PHALCON_INIT_NVAR(key); PHALCON_CALL_FUNC_PARAMS_1(key, "md5", view_path); } /** * We start the cache using the key set */ PHALCON_INIT_VAR(cached_view); PHALCON_CALL_METHOD_PARAMS_2(cached_view, cache, "start", key, lifetime); if (Z_TYPE_P(cached_view) != IS_NULL) { phalcon_update_property_this(this_ptr, SL("_content"), cached_view TSRMLS_CC); RETURN_MM_NULL(); } } /** * This method only returns true if the cache has not expired */ PHALCON_INIT_VAR(is_fresh); PHALCON_CALL_METHOD(is_fresh, cache, "isfresh"); if (!zend_is_true(is_fresh)) { RETURN_MM_NULL(); } } } /** * Views are rendered in each engine */ if (!phalcon_is_iterable(engines, &ah0, &hp0, 0, 0 TSRMLS_CC)) { return; } while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { PHALCON_GET_FOREACH_KEY(extension, ah0, hp0); PHALCON_GET_FOREACH_VALUE(engine); PHALCON_INIT_NVAR(view_engine_path); PHALCON_CONCAT_VV(view_engine_path, views_dir_path, extension); if (phalcon_file_exists(view_engine_path TSRMLS_CC) == SUCCESS) { /** * Call beforeRenderView if there is a events manager available */ if (Z_TYPE_P(events_manager) == IS_OBJECT) { phalcon_update_property_this(this_ptr, SL("_activeRenderPath"), view_engine_path TSRMLS_CC); PHALCON_INIT_NVAR(event_name); ZVAL_STRING(event_name, "view:beforeRenderView", 1); PHALCON_INIT_NVAR(status); PHALCON_CALL_METHOD_PARAMS_3(status, events_manager, "fire", event_name, this_ptr, view_engine_path); if (PHALCON_IS_FALSE(status)) { zend_hash_move_forward_ex(ah0, &hp0); continue; } } PHALCON_CALL_METHOD_PARAMS_3_NORETURN(engine, "render", view_engine_path, view_params, must_clean); /** * Call afterRenderView if there is a events manager available */ PHALCON_INIT_NVAR(not_exists); ZVAL_BOOL(not_exists, 0); if (Z_TYPE_P(events_manager) == IS_OBJECT) { PHALCON_INIT_NVAR(event_name); ZVAL_STRING(event_name, "view:afterRenderView", 1); PHALCON_CALL_METHOD_PARAMS_2_NORETURN(events_manager, "fire", event_name, this_ptr); } break; } zend_hash_move_forward_ex(ah0, &hp0); } if (PHALCON_IS_TRUE(not_exists)) { /** * Notify about not found views */ if (Z_TYPE_P(events_manager) == IS_OBJECT) { phalcon_update_property_this(this_ptr, SL("_activeRenderPath"), view_engine_path TSRMLS_CC); PHALCON_INIT_NVAR(event_name); ZVAL_STRING(event_name, "view:notFoundView", 1); PHALCON_CALL_METHOD_PARAMS_2_NORETURN(events_manager, "fire", event_name, this_ptr); } if (!zend_is_true(silence)) { PHALCON_INIT_VAR(exception_message); PHALCON_CONCAT_SVS(exception_message, "View '", views_dir_path, "' was not found in the views directory"); PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_view_exception_ce, exception_message); return; } } PHALCON_MM_RESTORE(); }