/** * Concatenates strings using the separator only once without duplication in places concatenation * * <code> * $str = Phalcon\Text::concat("/", "/tmp/", "/folder_1/", "/folder_2", "folder_3/"); * echo $str; // /tmp/folder_1/folder_2/folder_3/ * </code> * * @param string separator * @param string a * @param string b * @param string ...N */ PHP_METHOD(Phalcon_Text, concat) { HashTable *_6; HashPosition _5; int ZEPHIR_LAST_CALL_STATUS; zephir_fcall_cache_entry *_1 = NULL; zval *separator = NULL, *a = NULL, *b = NULL, _0 = zval_used_for_init, *c = NULL, *_2 = NULL, *_3 = NULL, *_4 = NULL, **_7, *_8 = NULL, *_9 = NULL, *_10 = NULL; ZEPHIR_MM_GROW(); ZEPHIR_SINIT_VAR(_0); ZVAL_LONG(&_0, 0); ZEPHIR_CALL_FUNCTION(&separator, "func_get_arg", &_1, 418, &_0); zephir_check_call_status(); ZEPHIR_SINIT_NVAR(_0); ZVAL_LONG(&_0, 1); ZEPHIR_CALL_FUNCTION(&a, "func_get_arg", &_1, 418, &_0); zephir_check_call_status(); ZEPHIR_SINIT_NVAR(_0); ZVAL_LONG(&_0, 2); ZEPHIR_CALL_FUNCTION(&b, "func_get_arg", &_1, 418, &_0); zephir_check_call_status(); ZEPHIR_CALL_FUNCTION(&_2, "func_num_args", NULL, 419); zephir_check_call_status(); if (ZEPHIR_GT_LONG(_2, 3)) { ZEPHIR_CALL_FUNCTION(&_3, "func_get_args", NULL, 165); zephir_check_call_status(); ZEPHIR_SINIT_NVAR(_0); ZVAL_LONG(&_0, 3); ZEPHIR_CALL_FUNCTION(&_4, "array_slice", NULL, 377, _3, &_0); zephir_check_call_status(); zephir_is_iterable(_4, &_6, &_5, 0, 0, "phalcon/text.zep", 246); for ( ; zephir_hash_get_current_data_ex(_6, (void**) &_7, &_5) == SUCCESS ; zephir_hash_move_forward_ex(_6, &_5) ) { ZEPHIR_GET_HVALUE(c, _7); ZEPHIR_INIT_NVAR(_8); zephir_fast_trim(_8, b, separator, ZEPHIR_TRIM_RIGHT TSRMLS_CC); ZEPHIR_INIT_NVAR(_9); zephir_fast_trim(_9, c, separator, ZEPHIR_TRIM_LEFT TSRMLS_CC); ZEPHIR_INIT_LNVAR(_10); ZEPHIR_CONCAT_VVV(_10, _8, separator, _9); ZEPHIR_CPY_WRT(b, _10); } } ZEPHIR_INIT_NVAR(_8); zephir_fast_trim(_8, a, separator, ZEPHIR_TRIM_RIGHT TSRMLS_CC); ZEPHIR_INIT_NVAR(_9); zephir_fast_trim(_9, b, separator, ZEPHIR_TRIM_LEFT TSRMLS_CC); ZEPHIR_CONCAT_VVV(return_value, _8, separator, _9); RETURN_MM(); }
/** * Concatenates strings using the separator only once without duplication in places concatenation * * <code> * $str = Phalcon\Text::concat("/", "/tmp/", "/folder_1/", "/folder_2", "folder_3/"); * echo $str; // /tmp/folder_1/folder_2/folder_3/ * </code> * * @param string separator * @param string a * @param string b * @param string ...N */ PHP_METHOD(Phalcon_Text, concat) { HashTable *_7$$3; HashPosition _6$$3; zval *separator = NULL, *a = NULL, *b = NULL, _0 = zval_used_for_init, *c = NULL, *_2 = NULL, *_12, *_13, *_3$$3 = NULL, _4$$3, *_5$$3 = NULL, **_8$$3, *_9$$4 = NULL, *_10$$4 = NULL, *_11$$4 = NULL; int ZEPHIR_LAST_CALL_STATUS; zephir_fcall_cache_entry *_1 = NULL; ZEPHIR_MM_GROW(); ZEPHIR_SINIT_VAR(_0); ZVAL_LONG(&_0, 0); ZEPHIR_CALL_FUNCTION(&separator, "func_get_arg", &_1, 443, &_0); zephir_check_call_status(); ZEPHIR_SINIT_NVAR(_0); ZVAL_LONG(&_0, 1); ZEPHIR_CALL_FUNCTION(&a, "func_get_arg", &_1, 443, &_0); zephir_check_call_status(); ZEPHIR_SINIT_NVAR(_0); ZVAL_LONG(&_0, 2); ZEPHIR_CALL_FUNCTION(&b, "func_get_arg", &_1, 443, &_0); zephir_check_call_status(); ZEPHIR_CALL_FUNCTION(&_2, "func_num_args", NULL, 444); zephir_check_call_status(); if (ZEPHIR_GT_LONG(_2, 3)) { ZEPHIR_CALL_FUNCTION(&_3$$3, "func_get_args", NULL, 172); zephir_check_call_status(); ZEPHIR_SINIT_VAR(_4$$3); ZVAL_LONG(&_4$$3, 3); ZEPHIR_CALL_FUNCTION(&_5$$3, "array_slice", NULL, 391, _3$$3, &_4$$3); zephir_check_call_status(); zephir_is_iterable(_5$$3, &_7$$3, &_6$$3, 0, 0, "phalcon/text.zep", 245); for ( ; zephir_hash_get_current_data_ex(_7$$3, (void**) &_8$$3, &_6$$3) == SUCCESS ; zephir_hash_move_forward_ex(_7$$3, &_6$$3) ) { ZEPHIR_GET_HVALUE(c, _8$$3); ZEPHIR_INIT_NVAR(_9$$4); zephir_fast_trim(_9$$4, b, separator, ZEPHIR_TRIM_RIGHT TSRMLS_CC); ZEPHIR_INIT_NVAR(_10$$4); zephir_fast_trim(_10$$4, c, separator, ZEPHIR_TRIM_LEFT TSRMLS_CC); ZEPHIR_INIT_LNVAR(_11$$4); ZEPHIR_CONCAT_VVV(_11$$4, _9$$4, separator, _10$$4); ZEPHIR_CPY_WRT(b, _11$$4); } } ZEPHIR_INIT_VAR(_12); zephir_fast_trim(_12, a, separator, ZEPHIR_TRIM_RIGHT TSRMLS_CC); ZEPHIR_INIT_VAR(_13); zephir_fast_trim(_13, b, separator, ZEPHIR_TRIM_LEFT TSRMLS_CC); ZEPHIR_CONCAT_VVV(return_value, _12, separator, _13); RETURN_MM(); }
/** * Concatenates strings using the separator only once without duplication in places concatenation * * <code> * $str = Phalcon\Text::concat( * "/", * "/tmp/", * "/folder_1/", * "/folder_2", * "folder_3/" * ); * * // /tmp/folder_1/folder_2/folder_3/ * echo $str; * </code> * * @param string separator * @param string a * @param string b * @param string ...N */ PHP_METHOD(Phalcon_Text, concat) { HashTable *_7$$3; HashPosition _6$$3; zval *separator = NULL, *a = NULL, *b = NULL, _0, _1, _2, *c = NULL, *_12, *_13, *_3$$3, _4$$3, *_5$$3 = NULL, **_8$$3, *_9$$4 = NULL, *_10$$4 = NULL, *_11$$4 = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; ZEPHIR_MM_GROW(); ZEPHIR_INIT_VAR(separator); ZEPHIR_SINIT_VAR(_0); ZVAL_LONG(&_0, 0); zephir_get_arg(separator, zephir_get_intval(&_0) TSRMLS_CC); ZEPHIR_INIT_VAR(a); ZEPHIR_SINIT_VAR(_1); ZVAL_LONG(&_1, 1); zephir_get_arg(a, zephir_get_intval(&_1) TSRMLS_CC); ZEPHIR_INIT_VAR(b); ZEPHIR_SINIT_VAR(_2); ZVAL_LONG(&_2, 2); zephir_get_arg(b, zephir_get_intval(&_2) TSRMLS_CC); if (ZEND_NUM_ARGS() > 3) { ZEPHIR_INIT_VAR(_3$$3); zephir_get_args(_3$$3 TSRMLS_CC); ZEPHIR_SINIT_VAR(_4$$3); ZVAL_LONG(&_4$$3, 3); ZEPHIR_CALL_FUNCTION(&_5$$3, "array_slice", NULL, 406, _3$$3, &_4$$3); zephir_check_call_status(); zephir_is_iterable(_5$$3, &_7$$3, &_6$$3, 0, 0, "phalcon/text.zep", 262); for ( ; zend_hash_get_current_data_ex(_7$$3, (void**) &_8$$3, &_6$$3) == SUCCESS ; zend_hash_move_forward_ex(_7$$3, &_6$$3) ) { ZEPHIR_GET_HVALUE(c, _8$$3); ZEPHIR_INIT_NVAR(_9$$4); zephir_fast_trim(_9$$4, b, separator, ZEPHIR_TRIM_RIGHT TSRMLS_CC); ZEPHIR_INIT_NVAR(_10$$4); zephir_fast_trim(_10$$4, c, separator, ZEPHIR_TRIM_LEFT TSRMLS_CC); ZEPHIR_INIT_LNVAR(_11$$4); ZEPHIR_CONCAT_VVV(_11$$4, _9$$4, separator, _10$$4); ZEPHIR_CPY_WRT(b, _11$$4); } } ZEPHIR_INIT_VAR(_12); zephir_fast_trim(_12, a, separator, ZEPHIR_TRIM_RIGHT TSRMLS_CC); ZEPHIR_INIT_VAR(_13); zephir_fast_trim(_13, b, separator, ZEPHIR_TRIM_LEFT TSRMLS_CC); ZEPHIR_CONCAT_VVV(return_value, _12, separator, _13); RETURN_MM(); }
/** * Gets a list of columns with escaped identifiers * *<code> * echo $dialect->getColumnList(array('column1', 'column')); *</code> * * @param array columnList * @return string */ PHP_METHOD(Pdm_Db_AbstractDialect, getColumnList) { HashTable *_2; HashPosition _1; zval *columnList, *strList, *escapeChar = NULL, *column = NULL, *_0, **_3, *_4 = NULL; ZEPHIR_MM_GROW(); zephir_fetch_params(1, 1, 0, &columnList); ZEPHIR_INIT_VAR(strList); array_init(strList); _0 = zephir_fetch_nproperty_this(this_ptr, SL("escapeChar"), PH_NOISY_CC); ZEPHIR_CPY_WRT(escapeChar, _0); zephir_is_iterable(columnList, &_2, &_1, 0, 0); for ( ; zephir_hash_get_current_data_ex(_2, (void**) &_3, &_1) == SUCCESS ; zephir_hash_move_forward_ex(_2, &_1) ) { ZEPHIR_GET_HVALUE(column, _3); ZEPHIR_INIT_LNVAR(_4); ZEPHIR_CONCAT_VVV(_4, escapeChar, column, escapeChar); zephir_array_append(&strList, _4, PH_SEPARATE); } zephir_fast_join_str(return_value, SL(", "), strList TSRMLS_CC); RETURN_MM(); }
/** * Adds a number to a string or increment that number if it already is defined * * <code> * echo Phalcon\Text::increment("a"); // "a_1" * echo Phalcon\Text::increment("a_1"); // "a_2" * </code> */ PHP_METHOD(Phalcon_Text, increment) { zval *str_param = NULL, *separator_param = NULL, *parts = NULL, *number = NULL, *_0; zval *str = NULL, *separator = NULL; ZEPHIR_MM_GROW(); zephir_fetch_params(1, 1, 1, &str_param, &separator_param); zephir_get_strval(str, str_param); if (!separator_param) { ZEPHIR_INIT_VAR(separator); ZVAL_STRING(separator, "_", 1); } else { zephir_get_strval(separator, separator_param); } ZEPHIR_INIT_VAR(parts); zephir_fast_explode(parts, separator, str, LONG_MAX TSRMLS_CC); ZEPHIR_OBS_VAR(number); if (zephir_array_isset_long_fetch(&number, parts, 1, 0 TSRMLS_CC)) { ZEPHIR_SEPARATE(number); zephir_increment(number); } else { ZEPHIR_INIT_NVAR(number); ZVAL_LONG(number, 1); } zephir_array_fetch_long(&_0, parts, 0, PH_NOISY | PH_READONLY, "phalcon/text.zep", 87 TSRMLS_CC); ZEPHIR_CONCAT_VVV(return_value, _0, separator, number); RETURN_MM(); }
/** * Possible class name that will be located to dispatch the request */ PHP_METHOD(Phalcon_Dispatcher, getHandlerClass) { zval *handlerSuffix = NULL, *handlerName = NULL, *namespaceName = NULL, *camelizedClass = NULL, *handlerClass = NULL; int ZEPHIR_LAST_CALL_STATUS; ZEPHIR_MM_GROW(); ZEPHIR_CALL_METHOD(NULL, this_ptr, "_resolveemptyproperties", NULL, 0); zephir_check_call_status(); ZEPHIR_OBS_VAR(handlerSuffix); zephir_read_property_this(&handlerSuffix, this_ptr, SL("_handlerSuffix"), PH_NOISY_CC); ZEPHIR_OBS_VAR(handlerName); zephir_read_property_this(&handlerName, this_ptr, SL("_handlerName"), PH_NOISY_CC); ZEPHIR_OBS_VAR(namespaceName); zephir_read_property_this(&namespaceName, this_ptr, SL("_namespaceName"), PH_NOISY_CC); if (!(zephir_memnstr_str(handlerName, SL("\\"), "phalcon/dispatcher.zep", 709))) { ZEPHIR_INIT_VAR(camelizedClass); zephir_camelize(camelizedClass, handlerName, NULL ); } else { ZEPHIR_CPY_WRT(camelizedClass, handlerName); } if (zephir_is_true(namespaceName)) { ZEPHIR_INIT_VAR(handlerClass); if (zephir_end_with_str(namespaceName, SL("\\"))) { ZEPHIR_CONCAT_VVV(handlerClass, namespaceName, camelizedClass, handlerSuffix); } else { ZEPHIR_CONCAT_VSVV(handlerClass, namespaceName, "\\", camelizedClass, handlerSuffix); } } else { ZEPHIR_INIT_NVAR(handlerClass); ZEPHIR_CONCAT_VV(handlerClass, camelizedClass, handlerSuffix); } RETURN_CCTOR(handlerClass); }
PHP_METHOD(Test_Statements, test544Issue) { zephir_fcall_cache_entry *_8 = NULL; zval *step_param = NULL, *_0, *_1, *_2, *_3, *_4, *_5, _6 = zval_used_for_init, *_7 = NULL, *_9, *_10, *_11 = NULL; int step, filledWidth, unfilledWidth, ZEPHIR_LAST_CALL_STATUS; ZEPHIR_MM_GROW(); zephir_fetch_params(1, 1, 0, &step_param); if (unlikely(Z_TYPE_P(step_param) != IS_LONG)) { zephir_throw_exception_string(spl_ce_InvalidArgumentException, SL("Parameter 'step' must be a long/integer") TSRMLS_CC); RETURN_MM_NULL(); } step = Z_LVAL_P(step_param); _0 = zephir_fetch_nproperty_this(this_ptr, SL("totalSteps"), PH_NOISY_CC); _1 = zephir_fetch_nproperty_this(this_ptr, SL("totalSteps"), PH_NOISY_CC); if (ZEPHIR_GT_LONG(_0, step)) { _2 = zephir_fetch_nproperty_this(this_ptr, SL("width"), PH_NOISY_CC); _3 = zephir_fetch_nproperty_this(this_ptr, SL("totalSteps"), PH_NOISY_CC); filledWidth = (long) ((zephir_safe_div_long_zval(((zephir_get_numberval(_2) - 1)), _3 TSRMLS_CC) * step)); _4 = zephir_fetch_nproperty_this(this_ptr, SL("width"), PH_NOISY_CC); unfilledWidth = (((zephir_get_numberval(_4) - 1)) - filledWidth); _5 = zephir_fetch_nproperty_this(this_ptr, SL("filledChar"), PH_NOISY_CC); ZEPHIR_SINIT_VAR(_6); ZVAL_LONG(&_6, filledWidth); ZEPHIR_CALL_FUNCTION(&_7, "str_repeat", &_8, 17, _5, &_6); zephir_check_call_status(); _9 = zephir_fetch_nproperty_this(this_ptr, SL("arrow"), PH_NOISY_CC); _10 = zephir_fetch_nproperty_this(this_ptr, SL("unfilledChar"), PH_NOISY_CC); ZEPHIR_SINIT_NVAR(_6); ZVAL_LONG(&_6, unfilledWidth); ZEPHIR_CALL_FUNCTION(&_11, "str_repeat", &_8, 17, _10, &_6); zephir_check_call_status(); ZEPHIR_CONCAT_VVV(return_value, _7, _9, _11); RETURN_MM(); } else if (ZEPHIR_IS_LONG_IDENTICAL(_1, step)) { _2 = zephir_fetch_nproperty_this(this_ptr, SL("filledChar"), PH_NOISY_CC); _3 = zephir_fetch_nproperty_this(this_ptr, SL("width"), PH_NOISY_CC); ZEPHIR_RETURN_CALL_FUNCTION("str_repeat", &_8, 17, _2, _3); zephir_check_call_status(); RETURN_MM(); } else { _2 = zephir_fetch_nproperty_this(this_ptr, SL("unfilledChar"), PH_NOISY_CC); _3 = zephir_fetch_nproperty_this(this_ptr, SL("width"), PH_NOISY_CC); ZEPHIR_RETURN_CALL_FUNCTION("str_repeat", &_8, 17, _2, _3); zephir_check_call_status(); RETURN_MM(); } }
PHP_METHOD(Test_Statements, test544IssueWithVariable) { zephir_fcall_cache_entry *_6 = NULL; zval *step_param = NULL, *_0, *_1$$3, *_2$$3, *_3$$3, _4$$3 = zval_used_for_init, *_5$$3 = NULL, *_7$$3, *_8$$3, *_9$$3 = NULL, *_10$$4, *_11$$4, *_12$$5, *_13$$5; int step, ZEPHIR_LAST_CALL_STATUS, filledWidth = 0, unfilledWidth = 0, totalSteps = 0; ZEPHIR_MM_GROW(); zephir_fetch_params(1, 1, 0, &step_param); if (unlikely(Z_TYPE_P(step_param) != IS_LONG)) { zephir_throw_exception_string(spl_ce_InvalidArgumentException, SL("Parameter 'step' must be a int") TSRMLS_CC); RETURN_MM_NULL(); } step = Z_LVAL_P(step_param); _0 = zephir_fetch_nproperty_this(this_ptr, SL("totalSteps"), PH_NOISY_CC); totalSteps = zephir_get_numberval(_0); if (step < totalSteps) { _1$$3 = zephir_fetch_nproperty_this(this_ptr, SL("width"), PH_NOISY_CC); filledWidth = (long) ((zephir_safe_div_long_long(((zephir_get_numberval(_1$$3) - 1)), totalSteps TSRMLS_CC) * step)); _2$$3 = zephir_fetch_nproperty_this(this_ptr, SL("width"), PH_NOISY_CC); unfilledWidth = (((zephir_get_numberval(_2$$3) - 1)) - filledWidth); _3$$3 = zephir_fetch_nproperty_this(this_ptr, SL("filledChar"), PH_NOISY_CC); ZEPHIR_SINIT_VAR(_4$$3); ZVAL_LONG(&_4$$3, filledWidth); ZEPHIR_CALL_FUNCTION(&_5$$3, "str_repeat", &_6, 17, _3$$3, &_4$$3); zephir_check_call_status(); _7$$3 = zephir_fetch_nproperty_this(this_ptr, SL("arrow"), PH_NOISY_CC); _8$$3 = zephir_fetch_nproperty_this(this_ptr, SL("unfilledChar"), PH_NOISY_CC); ZEPHIR_SINIT_NVAR(_4$$3); ZVAL_LONG(&_4$$3, unfilledWidth); ZEPHIR_CALL_FUNCTION(&_9$$3, "str_repeat", &_6, 17, _8$$3, &_4$$3); zephir_check_call_status(); ZEPHIR_CONCAT_VVV(return_value, _5$$3, _7$$3, _9$$3); RETURN_MM(); } else if (step == totalSteps) { _10$$4 = zephir_fetch_nproperty_this(this_ptr, SL("filledChar"), PH_NOISY_CC); _11$$4 = zephir_fetch_nproperty_this(this_ptr, SL("width"), PH_NOISY_CC); ZEPHIR_RETURN_CALL_FUNCTION("str_repeat", &_6, 17, _10$$4, _11$$4); zephir_check_call_status(); RETURN_MM(); } else { _12$$5 = zephir_fetch_nproperty_this(this_ptr, SL("unfilledChar"), PH_NOISY_CC); _13$$5 = zephir_fetch_nproperty_this(this_ptr, SL("width"), PH_NOISY_CC); ZEPHIR_RETURN_CALL_FUNCTION("str_repeat", &_6, 17, _12$$5, _13$$5); zephir_check_call_status(); RETURN_MM(); } }
PHP_METHOD(Xs_Command, __toString) { int ZEPHIR_LAST_CALL_STATUS; zval *_0, *_1, _2 = zval_used_for_init, _3 = zval_used_for_init, *_4, *_5, *_6, *_7, *_8, _9, *_10 = NULL, *_11, *_12; ZEPHIR_MM_GROW(); _0 = zephir_fetch_nproperty_this(this_ptr, SL("buf1"), PH_NOISY_CC); if (zephir_fast_strlen_ev(_0) > 0xff) { _1 = zephir_fetch_nproperty_this(this_ptr, SL("buf1"), PH_NOISY_CC); ZEPHIR_SINIT_VAR(_2); ZVAL_LONG(&_2, 0); ZEPHIR_SINIT_VAR(_3); ZVAL_LONG(&_3, 0xff); ZEPHIR_INIT_VAR(_4); zephir_substr(_4, _1, 0 , 0xff , 0); zephir_update_property_this(this_ptr, SL("buf1"), _4 TSRMLS_CC); } _1 = zephir_fetch_nproperty_this(this_ptr, SL("cmd"), PH_NOISY_CC); _5 = zephir_fetch_nproperty_this(this_ptr, SL("arg1"), PH_NOISY_CC); _6 = zephir_fetch_nproperty_this(this_ptr, SL("arg2"), PH_NOISY_CC); _7 = zephir_fetch_nproperty_this(this_ptr, SL("buf1"), PH_NOISY_CC); _8 = zephir_fetch_nproperty_this(this_ptr, SL("buf"), PH_NOISY_CC); ZEPHIR_SINIT_NVAR(_2); ZVAL_STRING(&_2, "CCCCI", 0); ZEPHIR_SINIT_NVAR(_3); ZVAL_LONG(&_3, zephir_fast_strlen_ev(_7)); ZEPHIR_SINIT_VAR(_9); ZVAL_LONG(&_9, zephir_fast_strlen_ev(_8)); ZEPHIR_CALL_FUNCTION(&_10, "pack", NULL, 2, &_2, _1, _5, _6, &_3, &_9); zephir_check_call_status(); _11 = zephir_fetch_nproperty_this(this_ptr, SL("buf"), PH_NOISY_CC); _12 = zephir_fetch_nproperty_this(this_ptr, SL("buf1"), PH_NOISY_CC); ZEPHIR_CONCAT_VVV(return_value, _10, _11, _12); RETURN_MM(); }
PHP_METHOD(Test_Statements, test544IssueWithVariable) { zephir_fcall_cache_entry *_6 = NULL; zval *step_param = NULL, _0, _1$$3, _2$$3, _3$$3, _4$$3, _5$$3, _7$$3, _8$$3, _9$$3, _10$$4, _11$$4, _12$$5, _13$$5; int step, ZEPHIR_LAST_CALL_STATUS, filledWidth = 0, unfilledWidth = 0, totalSteps = 0; zval this_zv; zval *this_ptr = getThis(); if (EXPECTED(this_ptr)) { ZVAL_OBJ(&this_zv, Z_OBJ_P(this_ptr)); this_ptr = &this_zv; } else this_ptr = NULL; ZVAL_UNDEF(&_0); ZVAL_UNDEF(&_1$$3); ZVAL_UNDEF(&_2$$3); ZVAL_UNDEF(&_3$$3); ZVAL_UNDEF(&_4$$3); ZVAL_UNDEF(&_5$$3); ZVAL_UNDEF(&_7$$3); ZVAL_UNDEF(&_8$$3); ZVAL_UNDEF(&_9$$3); ZVAL_UNDEF(&_10$$4); ZVAL_UNDEF(&_11$$4); ZVAL_UNDEF(&_12$$5); ZVAL_UNDEF(&_13$$5); ZEPHIR_MM_GROW(); zephir_fetch_params(1, 1, 0, &step_param); if (unlikely(Z_TYPE_P(step_param) != IS_LONG)) { zephir_throw_exception_string(spl_ce_InvalidArgumentException, SL("Parameter 'step' must be a int") TSRMLS_CC); RETURN_MM_NULL(); } step = Z_LVAL_P(step_param); zephir_read_property(&_0, this_ptr, SL("totalSteps"), PH_NOISY_CC | PH_READONLY); totalSteps = zephir_get_numberval(&_0); if (step < totalSteps) { zephir_read_property(&_1$$3, this_ptr, SL("width"), PH_NOISY_CC | PH_READONLY); filledWidth = (long) ((zephir_safe_div_long_long(((zephir_get_numberval(&_1$$3) - 1)), totalSteps TSRMLS_CC) * step)); zephir_read_property(&_2$$3, this_ptr, SL("width"), PH_NOISY_CC | PH_READONLY); unfilledWidth = (((zephir_get_numberval(&_2$$3) - 1)) - filledWidth); zephir_read_property(&_3$$3, this_ptr, SL("filledChar"), PH_NOISY_CC | PH_READONLY); ZVAL_LONG(&_4$$3, filledWidth); ZEPHIR_CALL_FUNCTION(&_5$$3, "str_repeat", &_6, 17, &_3$$3, &_4$$3); zephir_check_call_status(); zephir_read_property(&_4$$3, this_ptr, SL("arrow"), PH_NOISY_CC | PH_READONLY); zephir_read_property(&_7$$3, this_ptr, SL("unfilledChar"), PH_NOISY_CC | PH_READONLY); ZVAL_LONG(&_8$$3, unfilledWidth); ZEPHIR_CALL_FUNCTION(&_9$$3, "str_repeat", &_6, 17, &_7$$3, &_8$$3); zephir_check_call_status(); ZEPHIR_CONCAT_VVV(return_value, &_5$$3, &_4$$3, &_9$$3); RETURN_MM(); } else if (step == totalSteps) { zephir_read_property(&_10$$4, this_ptr, SL("filledChar"), PH_NOISY_CC | PH_READONLY); zephir_read_property(&_11$$4, this_ptr, SL("width"), PH_NOISY_CC | PH_READONLY); ZEPHIR_RETURN_CALL_FUNCTION("str_repeat", &_6, 17, &_10$$4, &_11$$4); zephir_check_call_status(); RETURN_MM(); } else { zephir_read_property(&_12$$5, this_ptr, SL("unfilledChar"), PH_NOISY_CC | PH_READONLY); zephir_read_property(&_13$$5, this_ptr, SL("width"), PH_NOISY_CC | PH_READONLY); ZEPHIR_RETURN_CALL_FUNCTION("str_repeat", &_6, 17, &_12$$5, &_13$$5); zephir_check_call_status(); RETURN_MM(); } }
/** * Dispatches a handle action taking into account the routing parameters * * @return object */ PHP_METHOD(Phalcon_Dispatcher, dispatch) { zval *_18 = NULL; zephir_fcall_cache_entry *_4 = NULL, *_5 = NULL, *_8 = NULL, *_10 = NULL, *_11 = NULL, *_12 = NULL, *_13 = NULL, *_14 = NULL, *_16 = NULL, *_19 = NULL; zval *value, *handler = NULL, *dependencyInjector = NULL, *namespaceName = NULL, *handlerName = NULL, *actionName = NULL, *camelizedClass = NULL, *params = NULL, *eventsManager = NULL, *handlerSuffix, *actionSuffix, *handlerClass = NULL, *status = NULL, *actionMethod = NULL, *e = NULL, *_0, *_1 = NULL, *_2 = NULL, *_3 = NULL, *_6, *_7 = NULL, *_9 = NULL, *_15 = NULL, *_17; int numberDispatches, ZEPHIR_LAST_CALL_STATUS; zend_bool hasService, wasFresh = 0; ZEPHIR_MM_GROW(); _0 = zephir_fetch_nproperty_this(this_ptr, SL("_dependencyInjector"), PH_NOISY_CC); ZEPHIR_CPY_WRT(dependencyInjector, _0); if (Z_TYPE_P(dependencyInjector) != IS_OBJECT) { ZEPHIR_INIT_VAR(_1); ZVAL_STRING(_1, "A dependency injection container is required to access related dispatching services", ZEPHIR_TEMP_PARAM_COPY); ZEPHIR_INIT_VAR(_2); ZVAL_LONG(_2, 0); ZEPHIR_CALL_METHOD(NULL, this_ptr, "_throwdispatchexception", NULL, _1, _2); zephir_check_temp_parameter(_1); zephir_check_call_status(); RETURN_MM_BOOL(0); } _0 = zephir_fetch_nproperty_this(this_ptr, SL("_eventsManager"), PH_NOISY_CC); ZEPHIR_CPY_WRT(eventsManager, _0); if (Z_TYPE_P(eventsManager) == IS_OBJECT) { ZEPHIR_INIT_NVAR(_1); ZVAL_STRING(_1, "dispatch:beforeDispatchLoop", ZEPHIR_TEMP_PARAM_COPY); ZEPHIR_CALL_METHOD(&_3, eventsManager, "fire", NULL, _1, this_ptr); zephir_check_temp_parameter(_1); zephir_check_call_status(); if (ZEPHIR_IS_FALSE_IDENTICAL(_3)) { RETURN_MM_BOOL(0); } } ZEPHIR_INIT_VAR(value); ZVAL_NULL(value); ZEPHIR_INIT_VAR(handler); ZVAL_NULL(handler); numberDispatches = 0; ZEPHIR_OBS_VAR(handlerSuffix); zephir_read_property_this(&handlerSuffix, this_ptr, SL("_handlerSuffix"), PH_NOISY_CC); ZEPHIR_OBS_VAR(actionSuffix); zephir_read_property_this(&actionSuffix, this_ptr, SL("_actionSuffix"), PH_NOISY_CC); zephir_update_property_this(this_ptr, SL("_finished"), (0) ? ZEPHIR_GLOBAL(global_true) : ZEPHIR_GLOBAL(global_false) TSRMLS_CC); while (1) { _0 = zephir_fetch_nproperty_this(this_ptr, SL("_finished"), PH_NOISY_CC); if (!(!(zephir_is_true(_0)))) { break; } numberDispatches++; if (numberDispatches == 256) { ZEPHIR_INIT_NVAR(_1); ZVAL_STRING(_1, "Dispatcher has detected a cyclic routing causing stability problems", ZEPHIR_TEMP_PARAM_COPY); ZEPHIR_INIT_NVAR(_2); ZVAL_LONG(_2, 1); ZEPHIR_CALL_METHOD(NULL, this_ptr, "_throwdispatchexception", &_4, _1, _2); zephir_check_temp_parameter(_1); zephir_check_call_status(); break; } zephir_update_property_this(this_ptr, SL("_finished"), (1) ? ZEPHIR_GLOBAL(global_true) : ZEPHIR_GLOBAL(global_false) TSRMLS_CC); ZEPHIR_OBS_NVAR(namespaceName); zephir_read_property_this(&namespaceName, this_ptr, SL("_namespaceName"), PH_NOISY_CC); if (!(zephir_is_true(namespaceName))) { ZEPHIR_OBS_NVAR(namespaceName); zephir_read_property_this(&namespaceName, this_ptr, SL("_defaultNamespace"), PH_NOISY_CC); zephir_update_property_this(this_ptr, SL("_namespaceName"), namespaceName TSRMLS_CC); } ZEPHIR_OBS_NVAR(handlerName); zephir_read_property_this(&handlerName, this_ptr, SL("_handlerName"), PH_NOISY_CC); if (!(zephir_is_true(handlerName))) { ZEPHIR_OBS_NVAR(handlerName); zephir_read_property_this(&handlerName, this_ptr, SL("_defaultHandler"), PH_NOISY_CC); zephir_update_property_this(this_ptr, SL("_handlerName"), handlerName TSRMLS_CC); } ZEPHIR_OBS_NVAR(actionName); zephir_read_property_this(&actionName, this_ptr, SL("_actionName"), PH_NOISY_CC); if (!(zephir_is_true(actionName))) { ZEPHIR_OBS_NVAR(actionName); zephir_read_property_this(&actionName, this_ptr, SL("_defaultAction"), PH_NOISY_CC); zephir_update_property_this(this_ptr, SL("_actionName"), actionName TSRMLS_CC); } if (Z_TYPE_P(eventsManager) == IS_OBJECT) { ZEPHIR_INIT_NVAR(_1); ZVAL_STRING(_1, "dispatch:beforeDispatch", ZEPHIR_TEMP_PARAM_COPY); ZEPHIR_CALL_METHOD(&_3, eventsManager, "fire", &_5, _1, this_ptr); zephir_check_temp_parameter(_1); zephir_check_call_status(); if (ZEPHIR_IS_FALSE_IDENTICAL(_3)) { continue; } _6 = zephir_fetch_nproperty_this(this_ptr, SL("_finished"), PH_NOISY_CC); if (ZEPHIR_IS_FALSE_IDENTICAL(_6)) { continue; } } if (!(zephir_memnstr_str(handlerName, SL("\\"), "phalcon/dispatcher.zep", 390))) { ZEPHIR_INIT_NVAR(camelizedClass); zephir_camelize(camelizedClass, handlerName); } else { ZEPHIR_CPY_WRT(camelizedClass, handlerName); } if (zephir_is_true(namespaceName)) { ZEPHIR_INIT_NVAR(handlerClass); if (zephir_end_with_str(namespaceName, SL("\\"))) { ZEPHIR_CONCAT_VVV(handlerClass, namespaceName, camelizedClass, handlerSuffix); } else { ZEPHIR_CONCAT_VSVV(handlerClass, namespaceName, "\\", camelizedClass, handlerSuffix); } } else { ZEPHIR_INIT_NVAR(handlerClass); ZEPHIR_CONCAT_VV(handlerClass, camelizedClass, handlerSuffix); } ZEPHIR_CALL_METHOD(&_7, dependencyInjector, "has", &_8, handlerClass); zephir_check_call_status(); hasService = zephir_get_boolval(_7); if (!(hasService)) { hasService = zephir_class_exists(handlerClass, 1 TSRMLS_CC); } if (!(hasService)) { ZEPHIR_INIT_LNVAR(_9); ZEPHIR_CONCAT_VS(_9, handlerClass, " handler class cannot be loaded"); ZEPHIR_INIT_NVAR(_1); ZVAL_LONG(_1, 2); ZEPHIR_CALL_METHOD(&status, this_ptr, "_throwdispatchexception", &_10, _9, _1); zephir_check_call_status(); if (ZEPHIR_IS_FALSE_IDENTICAL(status)) { _6 = zephir_fetch_nproperty_this(this_ptr, SL("_finished"), PH_NOISY_CC); if (ZEPHIR_IS_FALSE_IDENTICAL(_6)) { continue; } } break; } ZEPHIR_CALL_METHOD(&handler, dependencyInjector, "getshared", &_11, handlerClass); zephir_check_call_status(); ZEPHIR_CALL_METHOD(&_7, dependencyInjector, "wasfreshinstance", &_12); zephir_check_call_status(); if (ZEPHIR_IS_TRUE_IDENTICAL(_7)) { wasFresh = 1; } if (Z_TYPE_P(handler) != IS_OBJECT) { ZEPHIR_INIT_NVAR(_1); ZVAL_STRING(_1, "Invalid handler returned from the services container", ZEPHIR_TEMP_PARAM_COPY); ZEPHIR_INIT_NVAR(_2); ZVAL_LONG(_2, 3); ZEPHIR_CALL_METHOD(&status, this_ptr, "_throwdispatchexception", &_13, _1, _2); zephir_check_temp_parameter(_1); zephir_check_call_status(); if (ZEPHIR_IS_FALSE_IDENTICAL(status)) { _6 = zephir_fetch_nproperty_this(this_ptr, SL("_finished"), PH_NOISY_CC); if (ZEPHIR_IS_FALSE_IDENTICAL(_6)) { continue; } } break; } zephir_update_property_this(this_ptr, SL("_activeHandler"), handler TSRMLS_CC); ZEPHIR_OBS_NVAR(params); zephir_read_property_this(¶ms, this_ptr, SL("_params"), PH_NOISY_CC); if (Z_TYPE_P(params) != IS_ARRAY) { ZEPHIR_INIT_NVAR(_1); ZVAL_STRING(_1, "Action parameters must be an Array", ZEPHIR_TEMP_PARAM_COPY); ZEPHIR_INIT_NVAR(_2); ZVAL_LONG(_2, 4); ZEPHIR_CALL_METHOD(&status, this_ptr, "_throwdispatchexception", &_14, _1, _2); zephir_check_temp_parameter(_1); zephir_check_call_status(); if (ZEPHIR_IS_FALSE_IDENTICAL(status)) { _6 = zephir_fetch_nproperty_this(this_ptr, SL("_finished"), PH_NOISY_CC); if (ZEPHIR_IS_FALSE_IDENTICAL(_6)) { continue; } } break; } ZEPHIR_INIT_NVAR(actionMethod); ZEPHIR_CONCAT_VV(actionMethod, actionName, actionSuffix); if (!((zephir_method_exists(handler, actionMethod TSRMLS_CC) == SUCCESS))) { if (Z_TYPE_P(eventsManager) == IS_OBJECT) { ZEPHIR_INIT_NVAR(_1); ZVAL_STRING(_1, "dispatch:beforeNotFoundAction", ZEPHIR_TEMP_PARAM_COPY); ZEPHIR_CALL_METHOD(&_15, eventsManager, "fire", &_5, _1, this_ptr); zephir_check_temp_parameter(_1); zephir_check_call_status(); if (ZEPHIR_IS_FALSE_IDENTICAL(_15)) { continue; } _6 = zephir_fetch_nproperty_this(this_ptr, SL("_finished"), PH_NOISY_CC); if (ZEPHIR_IS_FALSE_IDENTICAL(_6)) { continue; } } ZEPHIR_INIT_LNVAR(_9); ZEPHIR_CONCAT_SVSVS(_9, "Action '", actionName, "' was not found on handler '", handlerName, "'"); ZEPHIR_INIT_NVAR(_1); ZVAL_LONG(_1, 5); ZEPHIR_CALL_METHOD(&status, this_ptr, "_throwdispatchexception", &_16, _9, _1); zephir_check_call_status(); if (ZEPHIR_IS_FALSE_IDENTICAL(status)) { _17 = zephir_fetch_nproperty_this(this_ptr, SL("_finished"), PH_NOISY_CC); if (ZEPHIR_IS_FALSE_IDENTICAL(_17)) { continue; } } break; } if (Z_TYPE_P(eventsManager) == IS_OBJECT) { ZEPHIR_INIT_NVAR(_1); ZVAL_STRING(_1, "dispatch:beforeExecuteRoute", ZEPHIR_TEMP_PARAM_COPY); ZEPHIR_CALL_METHOD(&_15, eventsManager, "fire", &_5, _1, this_ptr); zephir_check_temp_parameter(_1); zephir_check_call_status(); if (ZEPHIR_IS_FALSE_IDENTICAL(_15)) { continue; } _6 = zephir_fetch_nproperty_this(this_ptr, SL("_finished"), PH_NOISY_CC); if (ZEPHIR_IS_FALSE_IDENTICAL(_6)) { continue; } } if ((zephir_method_exists_ex(handler, SS("beforeexecuteroute") TSRMLS_CC) == SUCCESS)) { ZEPHIR_CALL_METHOD(&_15, handler, "beforeexecuteroute", NULL, this_ptr); zephir_check_call_status(); if (ZEPHIR_IS_FALSE_IDENTICAL(_15)) { continue; } _6 = zephir_fetch_nproperty_this(this_ptr, SL("_finished"), PH_NOISY_CC); if (ZEPHIR_IS_FALSE_IDENTICAL(_6)) { continue; } } if (wasFresh == 1) { if ((zephir_method_exists_ex(handler, SS("initialize") TSRMLS_CC) == SUCCESS)) { ZEPHIR_CALL_METHOD(NULL, handler, "initialize", NULL); zephir_check_call_status(); } if (zephir_is_true(eventsManager)) { ZEPHIR_INIT_NVAR(_1); ZVAL_STRING(_1, "dispatch:afterInitialize", ZEPHIR_TEMP_PARAM_COPY); ZEPHIR_CALL_METHOD(&_15, eventsManager, "fire", &_5, _1, this_ptr); zephir_check_temp_parameter(_1); zephir_check_call_status(); if (ZEPHIR_IS_FALSE_IDENTICAL(_15)) { continue; } _6 = zephir_fetch_nproperty_this(this_ptr, SL("_finished"), PH_NOISY_CC); if (ZEPHIR_IS_FALSE_IDENTICAL(_6)) { continue; } } } /* try_start_1: */ ZEPHIR_INIT_NVAR(_1); ZEPHIR_INIT_NVAR(_18); zephir_create_array(_18, 2, 0 TSRMLS_CC); zephir_array_fast_append(_18, handler); zephir_array_fast_append(_18, actionMethod); ZEPHIR_CALL_USER_FUNC_ARRAY(_1, _18, params); zephir_check_call_status_or_jump(try_end_1); zephir_update_property_this(this_ptr, SL("_returnedValue"), _1 TSRMLS_CC); zephir_update_property_this(this_ptr, SL("_lastHandler"), handler TSRMLS_CC); try_end_1: if (EG(exception)) { ZEPHIR_CPY_WRT(e, EG(exception)); if (zephir_instance_of_ev(e, zend_exception_get_default(TSRMLS_C) TSRMLS_CC)) { zend_clear_exception(TSRMLS_C); ZEPHIR_CALL_METHOD(&_15, this_ptr, "_handleexception", &_19, e); zephir_check_call_status(); if (ZEPHIR_IS_FALSE_IDENTICAL(_15)) { _6 = zephir_fetch_nproperty_this(this_ptr, SL("_finished"), PH_NOISY_CC); if (ZEPHIR_IS_FALSE_IDENTICAL(_6)) { continue; } } else { zephir_throw_exception_debug(e, "phalcon/dispatcher.zep", 550 TSRMLS_CC); ZEPHIR_MM_RESTORE(); return; } } } if (Z_TYPE_P(eventsManager) == IS_OBJECT) { ZEPHIR_INIT_NVAR(_2); ZVAL_STRING(_2, "dispatch:afterExecuteRoute", ZEPHIR_TEMP_PARAM_COPY); ZEPHIR_CALL_METHOD(&_15, eventsManager, "fire", &_5, _2, this_ptr, value); zephir_check_temp_parameter(_2); zephir_check_call_status(); if (ZEPHIR_IS_FALSE_IDENTICAL(_15)) { continue; } _6 = zephir_fetch_nproperty_this(this_ptr, SL("_finished"), PH_NOISY_CC); if (ZEPHIR_IS_FALSE_IDENTICAL(_6)) { continue; } ZEPHIR_INIT_NVAR(_2); ZVAL_STRING(_2, "dispatch:afterDispatch", ZEPHIR_TEMP_PARAM_COPY); ZEPHIR_CALL_METHOD(NULL, eventsManager, "fire", &_5, _2, this_ptr); zephir_check_temp_parameter(_2); zephir_check_call_status(); } if ((zephir_method_exists_ex(handler, SS("afterexecuteroute") TSRMLS_CC) == SUCCESS)) { ZEPHIR_CALL_METHOD(&_15, handler, "afterexecuteroute", NULL, this_ptr, value); zephir_check_call_status(); if (ZEPHIR_IS_FALSE_IDENTICAL(_15)) { continue; } _6 = zephir_fetch_nproperty_this(this_ptr, SL("_finished"), PH_NOISY_CC); if (ZEPHIR_IS_FALSE_IDENTICAL(_6)) { continue; } } } if (Z_TYPE_P(eventsManager) == IS_OBJECT) { ZEPHIR_INIT_NVAR(_1); ZVAL_STRING(_1, "dispatch:afterDispatchLoop", ZEPHIR_TEMP_PARAM_COPY); ZEPHIR_CALL_METHOD(NULL, eventsManager, "fire", &_5, _1, this_ptr); zephir_check_temp_parameter(_1); zephir_check_call_status(); } RETURN_CCTOR(handler); }
/** * Builds a SELECT statement * * @param array definition * @return string */ PHP_METHOD(Pdm_Db_AbstractDialect, select) { zephir_fcall_cache_entry *_4 = NULL, *_9 = NULL; int ZEPHIR_LAST_CALL_STATUS; HashTable *_2, *_6, *_11, *_16, *_22, *_26; HashPosition _1, _5, _10, _15, _21, _25; zval *definition, *tables, *columns = NULL, *escapeChar = NULL, *columnItem = NULL, *column = NULL, *selectedColumns, *columnSql = NULL, *columnDomainSql = NULL, *columnAlias = NULL, *selectedTables, *sqlJoin = NULL, *joinExpressions = NULL, *joinCondition = NULL, *joinConditionsArray = NULL, *tablesSql = NULL, *columnDomain = NULL, *columnAliasSql = NULL, *columnsSql = NULL, *table = NULL, *sql, *joins, *join = NULL, *sqlTable = NULL, *whereConditions, *groupFields, *groupField = NULL, *groupItems, *havingConditions, *orderFields, *orderItem = NULL, *orderItems, *orderSqlItem = NULL, *sqlOrderType = NULL, *orderSqlItemType = NULL, *limitValue, *number, *offset, *_0, **_3, **_7, *_8 = NULL, **_12, *_13, *_14, **_17, *_18 = NULL, *_19 = NULL, *_20 = NULL, **_23, *_24 = NULL, **_27, *_28, *_29; ZEPHIR_MM_GROW(); zephir_fetch_params(1, 1, 0, &definition); if (Z_TYPE_P(definition) != IS_ARRAY) { ZEPHIR_THROW_EXCEPTION_DEBUG_STR(pdm_db_exception_ce, "Invalid SELECT definition", "pdm/db/abstractdialect.zep", 375); return; } ZEPHIR_OBS_VAR(tables); if (!(zephir_array_isset_string_fetch(&tables, definition, SS("tables"), 0 TSRMLS_CC))) { ZEPHIR_THROW_EXCEPTION_DEBUG_STR(pdm_db_exception_ce, "The index 'tables' is required in the definition array", "pdm/db/abstractdialect.zep", 379); return; } ZEPHIR_OBS_VAR(columns); if (!(zephir_array_isset_string_fetch(&columns, definition, SS("columns"), 0 TSRMLS_CC))) { ZEPHIR_THROW_EXCEPTION_DEBUG_STR(pdm_db_exception_ce, "The index 'columns' is required in the definition array", "pdm/db/abstractdialect.zep", 383); return; } if (ZEPHIR_GLOBAL(db).escape_identifiers) { _0 = zephir_fetch_nproperty_this(this_ptr, SL("escapeChar"), PH_NOISY_CC); ZEPHIR_CPY_WRT(escapeChar, _0); } else { ZEPHIR_INIT_VAR(escapeChar); ZVAL_NULL(escapeChar); } ZEPHIR_OBS_NVAR(columns); zephir_array_fetch_string(&columns, definition, SL("columns"), PH_NOISY TSRMLS_CC); if (Z_TYPE_P(columns) == IS_ARRAY) { ZEPHIR_INIT_VAR(selectedColumns); array_init(selectedColumns); zephir_is_iterable(columns, &_2, &_1, 0, 0); for ( ; zephir_hash_get_current_data_ex(_2, (void**) &_3, &_1) == SUCCESS ; zephir_hash_move_forward_ex(_2, &_1) ) { ZEPHIR_GET_HVALUE(column, _3); ZEPHIR_OBS_NVAR(columnItem); zephir_array_fetch_long(&columnItem, column, 0, PH_NOISY TSRMLS_CC); if (Z_TYPE_P(columnItem) == IS_ARRAY) { ZEPHIR_CALL_METHOD(&columnSql, this_ptr, "getsqlexpression", &_4, columnItem, escapeChar); zephir_check_call_status(); } else { if (ZEPHIR_IS_STRING(columnItem, "*")) { ZEPHIR_CPY_WRT(columnSql, columnItem); } else { if (ZEPHIR_GLOBAL(db).escape_identifiers) { ZEPHIR_INIT_NVAR(columnSql); ZEPHIR_CONCAT_VVV(columnSql, escapeChar, columnItem, escapeChar); } else { ZEPHIR_CPY_WRT(columnSql, columnItem); } } } ZEPHIR_OBS_NVAR(columnDomain); if (zephir_array_isset_long_fetch(&columnDomain, column, 1, 0 TSRMLS_CC)) { if (zephir_is_true(columnDomain)) { ZEPHIR_INIT_NVAR(columnDomainSql); if (ZEPHIR_GLOBAL(db).escape_identifiers) { ZEPHIR_CONCAT_VVVSV(columnDomainSql, escapeChar, columnDomain, escapeChar, ".", columnSql); } else { ZEPHIR_CONCAT_VSV(columnDomainSql, columnDomain, ".", columnSql); } } else { ZEPHIR_CPY_WRT(columnDomainSql, columnSql); } } else { ZEPHIR_CPY_WRT(columnDomainSql, columnSql); } ZEPHIR_OBS_NVAR(columnAlias); if (zephir_array_isset_long_fetch(&columnAlias, column, 2, 0 TSRMLS_CC)) { if (zephir_is_true(columnAlias)) { ZEPHIR_INIT_NVAR(columnAliasSql); if (ZEPHIR_GLOBAL(db).escape_identifiers) { ZEPHIR_CONCAT_VSVVV(columnAliasSql, columnDomainSql, " AS ", escapeChar, columnAlias, escapeChar); } else { ZEPHIR_CONCAT_VSV(columnAliasSql, columnDomainSql, " AS ", columnAlias); } } else { ZEPHIR_CPY_WRT(columnAliasSql, columnDomainSql); } } else { ZEPHIR_CPY_WRT(columnAliasSql, columnDomainSql); } zephir_array_append(&selectedColumns, columnAliasSql, PH_SEPARATE); } ZEPHIR_INIT_VAR(columnsSql); zephir_fast_join_str(columnsSql, SL(", "), selectedColumns TSRMLS_CC); } else { ZEPHIR_CPY_WRT(columnsSql, columns); } if (Z_TYPE_P(tables) == IS_ARRAY) { ZEPHIR_INIT_VAR(selectedTables); array_init(selectedTables); zephir_is_iterable(tables, &_6, &_5, 0, 0); for ( ; zephir_hash_get_current_data_ex(_6, (void**) &_7, &_5) == SUCCESS ; zephir_hash_move_forward_ex(_6, &_5) ) { ZEPHIR_GET_HVALUE(table, _7); ZEPHIR_CALL_METHOD(&_8, this_ptr, "getsqltable", &_9, table, escapeChar); zephir_check_call_status(); zephir_array_append(&selectedTables, _8, PH_SEPARATE); } ZEPHIR_INIT_VAR(tablesSql); zephir_fast_join_str(tablesSql, SL(", "), selectedTables TSRMLS_CC); } else { ZEPHIR_CPY_WRT(tablesSql, tables); } ZEPHIR_INIT_VAR(sql); ZEPHIR_CONCAT_SVSV(sql, "SELECT ", columnsSql, " FROM ", tablesSql); ZEPHIR_OBS_VAR(joins); if (zephir_array_isset_string_fetch(&joins, definition, SS("joins"), 0 TSRMLS_CC)) { zephir_is_iterable(joins, &_11, &_10, 0, 0); for ( ; zephir_hash_get_current_data_ex(_11, (void**) &_12, &_10) == SUCCESS ; zephir_hash_move_forward_ex(_11, &_10) ) { ZEPHIR_GET_HVALUE(join, _12); zephir_array_fetch_string(&_13, join, SL("source"), PH_NOISY | PH_READONLY TSRMLS_CC); ZEPHIR_CALL_METHOD(&sqlTable, this_ptr, "getsqltable", &_9, _13, escapeChar); zephir_check_call_status(); zephir_array_append(&selectedTables, sqlTable, PH_SEPARATE); zephir_array_fetch_string(&_14, join, SL("type"), PH_NOISY | PH_READONLY TSRMLS_CC); ZEPHIR_INIT_NVAR(sqlJoin); ZEPHIR_CONCAT_SVSV(sqlJoin, " ", _14, " JOIN ", sqlTable); ZEPHIR_OBS_NVAR(joinConditionsArray); if (zephir_array_isset_string_fetch(&joinConditionsArray, join, SS("conditions"), 0 TSRMLS_CC)) { if (zephir_fast_count_int(joinConditionsArray TSRMLS_CC)) { ZEPHIR_INIT_NVAR(joinExpressions); array_init(joinExpressions); zephir_is_iterable(joinConditionsArray, &_16, &_15, 0, 0); for ( ; zephir_hash_get_current_data_ex(_16, (void**) &_17, &_15) == SUCCESS ; zephir_hash_move_forward_ex(_16, &_15) ) { ZEPHIR_GET_HVALUE(joinCondition, _17); ZEPHIR_CALL_METHOD(&_8, this_ptr, "getsqlexpression", &_4, joinCondition, escapeChar); zephir_check_call_status(); zephir_array_append(&joinExpressions, _8, PH_SEPARATE); } ZEPHIR_INIT_NVAR(_18); zephir_fast_join_str(_18, SL(" AND "), joinExpressions TSRMLS_CC); ZEPHIR_INIT_LNVAR(_19); ZEPHIR_CONCAT_SVS(_19, " ON ", _18, " "); zephir_concat_self(&sqlJoin, _19 TSRMLS_CC); } } zephir_concat_self(&sql, sqlJoin TSRMLS_CC); } } ZEPHIR_OBS_VAR(whereConditions); if (zephir_array_isset_string_fetch(&whereConditions, definition, SS("where"), 0 TSRMLS_CC)) { if (Z_TYPE_P(whereConditions) == IS_ARRAY) { ZEPHIR_CALL_METHOD(&_8, this_ptr, "getsqlexpression", &_4, whereConditions, escapeChar); zephir_check_call_status(); ZEPHIR_INIT_LNVAR(_19); ZEPHIR_CONCAT_SV(_19, " WHERE ", _8); zephir_concat_self(&sql, _19 TSRMLS_CC); } else { ZEPHIR_INIT_VAR(_20); ZEPHIR_CONCAT_SV(_20, " WHERE ", whereConditions); zephir_concat_self(&sql, _20 TSRMLS_CC); } } ZEPHIR_OBS_VAR(groupFields); if (zephir_array_isset_string_fetch(&groupFields, definition, SS("group"), 0 TSRMLS_CC)) { ZEPHIR_INIT_VAR(groupItems); array_init(groupItems); zephir_is_iterable(groupFields, &_22, &_21, 0, 0); for ( ; zephir_hash_get_current_data_ex(_22, (void**) &_23, &_21) == SUCCESS ; zephir_hash_move_forward_ex(_22, &_21) ) { ZEPHIR_GET_HVALUE(groupField, _23); ZEPHIR_CALL_METHOD(&_8, this_ptr, "getsqlexpression", &_4, groupField, escapeChar); zephir_check_call_status(); zephir_array_append(&groupItems, _8, PH_SEPARATE); } ZEPHIR_INIT_NVAR(_18); zephir_fast_join_str(_18, SL(", "), groupItems TSRMLS_CC); ZEPHIR_INIT_LNVAR(_20); ZEPHIR_CONCAT_SV(_20, " GROUP BY ", _18); zephir_concat_self(&sql, _20 TSRMLS_CC); ZEPHIR_OBS_VAR(havingConditions); if (zephir_array_isset_string_fetch(&havingConditions, definition, SS("having"), 0 TSRMLS_CC)) { ZEPHIR_CALL_METHOD(&_8, this_ptr, "getsqlexpression", &_4, havingConditions, escapeChar); zephir_check_call_status(); ZEPHIR_INIT_VAR(_24); ZEPHIR_CONCAT_SV(_24, " HAVING ", _8); zephir_concat_self(&sql, _24 TSRMLS_CC); } } ZEPHIR_OBS_VAR(orderFields); if (zephir_array_isset_string_fetch(&orderFields, definition, SS("order"), 0 TSRMLS_CC)) { ZEPHIR_INIT_VAR(orderItems); array_init(orderItems); zephir_is_iterable(orderFields, &_26, &_25, 0, 0); for ( ; zephir_hash_get_current_data_ex(_26, (void**) &_27, &_25) == SUCCESS ; zephir_hash_move_forward_ex(_26, &_25) ) { ZEPHIR_GET_HVALUE(orderItem, _27); zephir_array_fetch_long(&_13, orderItem, 0, PH_NOISY | PH_READONLY TSRMLS_CC); ZEPHIR_CALL_METHOD(&orderSqlItem, this_ptr, "getsqlexpression", &_4, _13, escapeChar); zephir_check_call_status(); ZEPHIR_OBS_NVAR(sqlOrderType); if (zephir_array_isset_long_fetch(&sqlOrderType, orderItem, 1, 0 TSRMLS_CC)) { ZEPHIR_INIT_NVAR(orderSqlItemType); ZEPHIR_CONCAT_VSV(orderSqlItemType, orderSqlItem, " ", sqlOrderType); } else { ZEPHIR_CPY_WRT(orderSqlItemType, orderSqlItem); } zephir_array_append(&orderItems, orderSqlItemType, PH_SEPARATE); } ZEPHIR_INIT_VAR(_28); zephir_fast_join_str(_28, SL(", "), orderItems TSRMLS_CC); ZEPHIR_INIT_LNVAR(_20); ZEPHIR_CONCAT_SV(_20, " ORDER BY ", _28); zephir_concat_self(&sql, _20 TSRMLS_CC); } if (zephir_array_isset_string_fetch(&limitValue, definition, SS("limit"), 1 TSRMLS_CC)) { if (Z_TYPE_P(limitValue) == IS_ARRAY) { zephir_array_fetch_string(&_13, limitValue, SL("number"), PH_NOISY | PH_READONLY TSRMLS_CC); zephir_array_fetch_string(&number, _13, SL("value"), PH_NOISY | PH_READONLY TSRMLS_CC); if (zephir_array_isset_string_fetch(&offset, limitValue, SS("offset"), 1 TSRMLS_CC)) { zephir_array_fetch_string(&_14, offset, SL("value"), PH_NOISY | PH_READONLY TSRMLS_CC); ZEPHIR_INIT_LNVAR(_24); ZEPHIR_CONCAT_SVSV(_24, " LIMIT ", number, " OFFSET ", _14); zephir_concat_self(&sql, _24 TSRMLS_CC); } else { ZEPHIR_INIT_VAR(_29); ZEPHIR_CONCAT_SV(_29, " LIMIT ", number); zephir_concat_self(&sql, _29 TSRMLS_CC); } } else { ZEPHIR_INIT_LNVAR(_20); ZEPHIR_CONCAT_SV(_20, " LIMIT ", limitValue); zephir_concat_self(&sql, _20 TSRMLS_CC); } } RETURN_CCTOR(sql); }
/** * Transform an intermediate representation for a schema/table into a database system valid expression * * @param array table * @param string escapeChar * @return string */ PHP_METHOD(Pdm_Db_AbstractDialect, getSqlTable) { zval *escapeChar = NULL, *_1 = NULL; zval *table, *escapeChar_param = NULL, *sqlTable = NULL, *sqlSchema = NULL, *aliasName, *sqlTableAlias = NULL, *schemaName, *tableName, *_0; ZEPHIR_MM_GROW(); zephir_fetch_params(1, 1, 1, &table, &escapeChar_param); if (!escapeChar_param) { ZEPHIR_INIT_VAR(escapeChar); ZVAL_EMPTY_STRING(escapeChar); } else { zephir_get_strval(escapeChar, escapeChar_param); } if (ZEPHIR_IS_STRING_IDENTICAL(escapeChar, "")) { ZEPHIR_OBS_VAR(_0); zephir_read_property_this(&_0, this_ptr, SL("escapeChar"), PH_NOISY_CC); zephir_get_strval(_1, _0); ZEPHIR_CPY_WRT(escapeChar, _1); } if (Z_TYPE_P(table) == IS_ARRAY) { ZEPHIR_OBS_VAR(tableName); zephir_array_fetch_long(&tableName, table, 0, PH_NOISY TSRMLS_CC); if (ZEPHIR_GLOBAL(db).escape_identifiers) { ZEPHIR_INIT_VAR(sqlTable); ZEPHIR_CONCAT_VVV(sqlTable, escapeChar, tableName, escapeChar); } else { ZEPHIR_CPY_WRT(sqlTable, tableName); } ZEPHIR_OBS_VAR(schemaName); zephir_array_fetch_long(&schemaName, table, 1, PH_NOISY TSRMLS_CC); if (Z_TYPE_P(schemaName) != IS_ARRAY) { ZEPHIR_INIT_VAR(sqlSchema); if (ZEPHIR_GLOBAL(db).escape_identifiers) { ZEPHIR_CONCAT_VVVSV(sqlSchema, escapeChar, schemaName, escapeChar, ".", sqlTable); } else { ZEPHIR_CONCAT_VSV(sqlSchema, schemaName, ".", sqlTable); } } else { ZEPHIR_CPY_WRT(sqlSchema, sqlTable); } ZEPHIR_OBS_VAR(aliasName); if (zephir_array_isset_long_fetch(&aliasName, table, 2, 0 TSRMLS_CC)) { ZEPHIR_INIT_VAR(sqlTableAlias); if (ZEPHIR_GLOBAL(db).escape_identifiers) { ZEPHIR_CONCAT_VSVVV(sqlTableAlias, sqlSchema, " AS ", escapeChar, aliasName, escapeChar); } else { ZEPHIR_CONCAT_VSV(sqlTableAlias, sqlSchema, " AS ", aliasName); } } else { ZEPHIR_CPY_WRT(sqlTableAlias, sqlSchema); } RETURN_CCTOR(sqlTableAlias); } if (ZEPHIR_GLOBAL(db).escape_identifiers) { ZEPHIR_CONCAT_VVV(return_value, escapeChar, table, escapeChar); RETURN_MM(); } RETURN_CCTOR(table); }
/** * Transforms an intermediate representation for a expression into a database system valid expression * * @param array expression * @param string escapeChar * @return string */ PHP_METHOD(Pdm_Db_AbstractDialect, getSqlExpression) { zephir_fcall_cache_entry *_10 = NULL; HashTable *_7, *_13; HashPosition _6, _12; int ZEPHIR_LAST_CALL_STATUS; zval *escapeChar = NULL, *_1 = NULL; zval *expression, *escapeChar_param = NULL, *type, *domain, *operator, *left = NULL, *right = NULL, *name = NULL, *sqlItems, *escapedName = NULL, *sqlArguments, *arguments, *argument = NULL, *item = NULL, *_0, *_2, *_3, *_4, *_5 = NULL, **_8, *_9 = NULL, *_11 = NULL, **_14, *_15, *_16; ZEPHIR_MM_GROW(); zephir_fetch_params(1, 1, 1, &expression, &escapeChar_param); if (!escapeChar_param) { ZEPHIR_INIT_VAR(escapeChar); ZVAL_EMPTY_STRING(escapeChar); } else { zephir_get_strval(escapeChar, escapeChar_param); } if (ZEPHIR_GLOBAL(db).escape_identifiers) { if (ZEPHIR_IS_STRING_IDENTICAL(escapeChar, "")) { ZEPHIR_OBS_VAR(_0); zephir_read_property_this(&_0, this_ptr, SL("escapeChar"), PH_NOISY_CC); zephir_get_strval(_1, _0); ZEPHIR_CPY_WRT(escapeChar, _1); } } if (Z_TYPE_P(expression) != IS_ARRAY) { ZEPHIR_THROW_EXCEPTION_DEBUG_STR(pdm_db_exception_ce, "Invalid SQL expression", "pdm/db/abstractdialect.zep", 176); return; } ZEPHIR_OBS_VAR(type); if (!(zephir_array_isset_string_fetch(&type, expression, SS("type"), 0 TSRMLS_CC))) { ZEPHIR_THROW_EXCEPTION_DEBUG_STR(pdm_db_exception_ce, "Invalid SQL expression", "pdm/db/abstractdialect.zep", 180); return; } if (ZEPHIR_IS_STRING(type, "qualified")) { ZEPHIR_OBS_VAR(name); zephir_array_fetch_string(&name, expression, SL("name"), PH_NOISY TSRMLS_CC); if (ZEPHIR_GLOBAL(db).escape_identifiers) { ZEPHIR_INIT_VAR(escapedName); ZEPHIR_CONCAT_VVV(escapedName, escapeChar, name, escapeChar); } else { ZEPHIR_CPY_WRT(escapedName, name); } ZEPHIR_OBS_VAR(domain); if (zephir_array_isset_string_fetch(&domain, expression, SS("domain"), 0 TSRMLS_CC)) { if (ZEPHIR_GLOBAL(db).escape_identifiers) { ZEPHIR_CONCAT_VVVSV(return_value, escapeChar, domain, escapeChar, ".", escapedName); RETURN_MM(); } else { ZEPHIR_CONCAT_VSV(return_value, domain, ".", escapedName); RETURN_MM(); } } RETURN_CCTOR(escapedName); } if (ZEPHIR_IS_STRING(type, "literal")) { zephir_array_fetch_string(&_2, expression, SL("value"), PH_NOISY | PH_READONLY TSRMLS_CC); RETURN_CTOR(_2); } if (ZEPHIR_IS_STRING(type, "binary-op")) { zephir_array_fetch_string(&_2, expression, SL("left"), PH_NOISY | PH_READONLY TSRMLS_CC); ZEPHIR_CALL_METHOD(&left, this_ptr, "getsqlexpression", NULL, _2, escapeChar); zephir_check_call_status(); zephir_array_fetch_string(&_3, expression, SL("right"), PH_NOISY | PH_READONLY TSRMLS_CC); ZEPHIR_CALL_METHOD(&right, this_ptr, "getsqlexpression", NULL, _3, escapeChar); zephir_check_call_status(); zephir_array_fetch_string(&_4, expression, SL("op"), PH_NOISY | PH_READONLY TSRMLS_CC); ZEPHIR_CONCAT_VSVSV(return_value, left, " ", _4, " ", right); RETURN_MM(); } if (ZEPHIR_IS_STRING(type, "unary-op")) { ZEPHIR_OBS_VAR(operator); zephir_array_fetch_string(&operator, expression, SL("op"), PH_NOISY TSRMLS_CC); ZEPHIR_OBS_NVAR(left); if (zephir_array_isset_string_fetch(&left, expression, SS("left"), 0 TSRMLS_CC)) { ZEPHIR_CALL_METHOD(&_5, this_ptr, "getsqlexpression", NULL, left, escapeChar); zephir_check_call_status(); ZEPHIR_CONCAT_VV(return_value, _5, operator); RETURN_MM(); } ZEPHIR_OBS_NVAR(right); if (zephir_array_isset_string_fetch(&right, expression, SS("right"), 0 TSRMLS_CC)) { ZEPHIR_CALL_METHOD(&_5, this_ptr, "getsqlexpression", NULL, right, escapeChar); zephir_check_call_status(); ZEPHIR_CONCAT_VV(return_value, _5, operator); RETURN_MM(); } } if (ZEPHIR_IS_STRING(type, "placeholder")) { zephir_array_fetch_string(&_2, expression, SL("value"), PH_NOISY | PH_READONLY TSRMLS_CC); RETURN_CTOR(_2); } if (ZEPHIR_IS_STRING(type, "parentheses")) { zephir_array_fetch_string(&_2, expression, SL("left"), PH_NOISY | PH_READONLY TSRMLS_CC); ZEPHIR_CALL_METHOD(&_5, this_ptr, "getsqlexpression", NULL, _2, escapeChar); zephir_check_call_status(); ZEPHIR_CONCAT_SVS(return_value, "(", _5, ")"); RETURN_MM(); } if (ZEPHIR_IS_STRING(type, "functionCall")) { ZEPHIR_OBS_NVAR(name); zephir_array_fetch_string(&name, expression, SL("name"), PH_NOISY TSRMLS_CC); ZEPHIR_INIT_VAR(sqlArguments); array_init(sqlArguments); ZEPHIR_OBS_VAR(arguments); if (zephir_array_isset_string_fetch(&arguments, expression, SS("arguments"), 0 TSRMLS_CC)) { zephir_is_iterable(arguments, &_7, &_6, 0, 0); for ( ; zephir_hash_get_current_data_ex(_7, (void**) &_8, &_6) == SUCCESS ; zephir_hash_move_forward_ex(_7, &_6) ) { ZEPHIR_GET_HVALUE(argument, _8); ZEPHIR_CALL_METHOD(&_9, this_ptr, "getsqlexpression", &_10, argument, escapeChar); zephir_check_call_status(); zephir_array_append(&sqlArguments, _9, PH_SEPARATE); } ZEPHIR_INIT_VAR(_11); zephir_fast_join_str(_11, SL(", "), sqlArguments TSRMLS_CC); ZEPHIR_CONCAT_VSVS(return_value, name, "(", _11, ")"); RETURN_MM(); } else { ZEPHIR_CONCAT_VS(return_value, name, "()"); RETURN_MM(); } } if (ZEPHIR_IS_STRING(type, "list")) { ZEPHIR_INIT_VAR(sqlItems); array_init(sqlItems); zephir_array_fetch_long(&_2, expression, 0, PH_NOISY | PH_READONLY TSRMLS_CC); zephir_is_iterable(_2, &_13, &_12, 0, 0); for ( ; zephir_hash_get_current_data_ex(_13, (void**) &_14, &_12) == SUCCESS ; zephir_hash_move_forward_ex(_13, &_12) ) { ZEPHIR_GET_HVALUE(item, _14); ZEPHIR_CALL_METHOD(&_5, this_ptr, "getsqlexpression", &_10, item, escapeChar); zephir_check_call_status(); zephir_array_append(&sqlItems, _5, PH_SEPARATE); } ZEPHIR_INIT_NVAR(_11); zephir_fast_join_str(_11, SL(", "), sqlItems TSRMLS_CC); ZEPHIR_CONCAT_SVS(return_value, "(", _11, ")"); RETURN_MM(); } if (ZEPHIR_IS_STRING(type, "all")) { RETURN_MM_STRING("*", 1); } if (ZEPHIR_IS_STRING(type, "cast")) { zephir_array_fetch_string(&_2, expression, SL("left"), PH_NOISY | PH_READONLY TSRMLS_CC); ZEPHIR_CALL_METHOD(&left, this_ptr, "getsqlexpression", &_10, _2, escapeChar); zephir_check_call_status(); zephir_array_fetch_string(&_3, expression, SL("right"), PH_NOISY | PH_READONLY TSRMLS_CC); ZEPHIR_CALL_METHOD(&right, this_ptr, "getsqlexpression", &_10, _3, escapeChar); zephir_check_call_status(); ZEPHIR_CONCAT_SVSVS(return_value, "CAST(", left, " AS ", right, ")"); RETURN_MM(); } if (ZEPHIR_IS_STRING(type, "convert")) { zephir_array_fetch_string(&_2, expression, SL("left"), PH_NOISY | PH_READONLY TSRMLS_CC); ZEPHIR_CALL_METHOD(&left, this_ptr, "getsqlexpression", &_10, _2, escapeChar); zephir_check_call_status(); zephir_array_fetch_string(&_3, expression, SL("right"), PH_NOISY | PH_READONLY TSRMLS_CC); ZEPHIR_CALL_METHOD(&right, this_ptr, "getsqlexpression", &_10, _3, escapeChar); zephir_check_call_status(); ZEPHIR_CONCAT_SVSVS(return_value, "CONVERT(", left, " USING ", right, ")"); RETURN_MM(); } ZEPHIR_INIT_VAR(_15); object_init_ex(_15, pdm_db_exception_ce); ZEPHIR_INIT_VAR(_16); ZEPHIR_CONCAT_SVS(_16, "Invalid SQL expression type '", type, "'"); ZEPHIR_CALL_METHOD(NULL, _15, "__construct", NULL, _16); zephir_check_call_status(); zephir_throw_exception_debug(_15, "pdm/db/abstractdialect.zep", 287 TSRMLS_CC); ZEPHIR_MM_RESTORE(); return; }