Example #1
0
/**
 * Generates the SQL for LIMIT clause
 */
PHP_METHOD(Phalcon_Db_Dialect_Oracle, limit) {

	int limit = 0, offset;
	zval *sqlQuery_param = NULL, *number, *_0$$4, *_1$$4, _2$$4, *_3$$3, *_4$$3, _5$$3, *_6$$5, _7$$5, _9$$6, _11$$7;
	zval *sqlQuery = NULL, *_8, *_10$$6, *_12$$7;

	ZEPHIR_MM_GROW();
	zephir_fetch_params(1, 2, 0, &sqlQuery_param, &number);

	if (unlikely(Z_TYPE_P(sqlQuery_param) != IS_STRING && Z_TYPE_P(sqlQuery_param) != IS_NULL)) {
		zephir_throw_exception_string(spl_ce_InvalidArgumentException, SL("Parameter 'sqlQuery' must be a string") TSRMLS_CC);
		RETURN_MM_NULL();
	}
	if (likely(Z_TYPE_P(sqlQuery_param) == IS_STRING)) {
		zephir_get_strval(sqlQuery, sqlQuery_param);
	} else {
		ZEPHIR_INIT_VAR(sqlQuery);
		ZVAL_EMPTY_STRING(sqlQuery);
	}


	offset = 0;
	if (Z_TYPE_P(number) == IS_ARRAY) {
		if (zephir_array_isset_long(number, 1)) {
			ZEPHIR_INIT_VAR(_0$$4);
			zephir_array_fetch_long(&_1$$4, number, 1, PH_NOISY | PH_READONLY, "phalcon/db/dialect/oracle.zep", 51 TSRMLS_CC);
			ZEPHIR_SINIT_VAR(_2$$4);
			ZVAL_STRING(&_2$$4, "'", 0);
			zephir_fast_trim(_0$$4, _1$$4, &_2$$4, ZEPHIR_TRIM_BOTH TSRMLS_CC);
			offset = zephir_get_intval(_0$$4);
		}
		ZEPHIR_INIT_VAR(_3$$3);
		zephir_array_fetch_long(&_4$$3, number, 0, PH_NOISY | PH_READONLY, "phalcon/db/dialect/oracle.zep", 54 TSRMLS_CC);
		ZEPHIR_SINIT_VAR(_5$$3);
		ZVAL_STRING(&_5$$3, "'", 0);
		zephir_fast_trim(_3$$3, _4$$3, &_5$$3, ZEPHIR_TRIM_BOTH TSRMLS_CC);
		limit = (zephir_get_intval(_3$$3) + offset);
	} else {
		ZEPHIR_INIT_VAR(_6$$5);
		ZEPHIR_SINIT_VAR(_7$$5);
		ZVAL_STRING(&_7$$5, "'", 0);
		zephir_fast_trim(_6$$5, number, &_7$$5, ZEPHIR_TRIM_BOTH TSRMLS_CC);
		limit = zephir_get_intval(_6$$5);
	}
	ZEPHIR_INIT_VAR(_8);
	ZEPHIR_CONCAT_SVS(_8, "SELECT * FROM (SELECT Z1.*, ROWNUM PHALCON_RN FROM (", sqlQuery, ") Z1");
	ZEPHIR_CPY_WRT(sqlQuery, _8);
	if (limit != 0) {
		ZEPHIR_SINIT_VAR(_9$$6);
		ZVAL_LONG(&_9$$6, limit);
		ZEPHIR_INIT_VAR(_10$$6);
		ZEPHIR_CONCAT_SV(_10$$6, " WHERE ROWNUM <= ", &_9$$6);
		zephir_concat_self(&sqlQuery, _10$$6 TSRMLS_CC);
	}
	zephir_concat_self_str(&sqlQuery, ")", sizeof(")")-1 TSRMLS_CC);
	if (offset != 0) {
		ZEPHIR_SINIT_VAR(_11$$7);
		ZVAL_LONG(&_11$$7, offset);
		ZEPHIR_INIT_VAR(_12$$7);
		ZEPHIR_CONCAT_SV(_12$$7, " WHERE PHALCON_RN >= ", &_11$$7);
		zephir_concat_self(&sqlQuery, _12$$7 TSRMLS_CC);
	}
	RETURN_CTOR(sqlQuery);

}
Example #2
0
/**
 * Removes padding @a padding_type from @a text
 * If the function detects that the text was not padded, it will return it unmodified
 *
 * @param string text Message to be unpadded
 * @param string mode Encryption mode; unpadding is applied only in CBC or ECB mode
 * @param int blockSize Cipher block size
 * @param int paddingType Padding scheme
 */
PHP_METHOD(Phalcon_Crypt, _cryptUnpadText) {

	unsigned char _23$$11, _25$$11, _27$$15, _30$$17;
	zend_bool _0, _1, _2, _22$$11, _24$$11, _26$$15, _28$$15, _29$$17, _31$$17, _32$$3;
	long length = 0;
	zephir_fcall_cache_entry *_6 = NULL, *_9 = NULL, *_11 = NULL;
	int blockSize, paddingType, ZEPHIR_LAST_CALL_STATUS, i = 0, paddingSize, ord = 0;
	zval *text_param = NULL, *mode_param = NULL, *blockSize_param = NULL, *paddingType_param = NULL, *padding = NULL, *last = NULL, _3$$4, _4$$4, *_5$$4 = NULL, _7$$5 = zval_used_for_init, *_8$$5 = NULL, *_10$$5 = NULL, *_12$$5, _13$$7, _14$$7, *_15$$7 = NULL, _16$$8 = zval_used_for_init, *_17$$8 = NULL, *_18$$8, _19$$10, _20$$10, *_21$$10 = NULL, _33$$21, _34$$21;
	zval *text = NULL, *mode = NULL;

	ZEPHIR_MM_GROW();
	zephir_fetch_params(1, 4, 0, &text_param, &mode_param, &blockSize_param, &paddingType_param);

	zephir_get_strval(text, text_param);
	if (unlikely(Z_TYPE_P(mode_param) != IS_STRING && Z_TYPE_P(mode_param) != IS_NULL)) {
		zephir_throw_exception_string(spl_ce_InvalidArgumentException, SL("Parameter 'mode' must be a string") TSRMLS_CC);
		RETURN_MM_NULL();
	}
	if (likely(Z_TYPE_P(mode_param) == IS_STRING)) {
		zephir_get_strval(mode, mode_param);
	} else {
		ZEPHIR_INIT_VAR(mode);
		ZVAL_EMPTY_STRING(mode);
	}
	if (unlikely(Z_TYPE_P(blockSize_param) != IS_LONG)) {
		zephir_throw_exception_string(spl_ce_InvalidArgumentException, SL("Parameter 'blockSize' must be a int") TSRMLS_CC);
		RETURN_MM_NULL();
	}
	blockSize = Z_LVAL_P(blockSize_param);
	if (unlikely(Z_TYPE_P(paddingType_param) != IS_LONG)) {
		zephir_throw_exception_string(spl_ce_InvalidArgumentException, SL("Parameter 'paddingType' must be a int") TSRMLS_CC);
		RETURN_MM_NULL();
	}
	paddingType = Z_LVAL_P(paddingType_param);


	paddingSize = 0;
	length = zephir_fast_strlen_ev(text);
	_0 = length > 0;
	if (_0) {
		_0 = (zephir_safe_mod_long_long(length, blockSize TSRMLS_CC) == 0);
	}
	_1 = _0;
	if (_1) {
		_2 = ZEPHIR_IS_STRING(mode, "cbc");
		if (!(_2)) {
			_2 = ZEPHIR_IS_STRING(mode, "ecb");
		}
		_1 = _2;
	}
	if (_1) {
		do {
			if (paddingType == 1) {
				ZEPHIR_SINIT_VAR(_3$$4);
				ZVAL_LONG(&_3$$4, (length - 1));
				ZEPHIR_SINIT_VAR(_4$$4);
				ZVAL_LONG(&_4$$4, 1);
				ZEPHIR_INIT_VAR(last);
				zephir_substr(last, text, zephir_get_intval(&_3$$4), 1 , 0);
				ZEPHIR_CALL_FUNCTION(&_5$$4, "ord", &_6, 134, last);
				zephir_check_call_status();
				ord = zephir_get_intval(_5$$4);
				if (ord <= blockSize) {
					paddingSize = ord;
					ZEPHIR_SINIT_VAR(_7$$5);
					ZVAL_LONG(&_7$$5, 0);
					ZEPHIR_CALL_FUNCTION(&_8$$5, "chr", &_9, 132, &_7$$5);
					zephir_check_call_status();
					ZEPHIR_SINIT_NVAR(_7$$5);
					ZVAL_LONG(&_7$$5, (paddingSize - 1));
					ZEPHIR_CALL_FUNCTION(&_10$$5, "str_repeat", &_11, 133, _8$$5, &_7$$5);
					zephir_check_call_status();
					ZEPHIR_INIT_VAR(padding);
					ZEPHIR_CONCAT_VV(padding, _10$$5, last);
					ZEPHIR_SINIT_NVAR(_7$$5);
					ZVAL_LONG(&_7$$5, (length - paddingSize));
					ZEPHIR_INIT_VAR(_12$$5);
					zephir_substr(_12$$5, text, zephir_get_intval(&_7$$5), 0, ZEPHIR_SUBSTR_NO_LENGTH);
					if (!ZEPHIR_IS_EQUAL(_12$$5, padding)) {
						paddingSize = 0;
					}
				}
				break;
			}
			if (paddingType == 2) {
				ZEPHIR_SINIT_VAR(_13$$7);
				ZVAL_LONG(&_13$$7, (length - 1));
				ZEPHIR_SINIT_VAR(_14$$7);
				ZVAL_LONG(&_14$$7, 1);
				ZEPHIR_INIT_NVAR(last);
				zephir_substr(last, text, zephir_get_intval(&_13$$7), 1 , 0);
				ZEPHIR_CALL_FUNCTION(&_15$$7, "ord", &_6, 134, last);
				zephir_check_call_status();
				ord = zephir_get_intval(_15$$7);
				if (ord <= blockSize) {
					paddingSize = ord;
					ZEPHIR_SINIT_VAR(_16$$8);
					ZVAL_LONG(&_16$$8, paddingSize);
					ZEPHIR_CALL_FUNCTION(&_17$$8, "chr", &_9, 132, &_16$$8);
					zephir_check_call_status();
					ZEPHIR_SINIT_NVAR(_16$$8);
					ZVAL_LONG(&_16$$8, paddingSize);
					ZEPHIR_CALL_FUNCTION(&padding, "str_repeat", &_11, 133, _17$$8, &_16$$8);
					zephir_check_call_status();
					ZEPHIR_SINIT_NVAR(_16$$8);
					ZVAL_LONG(&_16$$8, (length - paddingSize));
					ZEPHIR_INIT_VAR(_18$$8);
					zephir_substr(_18$$8, text, zephir_get_intval(&_16$$8), 0, ZEPHIR_SUBSTR_NO_LENGTH);
					if (!ZEPHIR_IS_EQUAL(_18$$8, padding)) {
						paddingSize = 0;
					}
				}
				break;
			}
			if (paddingType == 3) {
				ZEPHIR_SINIT_VAR(_19$$10);
				ZVAL_LONG(&_19$$10, (length - 1));
				ZEPHIR_SINIT_VAR(_20$$10);
				ZVAL_LONG(&_20$$10, 1);
				ZEPHIR_INIT_NVAR(last);
				zephir_substr(last, text, zephir_get_intval(&_19$$10), 1 , 0);
				ZEPHIR_CALL_FUNCTION(&_21$$10, "ord", &_6, 134, last);
				zephir_check_call_status();
				paddingSize = zephir_get_intval(_21$$10);
				break;
			}
			if (paddingType == 4) {
				i = (length - 1);
				while (1) {
					_22$$11 = i > 0;
					if (_22$$11) {
						_23$$11 = ZEPHIR_STRING_OFFSET(text, i);
						_22$$11 = _23$$11 == 0x00;
					}
					_24$$11 = _22$$11;
					if (_24$$11) {
						_24$$11 = paddingSize < blockSize;
					}
					if (!(_24$$11)) {
						break;
					}
					paddingSize++;
					i--;
				}
				_25$$11 = ZEPHIR_STRING_OFFSET(text, i);
				if (_25$$11 == 0x80) {
					paddingSize++;
				} else {
					paddingSize = 0;
				}
				break;
			}
			if (paddingType == 5) {
				i = (length - 1);
				while (1) {
					_26$$15 = i >= 0;
					if (_26$$15) {
						_27$$15 = ZEPHIR_STRING_OFFSET(text, i);
						_26$$15 = _27$$15 == 0x00;
					}
					_28$$15 = _26$$15;
					if (_28$$15) {
						_28$$15 = paddingSize <= blockSize;
					}
					if (!(_28$$15)) {
						break;
					}
					paddingSize++;
					i--;
				}
				break;
			}
			if (paddingType == 6) {
				i = (length - 1);
				while (1) {
					_29$$17 = i >= 0;
					if (_29$$17) {
						_30$$17 = ZEPHIR_STRING_OFFSET(text, i);
						_29$$17 = _30$$17 == 0x20;
					}
					_31$$17 = _29$$17;
					if (_31$$17) {
						_31$$17 = paddingSize <= blockSize;
					}
					if (!(_31$$17)) {
						break;
					}
					paddingSize++;
					i--;
				}
				break;
			}
			break;
		} while(0);

		_32$$3 = (paddingSize) ? 1 : 0;
		if (_32$$3) {
			_32$$3 = paddingSize <= blockSize;
		}
		if (_32$$3) {
			if (paddingSize < length) {
				ZEPHIR_SINIT_VAR(_33$$21);
				ZVAL_LONG(&_33$$21, 0);
				ZEPHIR_SINIT_VAR(_34$$21);
				ZVAL_LONG(&_34$$21, (length - paddingSize));
				zephir_substr(return_value, text, 0 , zephir_get_intval(&_34$$21), 0);
				RETURN_MM();
			}
			RETURN_MM_STRING("", 1);
		} else {
			paddingSize = 0;
		}
	}
	if (!(paddingSize)) {
		RETURN_CTOR(text);
	}
	ZEPHIR_MM_RESTORE();

}
Example #3
0
/**
 * Decrypts an encrypted text
 *
 *<code>
 *	echo $crypt->decrypt($encrypted, "decrypt password");
 *</code>
 */
PHP_METHOD(Phalcon_Crypt, decrypt) {

	zend_bool _3;
	int ZEPHIR_LAST_CALL_STATUS;
	zval *text_param = NULL, *key = NULL, *decryptKey = NULL, *ivSize = NULL, *cipher = NULL, *mode = NULL, *keySize = NULL, *length = NULL, *blockSize = NULL, *paddingType = NULL, *decrypted = NULL, *_0, _1, *_2;
	zval *text = NULL;

	ZEPHIR_MM_GROW();
	zephir_fetch_params(1, 1, 1, &text_param, &key);

	if (unlikely(Z_TYPE_P(text_param) != IS_STRING && Z_TYPE_P(text_param) != IS_NULL)) {
		zephir_throw_exception_string(spl_ce_InvalidArgumentException, SL("Parameter 'text' must be a string") TSRMLS_CC);
		RETURN_MM_NULL();
	}
	if (likely(Z_TYPE_P(text_param) == IS_STRING)) {
		zephir_get_strval(text, text_param);
	} else {
		ZEPHIR_INIT_VAR(text);
		ZVAL_EMPTY_STRING(text);
	}
	if (!key) {
		key = ZEPHIR_GLOBAL(global_null);
	}


	if (!((zephir_function_exists_ex(SS("mcrypt_get_iv_size") TSRMLS_CC) == SUCCESS))) {
		ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_crypt_exception_ce, "mcrypt extension is required", "phalcon/crypt.zep", 355);
		return;
	}
	if (Z_TYPE_P(key) == IS_NULL) {
		ZEPHIR_OBS_VAR(decryptKey);
		zephir_read_property_this(&decryptKey, this_ptr, SL("_key"), PH_NOISY_CC);
	} else {
		ZEPHIR_CPY_WRT(decryptKey, key);
	}
	if (ZEPHIR_IS_EMPTY(decryptKey)) {
		ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_crypt_exception_ce, "Decryption key cannot be empty", "phalcon/crypt.zep", 365);
		return;
	}
	ZEPHIR_OBS_VAR(cipher);
	zephir_read_property_this(&cipher, this_ptr, SL("_cipher"), PH_NOISY_CC);
	ZEPHIR_OBS_VAR(mode);
	zephir_read_property_this(&mode, this_ptr, SL("_mode"), PH_NOISY_CC);
	ZEPHIR_CALL_FUNCTION(&ivSize, "mcrypt_get_iv_size", NULL, 135, cipher, mode);
	zephir_check_call_status();
	ZEPHIR_INIT_VAR(keySize);
	ZVAL_LONG(keySize, zephir_fast_strlen_ev(decryptKey));
	if (ZEPHIR_GT(keySize, ivSize)) {
		ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_crypt_exception_ce, "Size of key is too large for this algorithm", "phalcon/crypt.zep", 374);
		return;
	}
	ZEPHIR_INIT_VAR(length);
	ZVAL_LONG(length, zephir_fast_strlen_ev(text));
	if (ZEPHIR_GT(keySize, length)) {
		ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_crypt_exception_ce, "Size of IV is larger than text to decrypt", "phalcon/crypt.zep", 379);
		return;
	}
	ZEPHIR_INIT_VAR(_0);
	zephir_substr(_0, text, zephir_get_intval(ivSize), 0, ZEPHIR_SUBSTR_NO_LENGTH);
	ZEPHIR_SINIT_VAR(_1);
	ZVAL_LONG(&_1, 0);
	ZEPHIR_INIT_VAR(_2);
	zephir_substr(_2, text, 0 , zephir_get_intval(ivSize), 0);
	ZEPHIR_CALL_FUNCTION(&decrypted, "mcrypt_decrypt", NULL, 139, cipher, decryptKey, _0, mode, _2);
	zephir_check_call_status();
	ZEPHIR_CALL_FUNCTION(&blockSize, "mcrypt_get_block_size", NULL, 137, cipher, mode);
	zephir_check_call_status();
	ZEPHIR_OBS_VAR(paddingType);
	zephir_read_property_this(&paddingType, this_ptr, SL("_padding"), PH_NOISY_CC);
	_3 = ZEPHIR_IS_STRING(mode, "cbc");
	if (!(_3)) {
		_3 = ZEPHIR_IS_STRING(mode, "ecb");
	}
	if (_3) {
		ZEPHIR_RETURN_CALL_METHOD(this_ptr, "_cryptunpadtext", NULL, 0, decrypted, mode, blockSize, paddingType);
		zephir_check_call_status();
		RETURN_MM();
	}
	RETURN_CCTOR(decrypted);

}
Example #4
0
/**
 * Set an specific argument
 */
PHP_METHOD(Phalcon_Cli_Console, setArgument) {

	HashTable *_3;
	HashPosition _2;
	int ZEPHIR_LAST_CALL_STATUS;
	zephir_fcall_cache_entry *_1 = NULL, *_8 = NULL, *_27 = NULL;
	zend_bool str, shift, _0;
	zval *arguments_param = NULL, *str_param = NULL, *shift_param = NULL, *arg = NULL, *pos = NULL, *args = NULL, *opts = NULL, *handleArgs = NULL, **_4, _5$$5 = zval_used_for_init, _6$$5 = zval_used_for_init, *_7$$5 = NULL, _9$$6 = zval_used_for_init, *_10$$7 = NULL, _11$$7 = zval_used_for_init, *_12$$7 = NULL, *_13$$7 = NULL, _14$$7 = zval_used_for_init, _15$$7 = zval_used_for_init, *_16$$7 = NULL, *_17$$8 = NULL, _18$$8 = zval_used_for_init, *_19$$8 = NULL, _20$$9 = zval_used_for_init, _21$$9 = zval_used_for_init, *_22$$9 = NULL, _23$$10 = zval_used_for_init, *_24$$10 = NULL, *_25$$13, *_26$$13 = NULL, *_28$$15 = NULL, *_29$$16 = NULL, *_30$$17;
	zval *arguments = NULL;

	ZEPHIR_MM_GROW();
	zephir_fetch_params(1, 0, 3, &arguments_param, &str_param, &shift_param);

	if (!arguments_param) {
		ZEPHIR_INIT_VAR(arguments);
		array_init(arguments);
	} else {
	arguments = arguments_param;
	}
	if (!str_param) {
		str = 1;
	} else {
	if (unlikely(Z_TYPE_P(str_param) != IS_BOOL)) {
		zephir_throw_exception_string(spl_ce_InvalidArgumentException, SL("Parameter 'str' must be a bool") TSRMLS_CC);
		RETURN_MM_NULL();
	}
	str = Z_BVAL_P(str_param);
	}
	if (!shift_param) {
		shift = 1;
	} else {
	if (unlikely(Z_TYPE_P(shift_param) != IS_BOOL)) {
		zephir_throw_exception_string(spl_ce_InvalidArgumentException, SL("Parameter 'shift' must be a bool") TSRMLS_CC);
		RETURN_MM_NULL();
	}
	shift = Z_BVAL_P(shift_param);
	}


	ZEPHIR_INIT_VAR(args);
	array_init(args);
	ZEPHIR_INIT_VAR(opts);
	array_init(opts);
	ZEPHIR_INIT_VAR(handleArgs);
	array_init(handleArgs);
	_0 = shift;
	if (_0) {
		_0 = ((zephir_fast_count_int(arguments TSRMLS_CC)) ? 1 : 0);
	}
	if (_0) {
		ZEPHIR_MAKE_REF(arguments);
		ZEPHIR_CALL_FUNCTION(NULL, "array_shift", &_1, 132, arguments);
		ZEPHIR_UNREF(arguments);
		zephir_check_call_status();
	}
	zephir_is_iterable(arguments, &_3, &_2, 0, 0, "phalcon/cli/console.zep", 199);
	for (
	  ; zephir_hash_get_current_data_ex(_3, (void**) &_4, &_2) == SUCCESS
	  ; zephir_hash_move_forward_ex(_3, &_2)
	) {
		ZEPHIR_GET_HVALUE(arg, _4);
		if (Z_TYPE_P(arg) == IS_STRING) {
			ZEPHIR_SINIT_NVAR(_5$$5);
			ZVAL_STRING(&_5$$5, "--", 0);
			ZEPHIR_SINIT_NVAR(_6$$5);
			ZVAL_LONG(&_6$$5, 2);
			ZEPHIR_CALL_FUNCTION(&_7$$5, "strncmp", &_8, 133, arg, &_5$$5, &_6$$5);
			zephir_check_call_status();
			if (ZEPHIR_IS_LONG(_7$$5, 0)) {
				ZEPHIR_SINIT_NVAR(_9$$6);
				ZVAL_STRING(&_9$$6, "=", 0);
				ZEPHIR_INIT_NVAR(pos);
				zephir_fast_strpos(pos, arg, &_9$$6, 0 );
				if (zephir_is_true(pos)) {
					ZEPHIR_INIT_NVAR(_10$$7);
					ZEPHIR_SINIT_NVAR(_11$$7);
					ZVAL_LONG(&_11$$7, (zephir_get_numberval(pos) + 1));
					ZEPHIR_INIT_NVAR(_12$$7);
					zephir_substr(_12$$7, arg, zephir_get_intval(&_11$$7), 0, ZEPHIR_SUBSTR_NO_LENGTH);
					zephir_fast_trim(_10$$7, _12$$7, NULL , ZEPHIR_TRIM_BOTH TSRMLS_CC);
					ZEPHIR_INIT_NVAR(_13$$7);
					ZEPHIR_SINIT_NVAR(_14$$7);
					ZVAL_LONG(&_14$$7, 2);
					ZEPHIR_SINIT_NVAR(_15$$7);
					ZVAL_LONG(&_15$$7, (zephir_get_numberval(pos) - 2));
					ZEPHIR_INIT_NVAR(_16$$7);
					zephir_substr(_16$$7, arg, 2 , zephir_get_intval(&_15$$7), 0);
					zephir_fast_trim(_13$$7, _16$$7, NULL , ZEPHIR_TRIM_BOTH TSRMLS_CC);
					zephir_array_update_zval(&opts, _13$$7, &_10$$7, PH_COPY | PH_SEPARATE);
				} else {
					ZEPHIR_INIT_NVAR(_17$$8);
					ZEPHIR_SINIT_NVAR(_18$$8);
					ZVAL_LONG(&_18$$8, 2);
					ZEPHIR_INIT_NVAR(_19$$8);
					zephir_substr(_19$$8, arg, 2 , 0, ZEPHIR_SUBSTR_NO_LENGTH);
					zephir_fast_trim(_17$$8, _19$$8, NULL , ZEPHIR_TRIM_BOTH TSRMLS_CC);
					zephir_array_update_zval(&opts, _17$$8, &ZEPHIR_GLOBAL(global_true), PH_COPY | PH_SEPARATE);
				}
			} else {
				ZEPHIR_SINIT_NVAR(_20$$9);
				ZVAL_STRING(&_20$$9, "-", 0);
				ZEPHIR_SINIT_NVAR(_21$$9);
				ZVAL_LONG(&_21$$9, 1);
				ZEPHIR_CALL_FUNCTION(&_22$$9, "strncmp", &_8, 133, arg, &_20$$9, &_21$$9);
				zephir_check_call_status();
				if (ZEPHIR_IS_LONG(_22$$9, 0)) {
					ZEPHIR_SINIT_NVAR(_23$$10);
					ZVAL_LONG(&_23$$10, 1);
					ZEPHIR_INIT_NVAR(_24$$10);
					zephir_substr(_24$$10, arg, 1 , 0, ZEPHIR_SUBSTR_NO_LENGTH);
					zephir_array_update_zval(&opts, _24$$10, &ZEPHIR_GLOBAL(global_true), PH_COPY | PH_SEPARATE);
				} else {
					zephir_array_append(&args, arg, PH_SEPARATE, "phalcon/cli/console.zep", 191);
				}
			}
		} else {
			zephir_array_append(&args, arg, PH_SEPARATE, "phalcon/cli/console.zep", 195);
		}
	}
	if (str) {
		ZEPHIR_INIT_VAR(_25$$13);
		ZEPHIR_CALL_CE_STATIC(&_26$$13, phalcon_cli_router_route_ce, "getdelimiter", &_27, 134);
		zephir_check_call_status();
		zephir_fast_join(_25$$13, _26$$13, args TSRMLS_CC);
		zephir_update_property_this(this_ptr, SL("_arguments"), _25$$13 TSRMLS_CC);
	} else {
		if (zephir_fast_count_int(args TSRMLS_CC)) {
			ZEPHIR_MAKE_REF(args);
			ZEPHIR_CALL_FUNCTION(&_28$$15, "array_shift", &_1, 132, args);
			ZEPHIR_UNREF(args);
			zephir_check_call_status();
			zephir_array_update_string(&handleArgs, SL("task"), &_28$$15, PH_COPY | PH_SEPARATE);
		}
		if (zephir_fast_count_int(args TSRMLS_CC)) {
			ZEPHIR_MAKE_REF(args);
			ZEPHIR_CALL_FUNCTION(&_29$$16, "array_shift", &_1, 132, args);
			ZEPHIR_UNREF(args);
			zephir_check_call_status();
			zephir_array_update_string(&handleArgs, SL("action"), &_29$$16, PH_COPY | PH_SEPARATE);
		}
		if (zephir_fast_count_int(args TSRMLS_CC)) {
			ZEPHIR_INIT_VAR(_30$$17);
			zephir_fast_array_merge(_30$$17, &(handleArgs), &(args) TSRMLS_CC);
			ZEPHIR_CPY_WRT(handleArgs, _30$$17);
		}
		zephir_update_property_this(this_ptr, SL("_arguments"), handleArgs TSRMLS_CC);
	}
	zephir_update_property_this(this_ptr, SL("_options"), opts TSRMLS_CC);
	RETURN_THIS();

}
Example #5
0
/**
 * @return mixed
 */
PHP_METHOD(Lynx_Annotation_RegexDocParser, parseValue) {

	int ZEPHIR_LAST_CALL_STATUS;
	zephir_nts_static zephir_fcall_cache_entry *_14 = NULL;
	HashTable *_11;
	HashPosition _10;
	zend_bool _3, _15, _20;
	zval *value, *val = NULL, *vals, *v = NULL, _0, _1, *_2, _4, *_5, _6 = zval_used_for_init, _7 = zval_used_for_init, *_8 = NULL, _9 = zval_used_for_init, **_12, *_13 = NULL, *_16, _17, _18, *_19, _21, *_22, _23, _24, *_25 = NULL, *_26;

	ZEPHIR_MM_GROW();
	zephir_fetch_params(1, 1, 0, &value);



	ZEPHIR_INIT_VAR(val);
	zephir_fast_trim(val, value, NULL , ZEPHIR_TRIM_BOTH TSRMLS_CC);
	ZEPHIR_SINIT_VAR(_0);
	ZVAL_LONG(&_0, 0);
	ZEPHIR_SINIT_VAR(_1);
	ZVAL_LONG(&_1, 1);
	ZEPHIR_INIT_VAR(_2);
	zephir_substr(_2, val, 0 , 1 , 0);
	_3 = ZEPHIR_IS_STRING(_2, "[");
	if (_3) {
		ZEPHIR_SINIT_VAR(_4);
		ZVAL_LONG(&_4, -1);
		ZEPHIR_INIT_VAR(_5);
		zephir_substr(_5, val, -1 , 0, ZEPHIR_SUBSTR_NO_LENGTH);
		_3 = ZEPHIR_IS_STRING(_5, "]");
	}
	if (_3) {
		ZEPHIR_INIT_VAR(vals);
		ZEPHIR_SINIT_VAR(_6);
		ZVAL_LONG(&_6, 1);
		ZEPHIR_SINIT_VAR(_7);
		ZVAL_LONG(&_7, -1);
		ZEPHIR_INIT_VAR(_8);
		zephir_substr(_8, val, 1 , -1 , 0);
		ZEPHIR_SINIT_VAR(_9);
		ZVAL_LONG(&_9, ',');
		zephir_fast_explode(vals, &_9, _8, LONG_MAX TSRMLS_CC);
		ZEPHIR_INIT_NVAR(val);
		array_init(val);
		zephir_is_iterable(vals, &_11, &_10, 0, 0, "lynx/Annotation/RegexDocParser.zep", 89);
		for (
		  ; zephir_hash_get_current_data_ex(_11, (void**) &_12, &_10) == SUCCESS
		  ; zephir_hash_move_forward_ex(_11, &_10)
		) {
			ZEPHIR_GET_HVALUE(v, _12);
			ZEPHIR_CALL_SELF(&_13, "parsevalue", &_14, v);
			zephir_check_call_status();
			zephir_array_append(&val, _13, PH_SEPARATE, "lynx/Annotation/RegexDocParser.zep", 86);
		}
		RETURN_CCTOR(val);
	} else {
		ZEPHIR_SINIT_NVAR(_6);
		ZVAL_LONG(&_6, 0);
		ZEPHIR_SINIT_NVAR(_7);
		ZVAL_LONG(&_7, 1);
		ZEPHIR_INIT_NVAR(_8);
		zephir_substr(_8, val, 0 , 1 , 0);
		_15 = ZEPHIR_IS_STRING(_8, "{");
		if (_15) {
			ZEPHIR_SINIT_NVAR(_9);
			ZVAL_LONG(&_9, -1);
			ZEPHIR_INIT_VAR(_16);
			zephir_substr(_16, val, -1 , 0, ZEPHIR_SUBSTR_NO_LENGTH);
			_15 = ZEPHIR_IS_STRING(_16, "}");
		}
		if (_15) {
			zephir_json_decode(return_value, &(return_value), val, 0  TSRMLS_CC);
			RETURN_MM();
		} else {
			ZEPHIR_SINIT_VAR(_17);
			ZVAL_LONG(&_17, 0);
			ZEPHIR_SINIT_VAR(_18);
			ZVAL_LONG(&_18, 1);
			ZEPHIR_INIT_VAR(_19);
			zephir_substr(_19, val, 0 , 1 , 0);
			_20 = ZEPHIR_IS_STRING(_19, "\"");
			if (_20) {
				ZEPHIR_SINIT_VAR(_21);
				ZVAL_LONG(&_21, -1);
				ZEPHIR_INIT_VAR(_22);
				zephir_substr(_22, val, -1 , 0, ZEPHIR_SUBSTR_NO_LENGTH);
				_20 = ZEPHIR_IS_STRING(_22, "\"");
			}
			if (_20) {
				ZEPHIR_SINIT_VAR(_23);
				ZVAL_LONG(&_23, 1);
				ZEPHIR_SINIT_VAR(_24);
				ZVAL_LONG(&_24, -1);
				ZEPHIR_INIT_VAR(_25);
				zephir_substr(_25, val, 1 , -1 , 0);
				ZEPHIR_CPY_WRT(val, _25);
				ZEPHIR_RETURN_CALL_SELF("parsevalue", &_14, val);
				zephir_check_call_status();
				RETURN_MM();
			} else {
				ZEPHIR_INIT_NVAR(_25);
				zephir_fast_strtolower(_25, val);
				if (ZEPHIR_IS_STRING(_25, "true")) {
					RETURN_MM_BOOL(1);
				} else {
					ZEPHIR_INIT_VAR(_26);
					zephir_fast_strtolower(_26, val);
					if (ZEPHIR_IS_STRING(_26, "false")) {
						RETURN_MM_BOOL(0);
					} else {
						if (zephir_is_numeric(val)) {
							if (zephir_get_doubleval(val) == zephir_get_intval(val)) {
								RETURN_MM_LONG(zephir_get_intval(val));
							} else {
								RETURN_MM_DOUBLE(zephir_get_doubleval(val));
							}
						}
					}
				}
			}
		}
	}
	RETURN_CCTOR(val);

}
Example #6
0
/**
 * Applies a format to a message before sending it to the log
 *
 * @param string $message
 * @param int $type
 * @param int $timestamp
 * @param array $context
 *
 * @return string
 */
PHP_METHOD(Phalcon_Logger_Formatter_Firephp, format) {

	zval *_21;
	HashTable *_10;
	HashPosition _9;
	zephir_nts_static zephir_fcall_cache_entry *_5 = NULL, *_6 = NULL, *_7 = NULL;
	zend_bool param, _14, _17;
	int type, timestamp, ZEPHIR_LAST_CALL_STATUS;
	zval *message_param = NULL, *type_param = NULL, *timestamp_param = NULL, *context = NULL, *meta, *body = NULL, *backtrace = NULL, *encoded, *len, *lastTrace = NULL, *_0 = NULL, *_1 = NULL, *_2, *backtraceItem = NULL, *key = NULL, _3, _4, *_8, **_11, *_12, *_13, *_15, *_16, *_18, *_19, *_20;
	zval *message = NULL;

	ZEPHIR_MM_GROW();
	zephir_fetch_params(1, 3, 1, &message_param, &type_param, &timestamp_param, &context);

	zephir_get_strval(message, message_param);
	type = zephir_get_intval(type_param);
	timestamp = zephir_get_intval(timestamp_param);
	if (!context) {
		context = ZEPHIR_GLOBAL(global_null);
	}


	if (Z_TYPE_P(context) == IS_ARRAY) {
		ZEPHIR_CALL_METHOD(&_0, this_ptr, "interpolate", NULL, message, context);
		zephir_check_call_status();
		zephir_get_strval(message, _0);
	}
	ZEPHIR_INIT_VAR(meta);
	zephir_create_array(meta, 1, 0 TSRMLS_CC);
	ZEPHIR_INIT_VAR(_1);
	ZVAL_LONG(_1, type);
	ZEPHIR_CALL_METHOD(&_0, this_ptr, "gettypestring", NULL, _1);
	zephir_check_call_status();
	zephir_array_update_string(&meta, SL("Type"), &_0, PH_COPY | PH_SEPARATE);
	_2 = zephir_fetch_nproperty_this(this_ptr, SL("_showBacktrace"), PH_NOISY_CC);
	if (zephir_is_true(_2)) {
		param = 0;
		ZEPHIR_INIT_NVAR(_1);
		ZEPHIR_GET_CONSTANT(_1, "PHP_VERSION");
		ZEPHIR_SINIT_VAR(_3);
		ZVAL_STRING(&_3, "5.3.6", 0);
		ZEPHIR_SINIT_VAR(_4);
		ZVAL_STRING(&_4, "<", 0);
		ZEPHIR_CALL_FUNCTION(&_0, "version_compare", &_5, _1, &_3, &_4);
		zephir_check_call_status();
		if (!(zephir_is_true(_0))) {
			param = (2) ? 1 : 0;
		}
		ZEPHIR_CALL_FUNCTION(&backtrace, "debug_backtrace", &_6, (param ? ZEPHIR_GLOBAL(global_true) : ZEPHIR_GLOBAL(global_false)));
		zephir_check_call_status();
		Z_SET_ISREF_P(backtrace);
		ZEPHIR_CALL_FUNCTION(&lastTrace, "end", &_7, backtrace);
		Z_UNSET_ISREF_P(backtrace);
		zephir_check_call_status();
		if (zephir_array_isset_string(lastTrace, SS("file"))) {
			zephir_array_fetch_string(&_8, lastTrace, SL("file"), PH_NOISY | PH_READONLY, "phalcon/logger/formatter/firephp.zep", 145 TSRMLS_CC);
			zephir_array_update_string(&meta, SL("File"), &_8, PH_COPY | PH_SEPARATE);
		}
		if (zephir_array_isset_string(lastTrace, SS("line"))) {
			zephir_array_fetch_string(&_8, lastTrace, SL("line"), PH_NOISY | PH_READONLY, "phalcon/logger/formatter/firephp.zep", 149 TSRMLS_CC);
			zephir_array_update_string(&meta, SL("Line"), &_8, PH_COPY | PH_SEPARATE);
		}
		zephir_is_iterable(backtrace, &_10, &_9, 1, 0, "phalcon/logger/formatter/firephp.zep", 158);
		for (
		  ; zephir_hash_get_current_data_ex(_10, (void**) &_11, &_9) == SUCCESS
		  ; zephir_hash_move_forward_ex(_10, &_9)
		) {
			ZEPHIR_GET_HMKEY(key, _10, _9);
			ZEPHIR_GET_HVALUE(backtraceItem, _11);
			zephir_array_unset_string(&backtraceItem, SS("object"), PH_SEPARATE);
			zephir_array_unset_string(&backtraceItem, SS("args"), PH_SEPARATE);
			zephir_array_update_zval(&backtrace, key, &backtraceItem, PH_COPY | PH_SEPARATE);
		}
	}
	_12 = zephir_fetch_nproperty_this(this_ptr, SL("_enableLabels"), PH_NOISY_CC);
	if (zephir_is_true(_12)) {
		zephir_array_update_string(&meta, SL("Label"), &message, PH_COPY | PH_SEPARATE);
	}
	_13 = zephir_fetch_nproperty_this(this_ptr, SL("_enableLabels"), PH_NOISY_CC);
	_14 = !zephir_is_true(_13);
	if (_14) {
		_15 = zephir_fetch_nproperty_this(this_ptr, SL("_showBacktrace"), PH_NOISY_CC);
		_14 = !zephir_is_true(_15);
	}
	_16 = zephir_fetch_nproperty_this(this_ptr, SL("_enableLabels"), PH_NOISY_CC);
	_17 = zephir_is_true(_16);
	if (_17) {
		_18 = zephir_fetch_nproperty_this(this_ptr, SL("_showBacktrace"), PH_NOISY_CC);
		_17 = !zephir_is_true(_18);
	}
	if (_14) {
		ZEPHIR_CPY_WRT(body, message);
	} else if (_17) {
		ZEPHIR_INIT_NVAR(body);
		ZVAL_STRING(body, "", 1);
	} else {
		ZEPHIR_INIT_NVAR(body);
		array_init(body);
		_19 = zephir_fetch_nproperty_this(this_ptr, SL("_showBacktrace"), PH_NOISY_CC);
		if (zephir_is_true(_19)) {
			zephir_array_update_string(&body, SL("backtrace"), &backtrace, PH_COPY | PH_SEPARATE);
		}
		_20 = zephir_fetch_nproperty_this(this_ptr, SL("_enableLabels"), PH_NOISY_CC);
		if (!(zephir_is_true(_20))) {
			zephir_array_update_string(&body, SL("message"), &message, PH_COPY | PH_SEPARATE);
		}
	}
	ZEPHIR_INIT_VAR(encoded);
	ZEPHIR_INIT_VAR(_21);
	zephir_create_array(_21, 2, 0 TSRMLS_CC);
	zephir_array_fast_append(_21, meta);
	zephir_array_fast_append(_21, body);
	zephir_json_encode(encoded, &(encoded), _21, 0  TSRMLS_CC);
	ZEPHIR_INIT_VAR(len);
	ZVAL_LONG(len, zephir_fast_strlen_ev(encoded));
	ZEPHIR_CONCAT_VSVS(return_value, len, "|", encoded, "|");
	RETURN_MM();

}
PHP_METHOD(Xs_FieldMeta, fromConfig) {

	zend_bool _8, _11, _12, _13;
	int ZEPHIR_LAST_CALL_STATUS;
	zephir_fcall_cache_entry *_3 = NULL, *_5 = NULL;
	zval *predef = NULL;
	zval *config_param = NULL, *c = NULL, *_0 = NULL, *_1 = NULL, *_2 = NULL, *_4 = NULL, *_6, *_7, *_9, *_10;
	zval *config = NULL;

	ZEPHIR_MM_GROW();
	zephir_fetch_params(1, 1, 0, &config_param);

	zephir_get_arrval(config, config_param);


	ZEPHIR_OBS_VAR(c);
	if (zephir_array_isset_string_fetch(&c, config, SS("type"), 0 TSRMLS_CC)) {
		ZEPHIR_INIT_VAR(_0);
		zephir_fast_strtoupper(_0, c);
		ZEPHIR_INIT_VAR(_1);
		ZEPHIR_CONCAT_SSV(_1, "Xs\\FieldMeta", "::TYPE_", _0);
		zephir_get_strval(predef, _1);
		ZEPHIR_CALL_FUNCTION(&_2, "defined", &_3, 11, predef);
		zephir_check_call_status();
		if (zephir_is_true(_2)) {
			ZEPHIR_CALL_FUNCTION(&_4, "constant", &_5, 12, predef);
			zephir_check_call_status();
			zephir_update_property_this(this_ptr, SL("type"), _4 TSRMLS_CC);
			_6 = zephir_fetch_nproperty_this(this_ptr, SL("type"), PH_NOISY_CC);
			do {
				if (ZEPHIR_IS_LONG(_6, 10)) {
					ZEPHIR_INIT_ZVAL_NREF(_7);
					ZVAL_LONG(_7, 0x01);
					zephir_update_property_this(this_ptr, SL("flag"), _7 TSRMLS_CC);
					ZEPHIR_INIT_ZVAL_NREF(_7);
					ZVAL_STRING(_7, "full", 1);
					zephir_update_property_this(this_ptr, SL("tokenizer"), _7 TSRMLS_CC);
					break;
				}
				if (ZEPHIR_IS_LONG(_6, 11)) {
					ZEPHIR_INIT_ZVAL_NREF(_7);
					ZVAL_LONG(_7, (0x03 | 0x10));
					zephir_update_property_this(this_ptr, SL("flag"), _7 TSRMLS_CC);
					ZEPHIR_INIT_ZVAL_NREF(_7);
					ZVAL_LONG(_7, 5);
					zephir_update_property_this(this_ptr, SL("weight"), _7 TSRMLS_CC);
					break;
				}
				if (ZEPHIR_IS_LONG(_6, 12)) {
					ZEPHIR_INIT_ZVAL_NREF(_7);
					ZVAL_LONG(_7, 255);
					zephir_update_property_this(this_ptr, SL("vno"), _7 TSRMLS_CC);
					ZEPHIR_INIT_ZVAL_NREF(_7);
					ZVAL_LONG(_7, (0x01 | 0x10));
					zephir_update_property_this(this_ptr, SL("flag"), _7 TSRMLS_CC);
					ZEPHIR_INIT_ZVAL_NREF(_7);
					ZVAL_LONG(_7, 300);
					zephir_update_property_this(this_ptr, SL("cutlen"), _7 TSRMLS_CC);
					break;
				}
			} while(0);

		}
	}
	ZEPHIR_OBS_NVAR(c);
	_8 = zephir_array_isset_string_fetch(&c, config, SS("index"), 0 TSRMLS_CC);
	if (_8) {
		_6 = zephir_fetch_nproperty_this(this_ptr, SL("type"), PH_NOISY_CC);
		_8 = !ZEPHIR_IS_LONG(_6, 12);
	}
	if (_8) {
		ZEPHIR_INIT_NVAR(_0);
		zephir_fast_strtoupper(_0, c);
		ZEPHIR_INIT_LNVAR(_1);
		ZEPHIR_CONCAT_SSV(_1, "Xs\\FieldMeta", "::FLAG_INDEX_", _0);
		zephir_get_strval(predef, _1);
		ZEPHIR_CALL_FUNCTION(&_2, "defined", &_3, 11, predef);
		zephir_check_call_status();
		if (zephir_is_true(_2)) {
			_7 = zephir_fetch_nproperty_this(this_ptr, SL("flag"), PH_NOISY_CC);
			ZEPHIR_CALL_FUNCTION(&_4, "constant", &_5, 12, predef);
			zephir_check_call_status();
			ZEPHIR_INIT_ZVAL_NREF(_9);
			ZVAL_LONG(_9, ((((int) (zephir_get_numberval(_7)) & ~(0x03))) | zephir_get_intval(_4)));
			zephir_update_property_this(this_ptr, SL("flag"), _9 TSRMLS_CC);
		}
		_6 = zephir_fetch_nproperty_this(this_ptr, SL("type"), PH_NOISY_CC);
		if (ZEPHIR_IS_LONG(_6, 10)) {
			_9 = zephir_fetch_nproperty_this(this_ptr, SL("flag"), PH_NOISY_CC);
			ZEPHIR_INIT_ZVAL_NREF(_10);
			ZVAL_LONG(_10, ((int) (zephir_get_numberval(_9)) | 0x01));
			zephir_update_property_this(this_ptr, SL("flag"), _10 TSRMLS_CC);
		}
	}
	ZEPHIR_OBS_NVAR(c);
	if (zephir_array_isset_string_fetch(&c, config, SS("cutlen"), 0 TSRMLS_CC)) {
		ZEPHIR_INIT_ZVAL_NREF(_6);
		ZVAL_LONG(_6, zephir_get_intval(c));
		zephir_update_property_this(this_ptr, SL("cutlen"), _6 TSRMLS_CC);
	}
	ZEPHIR_OBS_NVAR(c);
	_11 = zephir_array_isset_string_fetch(&c, config, SS("weight"), 0 TSRMLS_CC);
	if (_11) {
		_6 = zephir_fetch_nproperty_this(this_ptr, SL("type"), PH_NOISY_CC);
		_11 = !ZEPHIR_IS_LONG(_6, 12);
	}
	if (_11) {
		ZEPHIR_INIT_ZVAL_NREF(_9);
		ZVAL_LONG(_9, (zephir_get_intval(c) & 0x3f));
		zephir_update_property_this(this_ptr, SL("weight"), _9 TSRMLS_CC);
	}
	ZEPHIR_OBS_NVAR(c);
	if (zephir_array_isset_string_fetch(&c, config, SS("phrase"), 0 TSRMLS_CC)) {
		ZEPHIR_INIT_NVAR(_0);
		zephir_fast_strtolower(_0, c);
		do {
			if (ZEPHIR_IS_STRING(_0, "yes")) {
				_9 = zephir_fetch_nproperty_this(this_ptr, SL("flag"), PH_NOISY_CC);
				ZEPHIR_INIT_ZVAL_NREF(_10);
				ZVAL_LONG(_10, ((int) (zephir_get_numberval(_9)) | 0x10));
				zephir_update_property_this(this_ptr, SL("flag"), _10 TSRMLS_CC);
				break;
			}
			if (ZEPHIR_IS_STRING(_0, "no")) {
				_6 = zephir_fetch_nproperty_this(this_ptr, SL("flag"), PH_NOISY_CC);
				ZEPHIR_INIT_ZVAL_NREF(_9);
				ZVAL_LONG(_9, ((int) (zephir_get_numberval(_6)) & ~(0x10)));
				zephir_update_property_this(this_ptr, SL("flag"), _9 TSRMLS_CC);
				break;
			}
		} while(0);

	}
	ZEPHIR_OBS_NVAR(c);
	if (zephir_array_isset_string_fetch(&c, config, SS("non_bool"), 0 TSRMLS_CC)) {
		ZEPHIR_INIT_NVAR(_0);
		zephir_fast_strtolower(_0, c);
		do {
			if (ZEPHIR_IS_STRING(_0, "yes")) {
				_6 = zephir_fetch_nproperty_this(this_ptr, SL("flag"), PH_NOISY_CC);
				ZEPHIR_INIT_ZVAL_NREF(_9);
				ZVAL_LONG(_9, ((int) (zephir_get_numberval(_6)) | 0x80));
				zephir_update_property_this(this_ptr, SL("flag"), _9 TSRMLS_CC);
				break;
			}
			if (ZEPHIR_IS_STRING(_0, "no")) {
				_6 = zephir_fetch_nproperty_this(this_ptr, SL("flag"), PH_NOISY_CC);
				ZEPHIR_INIT_ZVAL_NREF(_9);
				ZVAL_LONG(_9, ((int) (zephir_get_numberval(_6)) & ~(0x80)));
				zephir_update_property_this(this_ptr, SL("flag"), _9 TSRMLS_CC);
				break;
			}
		} while(0);

	}
	ZEPHIR_OBS_NVAR(c);
	_12 = zephir_array_isset_string_fetch(&c, config, SS("tokenizer"), 0 TSRMLS_CC);
	if (_12) {
		_6 = zephir_fetch_nproperty_this(this_ptr, SL("type"), PH_NOISY_CC);
		_12 = !ZEPHIR_IS_LONG(_6, 10);
	}
	_13 = _12;
	if (_13) {
		_13 = !ZEPHIR_IS_STRING(c, "default");
	}
	if (_13) {
		zephir_update_property_this(this_ptr, SL("tokenizer"), c TSRMLS_CC);
	}
	ZEPHIR_MM_RESTORE();

}
Example #8
0
/**
 * Reads a packet from the socket. Prior to reading from the socket will
 * check for availability of the connection.
 */
PHP_METHOD(Phalcon_Queue_Beanstalk, read) {

	zephir_fcall_cache_entry *_2 = NULL;
	zval *length_param = NULL, *connection = NULL, *data = NULL, _0$$5 = zval_used_for_init, *_1$$5 = NULL, *_3$$5 = NULL, *_4$$5, _5$$8, _6$$8;
	int length, ZEPHIR_LAST_CALL_STATUS;

	ZEPHIR_MM_GROW();
	zephir_fetch_params(1, 0, 1, &length_param);

	if (!length_param) {
		length = 0;
	} else {
		length = zephir_get_intval(length_param);
	}


	ZEPHIR_OBS_VAR(connection);
	zephir_read_property_this(&connection, this_ptr, SL("_connection"), PH_NOISY_CC);
	if (Z_TYPE_P(connection) != IS_RESOURCE) {
		ZEPHIR_CALL_METHOD(&connection, this_ptr, "connect", NULL, 0);
		zephir_check_call_status();
		if (Z_TYPE_P(connection) != IS_RESOURCE) {
			RETURN_MM_BOOL(0);
		}
	}
	if (length) {
		if (zephir_feof(connection TSRMLS_CC)) {
			RETURN_MM_BOOL(0);
		}
		ZEPHIR_SINIT_VAR(_0$$5);
		ZVAL_LONG(&_0$$5, (length + 2));
		ZEPHIR_CALL_FUNCTION(&_1$$5, "stream_get_line", &_2, 413, connection, &_0$$5);
		zephir_check_call_status();
		ZEPHIR_SINIT_NVAR(_0$$5);
		ZVAL_STRING(&_0$$5, "\r\n", 0);
		ZEPHIR_INIT_VAR(data);
		zephir_fast_trim(data, _1$$5, &_0$$5, ZEPHIR_TRIM_RIGHT TSRMLS_CC);
		ZEPHIR_CALL_FUNCTION(&_3$$5, "stream_get_meta_data", NULL, 414, connection);
		zephir_check_call_status();
		zephir_array_fetch_string(&_4$$5, _3$$5, SL("timed_out"), PH_NOISY | PH_READONLY, "phalcon/queue/beanstalk.zep", 535 TSRMLS_CC);
		if (zephir_is_true(_4$$5)) {
			ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_queue_beanstalk_exception_ce, "Connection timed out", "phalcon/queue/beanstalk.zep", 536);
			return;
		}
	} else {
		ZEPHIR_SINIT_VAR(_5$$8);
		ZVAL_LONG(&_5$$8, 16384);
		ZEPHIR_SINIT_VAR(_6$$8);
		ZVAL_STRING(&_6$$8, "\r\n", 0);
		ZEPHIR_CALL_FUNCTION(&data, "stream_get_line", &_2, 413, connection, &_5$$8, &_6$$8);
		zephir_check_call_status();
	}
	if (ZEPHIR_IS_STRING_IDENTICAL(data, "UNKNOWN_COMMAND")) {
		ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_queue_beanstalk_exception_ce, "UNKNOWN_COMMAND", "phalcon/queue/beanstalk.zep", 544);
		return;
	}
	if (ZEPHIR_IS_STRING_IDENTICAL(data, "JOB_TOO_BIG")) {
		ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_queue_beanstalk_exception_ce, "JOB_TOO_BIG", "phalcon/queue/beanstalk.zep", 548);
		return;
	}
	if (ZEPHIR_IS_STRING_IDENTICAL(data, "BAD_FORMAT")) {
		ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_queue_beanstalk_exception_ce, "BAD_FORMAT", "phalcon/queue/beanstalk.zep", 552);
		return;
	}
	if (ZEPHIR_IS_STRING_IDENTICAL(data, "OUT_OF_MEMORY")) {
		ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_queue_beanstalk_exception_ce, "OUT_OF_MEMORY", "phalcon/queue/beanstalk.zep", 556);
		return;
	}
	RETURN_CCTOR(data);

}
Example #9
0
/**
 * Starts a transaction in the connection
 */
PHP_METHOD(Phalcon_Db_Adapter_Pdo, begin) {

	int ZEPHIR_LAST_CALL_STATUS, transactionLevel = 0;
	zval *nesting_param = NULL, *pdo = NULL, *eventsManager = NULL, *savepointName = NULL, *_0, *_1$$4, *_2$$5, *_5$$6 = NULL, *_6$$7, *_7$$8;
	zend_bool nesting, _3$$6, _4$$6;

	ZEPHIR_MM_GROW();
	zephir_fetch_params(1, 0, 1, &nesting_param);

	if (!nesting_param) {
		nesting = 1;
	} else {
		nesting = zephir_get_boolval(nesting_param);
	}


	ZEPHIR_OBS_VAR(pdo);
	zephir_read_property_this(&pdo, this_ptr, SL("_pdo"), PH_NOISY_CC);
	if (Z_TYPE_P(pdo) != IS_OBJECT) {
		RETURN_MM_BOOL(0);
	}
	RETURN_ON_FAILURE(zephir_property_incr(this_ptr, SL("_transactionLevel") TSRMLS_CC));
	ZEPHIR_OBS_VAR(_0);
	zephir_read_property_this(&_0, this_ptr, SL("_transactionLevel"), PH_NOISY_CC);
	transactionLevel = zephir_get_intval(_0);
	if (transactionLevel == 1) {
		_1$$4 = zephir_fetch_nproperty_this(this_ptr, SL("_eventsManager"), PH_NOISY_CC);
		ZEPHIR_CPY_WRT(eventsManager, _1$$4);
		if (Z_TYPE_P(eventsManager) == IS_OBJECT) {
			ZEPHIR_INIT_VAR(_2$$5);
			ZVAL_STRING(_2$$5, "db:beginTransaction", ZEPHIR_TEMP_PARAM_COPY);
			ZEPHIR_CALL_METHOD(NULL, eventsManager, "fire", NULL, 0, _2$$5, this_ptr);
			zephir_check_temp_parameter(_2$$5);
			zephir_check_call_status();
		}
		ZEPHIR_RETURN_CALL_METHOD(pdo, "begintransaction", NULL, 0);
		zephir_check_call_status();
		RETURN_MM();
	} else {
		_3$$6 = (transactionLevel) ? 1 : 0;
		if (_3$$6) {
			_3$$6 = nesting;
		}
		_4$$6 = _3$$6;
		if (_4$$6) {
			ZEPHIR_CALL_METHOD(&_5$$6, this_ptr, "isnestedtransactionswithsavepoints", NULL, 0);
			zephir_check_call_status();
			_4$$6 = zephir_is_true(_5$$6);
		}
		if (_4$$6) {
			_6$$7 = zephir_fetch_nproperty_this(this_ptr, SL("_eventsManager"), PH_NOISY_CC);
			ZEPHIR_CPY_WRT(eventsManager, _6$$7);
			ZEPHIR_CALL_METHOD(&savepointName, this_ptr, "getnestedtransactionsavepointname", NULL, 0);
			zephir_check_call_status();
			if (Z_TYPE_P(eventsManager) == IS_OBJECT) {
				ZEPHIR_INIT_VAR(_7$$8);
				ZVAL_STRING(_7$$8, "db:createSavepoint", ZEPHIR_TEMP_PARAM_COPY);
				ZEPHIR_CALL_METHOD(NULL, eventsManager, "fire", NULL, 0, _7$$8, this_ptr, savepointName);
				zephir_check_temp_parameter(_7$$8);
				zephir_check_call_status();
			}
			ZEPHIR_RETURN_CALL_METHOD(this_ptr, "createsavepoint", NULL, 0, savepointName);
			zephir_check_call_status();
			RETURN_MM();
		}
	}
	RETURN_MM_BOOL(0);

}
Example #10
0
PHP_METHOD(Xpl_ClassLoader, findFileWithExtension) {

	HashTable *_16, *_39, *_6$$3, *_11$$5, *_32$$12, *_35$$14;
	HashPosition _15, _38, _5$$3, _10$$5, _31$$12, _34$$14;
	int ZEPHIR_LAST_CALL_STATUS;
	zephir_fcall_cache_entry *_3 = NULL;
	zval *className_param = NULL, *ext_param = NULL, *logicalPathPsr4 = NULL, *firstChar = NULL, *prefixLengthsPsr4 = NULL, *prefix = NULL, *length = NULL, *dir = NULL, *file = NULL, *prefixesPsr0 = NULL, *logicalPathPsr0 = NULL, *nsPos = NULL, *dirs = NULL, _0 = zval_used_for_init, _1 = zval_used_for_init, *_2 = NULL, *_4, *_14, **_17, _18, *_30, *_37, **_40, *_41, **_7$$3, *_8$$5, *_9$$5, **_12$$5, *_13$$6 = NULL, _19$$10, _20$$10, *_21$$10, _22$$10, *_23$$10, _24$$10, _25$$10, *_26$$10 = NULL, _27$$11, _28$$11, *_29$$11 = NULL, **_33$$12, **_36$$14;
	zval *className = NULL, *ext = NULL;

	ZEPHIR_MM_GROW();
	zephir_fetch_params(1, 2, 0, &className_param, &ext_param);

	if (unlikely(Z_TYPE_P(className_param) != IS_STRING && Z_TYPE_P(className_param) != IS_NULL)) {
		zephir_throw_exception_string(spl_ce_InvalidArgumentException, SL("Parameter 'className' must be a string") TSRMLS_CC);
		RETURN_MM_NULL();
	}
	if (likely(Z_TYPE_P(className_param) == IS_STRING)) {
		zephir_get_strval(className, className_param);
	} else {
		ZEPHIR_INIT_VAR(className);
		ZVAL_EMPTY_STRING(className);
	}
	zephir_get_strval(ext, ext_param);


	ZEPHIR_SINIT_VAR(_0);
	ZVAL_STRING(&_0, "\\", 0);
	ZEPHIR_SINIT_VAR(_1);
	ZVAL_STRING(&_1, "/", 0);
	ZEPHIR_CALL_FUNCTION(&_2, "strtr", &_3, 56, className, &_0, &_1);
	zephir_check_call_status();
	ZEPHIR_INIT_VAR(logicalPathPsr4);
	ZEPHIR_CONCAT_VV(logicalPathPsr4, _2, ext);
	ZEPHIR_SINIT_NVAR(_0);
	ZVAL_LONG(&_0, 0);
	ZEPHIR_SINIT_NVAR(_1);
	ZVAL_LONG(&_1, 1);
	ZEPHIR_INIT_VAR(firstChar);
	zephir_substr(firstChar, className, 0 , 1 , 0);
	ZEPHIR_OBS_VAR(prefixLengthsPsr4);
	_4 = zephir_fetch_nproperty_this(this_ptr, SL("prefixLengthsPsr4"), PH_NOISY_CC);
	if (zephir_array_isset_fetch(&prefixLengthsPsr4, _4, firstChar, 0 TSRMLS_CC)) {
		zephir_is_iterable(prefixLengthsPsr4, &_6$$3, &_5$$3, 0, 0, "xpl/classloader.zep", 505);
		for (
		  ; zephir_hash_get_current_data_ex(_6$$3, (void**) &_7$$3, &_5$$3) == SUCCESS
		  ; zephir_hash_move_forward_ex(_6$$3, &_5$$3)
		) {
			ZEPHIR_GET_HMKEY(prefix, _6$$3, _5$$3);
			ZEPHIR_GET_HVALUE(length, _7$$3);
			if (zephir_start_with(className, prefix, ZEPHIR_GLOBAL(global_false))) {
				_8$$5 = zephir_fetch_nproperty_this(this_ptr, SL("prefixDirsPsr4"), PH_NOISY_CC);
				zephir_array_fetch(&_9$$5, _8$$5, prefix, PH_NOISY | PH_READONLY, "xpl/classloader.zep", 495 TSRMLS_CC);
				zephir_is_iterable(_9$$5, &_11$$5, &_10$$5, 0, 0, "xpl/classloader.zep", 503);
				for (
				  ; zephir_hash_get_current_data_ex(_11$$5, (void**) &_12$$5, &_10$$5) == SUCCESS
				  ; zephir_hash_move_forward_ex(_11$$5, &_10$$5)
				) {
					ZEPHIR_GET_HVALUE(dir, _12$$5);
					ZEPHIR_INIT_NVAR(_13$$6);
					zephir_substr(_13$$6, logicalPathPsr4, zephir_get_intval(length), 0, ZEPHIR_SUBSTR_NO_LENGTH);
					ZEPHIR_INIT_NVAR(file);
					ZEPHIR_CONCAT_VSV(file, dir, "/", _13$$6);
					if ((zephir_file_exists(file TSRMLS_CC) == SUCCESS)) {
						RETURN_CCTOR(file);
					}
				}
			}
		}
	}
	_14 = zephir_fetch_nproperty_this(this_ptr, SL("fallbackDirsPsr4"), PH_NOISY_CC);
	zephir_is_iterable(_14, &_16, &_15, 0, 0, "xpl/classloader.zep", 517);
	for (
	  ; zephir_hash_get_current_data_ex(_16, (void**) &_17, &_15) == SUCCESS
	  ; zephir_hash_move_forward_ex(_16, &_15)
	) {
		ZEPHIR_GET_HVALUE(dir, _17);
		ZEPHIR_INIT_NVAR(file);
		ZEPHIR_CONCAT_VSV(file, dir, "/", logicalPathPsr4);
		if ((zephir_file_exists(file TSRMLS_CC) == SUCCESS)) {
			RETURN_CCTOR(file);
		}
	}
	ZEPHIR_SINIT_VAR(_18);
	ZVAL_STRING(&_18, "\\", 0);
	ZEPHIR_CALL_FUNCTION(&nsPos, "strrpos", NULL, 57, className, &_18);
	zephir_check_call_status();
	ZEPHIR_INIT_VAR(logicalPathPsr0);
	if (zephir_is_true(nsPos)) {
		ZEPHIR_SINIT_VAR(_19$$10);
		ZVAL_LONG(&_19$$10, 0);
		ZEPHIR_SINIT_VAR(_20$$10);
		ZVAL_LONG(&_20$$10, (zephir_get_numberval(nsPos) + 1));
		ZEPHIR_INIT_VAR(_21$$10);
		zephir_substr(_21$$10, logicalPathPsr4, 0 , zephir_get_intval(&_20$$10), 0);
		ZEPHIR_SINIT_VAR(_22$$10);
		ZVAL_LONG(&_22$$10, (zephir_get_numberval(nsPos) + 1));
		ZEPHIR_INIT_VAR(_23$$10);
		zephir_substr(_23$$10, logicalPathPsr4, zephir_get_intval(&_22$$10), 0, ZEPHIR_SUBSTR_NO_LENGTH);
		ZEPHIR_SINIT_VAR(_24$$10);
		ZVAL_STRING(&_24$$10, "_", 0);
		ZEPHIR_SINIT_VAR(_25$$10);
		ZVAL_STRING(&_25$$10, "/", 0);
		ZEPHIR_CALL_FUNCTION(&_26$$10, "strtr", &_3, 56, _23$$10, &_24$$10, &_25$$10);
		zephir_check_call_status();
		ZEPHIR_CONCAT_VV(logicalPathPsr0, _21$$10, _26$$10);
	} else {
		ZEPHIR_SINIT_VAR(_27$$11);
		ZVAL_STRING(&_27$$11, "_", 0);
		ZEPHIR_SINIT_VAR(_28$$11);
		ZVAL_STRING(&_28$$11, "/", 0);
		ZEPHIR_CALL_FUNCTION(&_29$$11, "strtr", &_3, 56, className, &_27$$11, &_28$$11);
		zephir_check_call_status();
		ZEPHIR_CONCAT_VV(logicalPathPsr0, _29$$11, ext);
	}
	ZEPHIR_OBS_VAR(prefixesPsr0);
	_30 = zephir_fetch_nproperty_this(this_ptr, SL("prefixesPsr0"), PH_NOISY_CC);
	if (zephir_array_isset_fetch(&prefixesPsr0, _30, firstChar, 0 TSRMLS_CC)) {
		zephir_is_iterable(prefixesPsr0, &_32$$12, &_31$$12, 0, 0, "xpl/classloader.zep", 546);
		for (
		  ; zephir_hash_get_current_data_ex(_32$$12, (void**) &_33$$12, &_31$$12) == SUCCESS
		  ; zephir_hash_move_forward_ex(_32$$12, &_31$$12)
		) {
			ZEPHIR_GET_HMKEY(prefix, _32$$12, _31$$12);
			ZEPHIR_GET_HVALUE(dirs, _33$$12);
			if (zephir_start_with(className, prefix, NULL)) {
				zephir_is_iterable(dirs, &_35$$14, &_34$$14, 0, 0, "xpl/classloader.zep", 544);
				for (
				  ; zephir_hash_get_current_data_ex(_35$$14, (void**) &_36$$14, &_34$$14) == SUCCESS
				  ; zephir_hash_move_forward_ex(_35$$14, &_34$$14)
				) {
					ZEPHIR_GET_HVALUE(dir, _36$$14);
					ZEPHIR_INIT_NVAR(file);
					ZEPHIR_CONCAT_VSV(file, dir, "/", logicalPathPsr0);
					if ((zephir_file_exists(file TSRMLS_CC) == SUCCESS)) {
						RETURN_CCTOR(file);
					}
				}
			}
		}
	}
	_37 = zephir_fetch_nproperty_this(this_ptr, SL("fallbackDirsPsr0"), PH_NOISY_CC);
	zephir_is_iterable(_37, &_39, &_38, 0, 0, "xpl/classloader.zep", 559);
	for (
	  ; zephir_hash_get_current_data_ex(_39, (void**) &_40, &_38) == SUCCESS
	  ; zephir_hash_move_forward_ex(_39, &_38)
	) {
		ZEPHIR_GET_HVALUE(dir, _40);
		ZEPHIR_INIT_NVAR(file);
		ZEPHIR_CONCAT_VSV(file, dir, "/", logicalPathPsr0);
		if ((zephir_file_exists(file TSRMLS_CC) == SUCCESS)) {
			RETURN_CCTOR(file);
		}
	}
	_41 = zephir_fetch_nproperty_this(this_ptr, SL("useIncludePath"), PH_NOISY_CC);
	if (ZEPHIR_IS_TRUE_IDENTICAL(_41)) {
		ZEPHIR_CALL_FUNCTION(&file, "stream_resolve_include_path", NULL, 58, logicalPathPsr0);
		zephir_check_call_status();
		if (zephir_is_true(file)) {
			RETURN_CCTOR(file);
		}
	}
	RETURN_MM_NULL();

}
Example #11
0
/**
 * Stores cached content into the file backend and stops the frontend
 *
 * @param int|string keyName
 * @param string content
 * @param long lifetime
 * @param boolean stopBuffer
 */
PHP_METHOD(Phalcon_Cache_Backend_Mongo, save) {

	zval *_2;
	zephir_nts_static zephir_fcall_cache_entry *_0 = NULL;
	int ZEPHIR_LAST_CALL_STATUS;
	zval *keyName = NULL, *content = NULL, *lifetime = NULL, *stopBuffer = NULL, *lastkey = NULL, *prefix, *frontend, *cachedContent = NULL, *tmp, *ttl = NULL, *collection = NULL, *timestamp, *conditions, *document = NULL, *preparedContent = NULL, *isBuffering = NULL, *data, *_1, *_3;

	ZEPHIR_MM_GROW();
	zephir_fetch_params(1, 0, 4, &keyName, &content, &lifetime, &stopBuffer);

	if (!keyName) {
		keyName = ZEPHIR_GLOBAL(global_null);
	}
	if (!content) {
		content = ZEPHIR_GLOBAL(global_null);
	}
	if (!lifetime) {
		lifetime = ZEPHIR_GLOBAL(global_null);
	}
	if (!stopBuffer) {
		stopBuffer = ZEPHIR_GLOBAL(global_true);
	}


	ZEPHIR_INIT_VAR(conditions);
	array_init(conditions);
	ZEPHIR_INIT_VAR(data);
	array_init(data);
	if (!(zephir_is_true(keyName))) {
		ZEPHIR_OBS_VAR(lastkey);
		zephir_read_property_this(&lastkey, this_ptr, SL("_lastKey"), PH_NOISY_CC);
	} else {
		ZEPHIR_OBS_VAR(prefix);
		zephir_read_property_this(&prefix, this_ptr, SL("_prefix"), PH_NOISY_CC);
		ZEPHIR_INIT_NVAR(lastkey);
		ZEPHIR_CONCAT_VV(lastkey, prefix, keyName);
	}
	if (!(zephir_is_true(lastkey))) {
		ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_cache_exception_ce, "Cache must be started first", "phalcon/cache/backend/mongo.zep", 206);
		return;
	}
	ZEPHIR_OBS_VAR(frontend);
	zephir_read_property_this(&frontend, this_ptr, SL("_frontend"), PH_NOISY_CC);
	if (!(zephir_is_true(content))) {
		ZEPHIR_CALL_METHOD(&cachedContent, frontend, "getcontent", NULL);
		zephir_check_call_status();
	} else {
		ZEPHIR_CPY_WRT(cachedContent, content);
	}
	if (!(zephir_is_numeric(cachedContent))) {
		ZEPHIR_CALL_METHOD(&preparedContent, frontend, "beforestore", NULL, cachedContent);
		zephir_check_call_status();
	}
	if (!(zephir_is_true(lifetime))) {
		ZEPHIR_OBS_VAR(tmp);
		zephir_read_property_this(&tmp, this_ptr, SL("_lastLifetime"), PH_NOISY_CC);
		if (!(zephir_is_true(tmp))) {
			ZEPHIR_CALL_METHOD(&ttl, frontend, "getlifetime", NULL);
			zephir_check_call_status();
		} else {
			ZEPHIR_CPY_WRT(ttl, tmp);
		}
	} else {
		ZEPHIR_CPY_WRT(ttl, lifetime);
	}
	ZEPHIR_CALL_METHOD(&collection, this_ptr, "_getcollection", &_0);
	zephir_check_call_status();
	ZEPHIR_INIT_VAR(_1);
	zephir_time(_1);
	ZEPHIR_INIT_VAR(timestamp);
	ZVAL_LONG(timestamp, (zephir_get_numberval(_1) + zephir_get_intval(ttl)));
	zephir_array_update_string(&conditions, SL("key"), &lastkey, PH_COPY | PH_SEPARATE);
	ZEPHIR_CALL_METHOD(&document, collection, "findone", NULL, conditions);
	zephir_check_call_status();
	if (Z_TYPE_P(document) == IS_ARRAY) {
		zephir_array_update_string(&document, SL("time"), &timestamp, PH_COPY | PH_SEPARATE);
		if (!(zephir_is_numeric(cachedContent))) {
			zephir_array_update_string(&document, SL("data"), &preparedContent, PH_COPY | PH_SEPARATE);
		} else {
			zephir_array_update_string(&document, SL("data"), &cachedContent, PH_COPY | PH_SEPARATE);
		}
		ZEPHIR_INIT_VAR(_2);
		zephir_create_array(_2, 1, 0 TSRMLS_CC);
		ZEPHIR_OBS_VAR(_3);
		zephir_array_fetch_string(&_3, document, SL("_id"), PH_NOISY, "phalcon/cache/backend/mongo.zep", 246 TSRMLS_CC);
		zephir_array_update_string(&_2, SL("_id"), &_3, PH_COPY | PH_SEPARATE);
		ZEPHIR_CALL_METHOD(NULL, collection, "update", NULL, _2, document);
		zephir_check_call_status();
	} else {
		zephir_array_update_string(&data, SL("key"), &lastkey, PH_COPY | PH_SEPARATE);
		zephir_array_update_string(&data, SL("time"), &timestamp, PH_COPY | PH_SEPARATE);
		if (!(zephir_is_numeric(cachedContent))) {
			zephir_array_update_string(&data, SL("data"), &preparedContent, PH_COPY | PH_SEPARATE);
		} else {
			zephir_array_update_string(&data, SL("data"), &cachedContent, PH_COPY | PH_SEPARATE);
		}
		ZEPHIR_CALL_METHOD(NULL, collection, "insert", NULL, data);
		zephir_check_call_status();
	}
	ZEPHIR_CALL_METHOD(&isBuffering, frontend, "isbuffering", NULL);
	zephir_check_call_status();
	if (ZEPHIR_IS_TRUE_IDENTICAL(stopBuffer)) {
		ZEPHIR_CALL_METHOD(NULL, frontend, "stop", NULL);
		zephir_check_call_status();
	}
	if (ZEPHIR_IS_TRUE_IDENTICAL(isBuffering)) {
		zend_print_zval(cachedContent, 0);
	}
	zephir_update_property_this(this_ptr, SL("_started"), (0) ? ZEPHIR_GLOBAL(global_true) : ZEPHIR_GLOBAL(global_false) TSRMLS_CC);
	ZEPHIR_MM_RESTORE();

}
Example #12
0
/**
 * Removes padding @a padding_type from @a text
 * If the function detects that the text was not padded, it will return it unmodified
 *
 * @param return_value Result, possibly unpadded
 * @param text Message to be unpadded
 * @param mode Encryption mode; unpadding is applied only in CBC or ECB mode
 * @param block_size Cipher block size
 * @param padding_type Padding scheme
 */
PHP_METHOD(Phalcon_Crypt, _cryptUnpadText) {

	unsigned char _14, _16;
	zephir_fcall_cache_entry *_6 = NULL, *_9 = NULL, *_11 = NULL;
	zend_bool _0, _1, _2, _13, _15;
	long length;
	int blockSize, paddingType, i, paddingSize = 0, ord, ZEPHIR_LAST_CALL_STATUS;
	zval *text_param = NULL, *mode_param = NULL, *blockSize_param = NULL, *paddingType_param = NULL, *padding = NULL, *last = NULL, _3 = zval_used_for_init, _4 = zval_used_for_init, *_5 = NULL, _7 = zval_used_for_init, *_8 = NULL, *_10 = NULL, *_12 = NULL;
	zval *text = NULL, *mode = NULL;

	ZEPHIR_MM_GROW();
	zephir_fetch_params(1, 4, 0, &text_param, &mode_param, &blockSize_param, &paddingType_param);

	zephir_get_strval(text, text_param);
	if (unlikely(Z_TYPE_P(mode_param) != IS_STRING && Z_TYPE_P(mode_param) != IS_NULL)) {
		zephir_throw_exception_string(spl_ce_InvalidArgumentException, SL("Parameter 'mode' must be a string") TSRMLS_CC);
		RETURN_MM_NULL();
	}

	if (likely(Z_TYPE_P(mode_param) == IS_STRING)) {
		zephir_get_strval(mode, mode_param);
	} else {
		ZEPHIR_INIT_VAR(mode);
		ZVAL_EMPTY_STRING(mode);
	}
	if (unlikely(Z_TYPE_P(blockSize_param) != IS_LONG)) {
		zephir_throw_exception_string(spl_ce_InvalidArgumentException, SL("Parameter 'blockSize' must be a long/integer") TSRMLS_CC);
		RETURN_MM_NULL();
	}

	blockSize = Z_LVAL_P(blockSize_param);
	if (unlikely(Z_TYPE_P(paddingType_param) != IS_LONG)) {
		zephir_throw_exception_string(spl_ce_InvalidArgumentException, SL("Parameter 'paddingType' must be a long/integer") TSRMLS_CC);
		RETURN_MM_NULL();
	}

	paddingType = Z_LVAL_P(paddingType_param);


	length = zephir_fast_strlen_ev(text);
	_0 = length > 0;
	if (_0) {
		_0 = (zephir_safe_mod_long_long(length, blockSize TSRMLS_CC) == 0);
	}
	_1 = _0;
	if (_1) {
		_2 = ZEPHIR_IS_STRING(mode, "cbc");
		if (!(_2)) {
			_2 = ZEPHIR_IS_STRING(mode, "ecb");
		}
		_1 = _2;
	}
	if (_1) {
		do {
			if (paddingType == 1) {
				ZEPHIR_SINIT_VAR(_3);
				ZVAL_LONG(&_3, (length - 1));
				ZEPHIR_SINIT_VAR(_4);
				ZVAL_LONG(&_4, 1);
				ZEPHIR_INIT_VAR(last);
				zephir_substr(last, text, zephir_get_intval(&_3), 1 , 0);
				ZEPHIR_CALL_FUNCTION(&_5, "ord", &_6, 130, last);
				zephir_check_call_status();
				ord = zephir_get_intval(_5);
				if (ord <= blockSize) {
					paddingSize = ord;
					ZEPHIR_SINIT_VAR(_7);
					ZVAL_LONG(&_7, 0);
					ZEPHIR_CALL_FUNCTION(&_8, "chr", &_9, 128, &_7);
					zephir_check_call_status();
					ZEPHIR_SINIT_NVAR(_7);
					ZVAL_LONG(&_7, (paddingSize - 1));
					ZEPHIR_CALL_FUNCTION(&_10, "str_repeat", &_11, 129, _8, &_7);
					zephir_check_call_status();
					ZEPHIR_INIT_VAR(padding);
					ZEPHIR_CONCAT_VV(padding, _10, last);
					ZEPHIR_SINIT_NVAR(_7);
					ZVAL_LONG(&_7, (length - paddingSize));
					ZEPHIR_INIT_VAR(_12);
					zephir_substr(_12, text, zephir_get_intval(&_7), 0, ZEPHIR_SUBSTR_NO_LENGTH);
					if (!ZEPHIR_IS_EQUAL(_12, padding)) {
						paddingSize = 0;
					}
				}
				break;
			}
			if (paddingType == 2) {
				ZEPHIR_SINIT_NVAR(_3);
				ZVAL_LONG(&_3, (length - 1));
				ZEPHIR_SINIT_NVAR(_4);
				ZVAL_LONG(&_4, 1);
				ZEPHIR_INIT_NVAR(last);
				zephir_substr(last, text, zephir_get_intval(&_3), 1 , 0);
				ZEPHIR_CALL_FUNCTION(&_5, "ord", &_6, 130, last);
				zephir_check_call_status();
				ord = zephir_get_intval(_5);
				if (ord <= blockSize) {
					paddingSize = ord;
					ZEPHIR_SINIT_NVAR(_7);
					ZVAL_LONG(&_7, paddingSize);
					ZEPHIR_CALL_FUNCTION(&_8, "chr", &_9, 128, &_7);
					zephir_check_call_status();
					ZEPHIR_SINIT_NVAR(_7);
					ZVAL_LONG(&_7, paddingSize);
					ZEPHIR_CALL_FUNCTION(&padding, "str_repeat", &_11, 129, _8, &_7);
					zephir_check_call_status();
					ZEPHIR_SINIT_NVAR(_7);
					ZVAL_LONG(&_7, (length - paddingSize));
					ZEPHIR_INIT_NVAR(_12);
					zephir_substr(_12, text, zephir_get_intval(&_7), 0, ZEPHIR_SUBSTR_NO_LENGTH);
					if (!ZEPHIR_IS_EQUAL(_12, padding)) {
						paddingSize = 0;
					}
				}
				break;
			}
			if (paddingType == 3) {
				ZEPHIR_SINIT_NVAR(_3);
				ZVAL_LONG(&_3, (length - 1));
				ZEPHIR_SINIT_NVAR(_4);
				ZVAL_LONG(&_4, 1);
				ZEPHIR_INIT_NVAR(last);
				zephir_substr(last, text, zephir_get_intval(&_3), 1 , 0);
				ZEPHIR_CALL_FUNCTION(&_5, "ord", &_6, 130, last);
				zephir_check_call_status();
				paddingSize = zephir_get_intval(_5);
				break;
			}
			if (paddingType == 4) {
				i = (length - 1);
				while (1) {
					_13 = i > 0;
					if (_13) {
						_14 = ZEPHIR_STRING_OFFSET(text, i);
						_13 = _14 == 0x00;
					}
					_15 = _13;
					if (_15) {
						_15 = paddingSize < blockSize;
					}
					if (!(_15)) {
						break;
					}
					paddingSize++;
					i--;
				}
				_16 = ZEPHIR_STRING_OFFSET(text, i);
				if (_16 == 0x80) {
					paddingSize++;
				} else {
					paddingSize = 0;
				}
				break;
			}
			if (paddingType == 5) {
				i = (length - 1);
				while (1) {
					_13 = i >= 0;
					if (_13) {
						_14 = ZEPHIR_STRING_OFFSET(text, i);
						_13 = _14 == 0x00;
					}
					_15 = _13;
					if (_15) {
						_15 = paddingSize <= blockSize;
					}
					if (!(_15)) {
						break;
					}
					paddingSize++;
					i--;
				}
				break;
			}
			if (paddingType == 6) {
				i = (length - 1);
				while (1) {
					_13 = i >= 0;
					if (_13) {
						_14 = ZEPHIR_STRING_OFFSET(text, i);
						_13 = _14 == 0x20;
					}
					_15 = _13;
					if (_15) {
						_15 = paddingSize <= blockSize;
					}
					if (!(_15)) {
						break;
					}
					paddingSize++;
					i--;
				}
				break;
			}
			break;
		} while(0);

		_13 = (paddingSize) ? 1 : 0;
		if (_13) {
			_13 = paddingSize <= blockSize;
		}
		if (_13) {
			if (paddingSize < length) {
				ZEPHIR_SINIT_NVAR(_3);
				ZVAL_LONG(&_3, 0);
				ZEPHIR_SINIT_NVAR(_4);
				ZVAL_LONG(&_4, (length - paddingSize));
				zephir_substr(return_value, text, 0 , zephir_get_intval(&_4), 0);
				RETURN_MM();
			}
			RETURN_MM_STRING("", 1);
		} else {
			paddingSize = 0;
		}
	}
	if (!(paddingSize)) {
		RETURN_CTOR(text);
	}
	ZEPHIR_MM_RESTORE();

}
Example #13
0
/**
 * Pads texts before encryption
 *
 * @see http://www.di-mgt.com.au/cryptopad.html
 */
PHP_METHOD(Phalcon_Crypt, _cryptPadText) {

	zephir_fcall_cache_entry *_3 = NULL, *_5 = NULL, *_10 = NULL;
	zend_bool _0, _7;
	int blockSize, paddingType, i, paddingSize = 0, ZEPHIR_LAST_CALL_STATUS, _8, _9;
	zval *text_param = NULL, *mode_param = NULL, *blockSize_param = NULL, *paddingType_param = NULL, *padding = NULL, _1 = zval_used_for_init, *_2 = NULL, *_4 = NULL, *_6 = NULL, _11 = zval_used_for_init, *_12;
	zval *text = NULL, *mode = NULL;

	ZEPHIR_MM_GROW();
	zephir_fetch_params(1, 4, 0, &text_param, &mode_param, &blockSize_param, &paddingType_param);

	zephir_get_strval(text, text_param);
	if (unlikely(Z_TYPE_P(mode_param) != IS_STRING && Z_TYPE_P(mode_param) != IS_NULL)) {
		zephir_throw_exception_string(spl_ce_InvalidArgumentException, SL("Parameter 'mode' must be a string") TSRMLS_CC);
		RETURN_MM_NULL();
	}

	if (likely(Z_TYPE_P(mode_param) == IS_STRING)) {
		zephir_get_strval(mode, mode_param);
	} else {
		ZEPHIR_INIT_VAR(mode);
		ZVAL_EMPTY_STRING(mode);
	}
	if (unlikely(Z_TYPE_P(blockSize_param) != IS_LONG)) {
		zephir_throw_exception_string(spl_ce_InvalidArgumentException, SL("Parameter 'blockSize' must be a long/integer") TSRMLS_CC);
		RETURN_MM_NULL();
	}

	blockSize = Z_LVAL_P(blockSize_param);
	if (unlikely(Z_TYPE_P(paddingType_param) != IS_LONG)) {
		zephir_throw_exception_string(spl_ce_InvalidArgumentException, SL("Parameter 'paddingType' must be a long/integer") TSRMLS_CC);
		RETURN_MM_NULL();
	}

	paddingType = Z_LVAL_P(paddingType_param);
	ZEPHIR_INIT_VAR(padding);
	ZVAL_NULL(padding);


	_0 = ZEPHIR_IS_STRING(mode, "cbc");
	if (!(_0)) {
		_0 = ZEPHIR_IS_STRING(mode, "ecb");
	}
	if (_0) {
		paddingSize = (blockSize - (zephir_safe_mod_long_long(zephir_fast_strlen_ev(text), blockSize TSRMLS_CC)));
		if (paddingSize >= 256) {
			ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_crypt_exception_ce, "Block size is bigger than 256", "phalcon/crypt.zep", 142);
			return;
		}
		do {
			if (paddingType == 1) {
				ZEPHIR_SINIT_VAR(_1);
				ZVAL_LONG(&_1, 0);
				ZEPHIR_CALL_FUNCTION(&_2, "chr", &_3, 128, &_1);
				zephir_check_call_status();
				ZEPHIR_SINIT_NVAR(_1);
				ZVAL_LONG(&_1, (paddingSize - 1));
				ZEPHIR_CALL_FUNCTION(&_4, "str_repeat", &_5, 129, _2, &_1);
				zephir_check_call_status();
				ZEPHIR_SINIT_NVAR(_1);
				ZVAL_LONG(&_1, paddingSize);
				ZEPHIR_CALL_FUNCTION(&_6, "chr", &_3, 128, &_1);
				zephir_check_call_status();
				ZEPHIR_INIT_NVAR(padding);
				ZEPHIR_CONCAT_VV(padding, _4, _6);
				break;
			}
			if (paddingType == 2) {
				ZEPHIR_SINIT_NVAR(_1);
				ZVAL_LONG(&_1, paddingSize);
				ZEPHIR_CALL_FUNCTION(&_2, "chr", &_3, 128, &_1);
				zephir_check_call_status();
				ZEPHIR_SINIT_NVAR(_1);
				ZVAL_LONG(&_1, paddingSize);
				ZEPHIR_CALL_FUNCTION(&padding, "str_repeat", &_5, 129, _2, &_1);
				zephir_check_call_status();
				break;
			}
			if (paddingType == 3) {
				ZEPHIR_INIT_NVAR(padding);
				ZVAL_STRING(padding, "", 1);
				_9 = (paddingSize - 2);
				_8 = 0;
				_7 = 0;
				if (_8 <= _9) {
					while (1) {
						if (_7) {
							_8++;
							if (!(_8 <= _9)) {
								break;
							}
						} else {
							_7 = 1;
						}
						i = _8;
						ZEPHIR_CALL_FUNCTION(&_2, "rand", &_10, 107);
						zephir_check_call_status();
						ZEPHIR_CALL_FUNCTION(&_4, "chr", &_3, 128, _2);
						zephir_check_call_status();
						zephir_concat_self(&padding, _4 TSRMLS_CC);
					}
				}
				ZEPHIR_SINIT_NVAR(_1);
				ZVAL_LONG(&_1, paddingSize);
				ZEPHIR_CALL_FUNCTION(&_6, "chr", &_3, 128, &_1);
				zephir_check_call_status();
				zephir_concat_self(&padding, _6 TSRMLS_CC);
				break;
			}
			if (paddingType == 4) {
				ZEPHIR_SINIT_NVAR(_1);
				ZVAL_LONG(&_1, 0x80);
				ZEPHIR_CALL_FUNCTION(&_2, "chr", &_3, 128, &_1);
				zephir_check_call_status();
				ZEPHIR_SINIT_NVAR(_1);
				ZVAL_LONG(&_1, 0);
				ZEPHIR_CALL_FUNCTION(&_4, "chr", &_3, 128, &_1);
				zephir_check_call_status();
				ZEPHIR_SINIT_NVAR(_1);
				ZVAL_LONG(&_1, (paddingSize - 1));
				ZEPHIR_CALL_FUNCTION(&_6, "str_repeat", &_5, 129, _4, &_1);
				zephir_check_call_status();
				ZEPHIR_INIT_NVAR(padding);
				ZEPHIR_CONCAT_VV(padding, _2, _6);
				break;
			}
			if (paddingType == 5) {
				ZEPHIR_SINIT_NVAR(_1);
				ZVAL_LONG(&_1, 0);
				ZEPHIR_CALL_FUNCTION(&_2, "chr", &_3, 128, &_1);
				zephir_check_call_status();
				ZEPHIR_SINIT_NVAR(_1);
				ZVAL_LONG(&_1, paddingSize);
				ZEPHIR_CALL_FUNCTION(&padding, "str_repeat", &_5, 129, _2, &_1);
				zephir_check_call_status();
				break;
			}
			if (paddingType == 6) {
				ZEPHIR_SINIT_NVAR(_1);
				ZVAL_STRING(&_1, " ", 0);
				ZEPHIR_SINIT_VAR(_11);
				ZVAL_LONG(&_11, paddingSize);
				ZEPHIR_CALL_FUNCTION(&padding, "str_repeat", &_5, 129, &_1, &_11);
				zephir_check_call_status();
				break;
			}
			paddingSize = 0;
			break;
		} while(0);

	}
	if (!(paddingSize)) {
		RETURN_CTOR(text);
	}
	if (paddingSize > blockSize) {
		ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_crypt_exception_ce, "Invalid padding size", "phalcon/crypt.zep", 186);
		return;
	}
	ZEPHIR_SINIT_NVAR(_1);
	ZVAL_LONG(&_1, 0);
	ZEPHIR_SINIT_NVAR(_11);
	ZVAL_LONG(&_11, paddingSize);
	ZEPHIR_INIT_VAR(_12);
	zephir_substr(_12, padding, 0 , zephir_get_intval(&_11), 0);
	ZEPHIR_CONCAT_VV(return_value, text, _12);
	RETURN_MM();

}
Example #14
0
/**
 * We have to cast values manually because parse_ini_file() has a poor implementation.
 *
 * @param mixed ini The array casted by `parse_ini_file`
 */
PHP_METHOD(Phalcon_Config_Adapter_Ini, _cast) {

	zend_bool _5$$5, _6$$5, _8$$5, _9$$5;
	HashTable *_1$$3;
	HashPosition _0$$3;
	zephir_fcall_cache_entry *_4 = NULL;
	int ZEPHIR_LAST_CALL_STATUS;
	zval *ini, *key = NULL, *val = NULL, **_2$$3, *_3$$4 = NULL, *_7$$5, *_10$$5, *_11$$9, *_12$$9, _13$$9;

	ZEPHIR_MM_GROW();
	zephir_fetch_params(1, 1, 0, &ini);

	ZEPHIR_SEPARATE_PARAM(ini);


	if (Z_TYPE_P(ini) == IS_ARRAY) {
		zephir_is_iterable(ini, &_1$$3, &_0$$3, 1, 0, "phalcon/config/adapter/ini.zep", 152);
		for (
		  ; zephir_hash_get_current_data_ex(_1$$3, (void**) &_2$$3, &_0$$3) == SUCCESS
		  ; zephir_hash_move_forward_ex(_1$$3, &_0$$3)
		) {
			ZEPHIR_GET_HMKEY(key, _1$$3, _0$$3);
			ZEPHIR_GET_HVALUE(val, _2$$3);
			ZEPHIR_CALL_METHOD(&_3$$4, this_ptr, "_cast", &_4, 138, val);
			zephir_check_call_status();
			zephir_array_update_zval(&ini, key, &_3$$4, PH_COPY | PH_SEPARATE);
		}
		zend_hash_destroy(_1$$3);
		FREE_HASHTABLE(_1$$3);
	}
	if (Z_TYPE_P(ini) == IS_STRING) {
		_5$$5 = ZEPHIR_IS_STRING_IDENTICAL(ini, "true");
		if (!(_5$$5)) {
			_5$$5 = ZEPHIR_IS_STRING_IDENTICAL(ini, "yes");
		}
		_6$$5 = _5$$5;
		if (!(_6$$5)) {
			ZEPHIR_INIT_VAR(_7$$5);
			zephir_fast_strtolower(_7$$5, ini);
			_6$$5 = ZEPHIR_IS_STRING_IDENTICAL(_7$$5, "on");
		}
		if (_6$$5) {
			RETURN_MM_BOOL(1);
		}
		_8$$5 = ZEPHIR_IS_STRING_IDENTICAL(ini, "false");
		if (!(_8$$5)) {
			_8$$5 = ZEPHIR_IS_STRING_IDENTICAL(ini, "no");
		}
		_9$$5 = _8$$5;
		if (!(_9$$5)) {
			ZEPHIR_INIT_VAR(_10$$5);
			zephir_fast_strtolower(_10$$5, ini);
			_9$$5 = ZEPHIR_IS_STRING_IDENTICAL(_10$$5, "off");
		}
		if (_9$$5) {
			RETURN_MM_BOOL(0);
		}
		if (ZEPHIR_IS_STRING_IDENTICAL(ini, "null")) {
			RETURN_MM_NULL();
		}
		if (zephir_is_numeric(ini)) {
			ZEPHIR_INIT_VAR(_11$$9);
			ZEPHIR_INIT_VAR(_12$$9);
			ZEPHIR_SINIT_VAR(_13$$9);
			ZVAL_STRING(&_13$$9, "/[.]+/", 0);
			zephir_preg_match(_12$$9, &_13$$9, ini, _11$$9, 0, 0 , 0  TSRMLS_CC);
			if (zephir_is_true(_12$$9)) {
				RETURN_MM_DOUBLE(zephir_get_doubleval(ini));
			} else {
				RETURN_MM_LONG(zephir_get_intval(ini));
			}
		}
	}
	RETVAL_ZVAL(ini, 1, 0);
	RETURN_MM();

}
Example #15
0
/**
 * Decrypts an encrypted text
 *
 *<code>
 * echo $crypt->decrypt($encrypted, "decrypt password");
 *</code>
 */
PHP_METHOD(Phalcon_Crypt, decrypt) {

	zend_bool _12;
	zephir_fcall_cache_entry *_4 = NULL;
	zend_long ZEPHIR_LAST_CALL_STATUS;
	zval *text_param = NULL, *key = NULL, *decryptKey = NULL, *ivSize = NULL, *cipher = NULL, *mode = NULL, *blockSize = NULL, *paddingType = NULL, *decrypted = NULL, _0 = zval_used_for_init, *_1 = NULL, *_2, *_3 = NULL, *_8, _9, *_10, _11, *_5$$9, *_6$$9, *_7$$9 = NULL;
	zval *text = NULL;

	ZEPHIR_MM_GROW();
	zephir_fetch_params(1, 1, 1, &text_param, &key);

	if (UNEXPECTED(Z_TYPE_P(text_param) != IS_STRING && Z_TYPE_P(text_param) != IS_NULL)) {
		zephir_throw_exception_string(spl_ce_InvalidArgumentException, SL("Parameter 'text' must be a string") TSRMLS_CC);
		RETURN_MM_NULL();
	}
	if (EXPECTED(Z_TYPE_P(text_param) == IS_STRING)) {
		zephir_get_strval(text, text_param);
	} else {
		ZEPHIR_INIT_VAR(text);
		ZVAL_EMPTY_STRING(text);
	}
	if (!key) {
		key = ZEPHIR_GLOBAL(global_null);
	}


	if (!((zephir_function_exists_ex(SS("openssl_cipher_iv_length") TSRMLS_CC) == SUCCESS))) {
		ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_crypt_exception_ce, "openssl extension is required", "phalcon/crypt.zep", 331);
		return;
	}
	if (Z_TYPE_P(key) == IS_NULL) {
		ZEPHIR_OBS_VAR(decryptKey);
		zephir_read_property_this(&decryptKey, this_ptr, SL("_key"), PH_NOISY_CC);
	} else {
		ZEPHIR_CPY_WRT(decryptKey, key);
	}
	if (ZEPHIR_IS_EMPTY(decryptKey)) {
		ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_crypt_exception_ce, "Decryption key cannot be empty", "phalcon/crypt.zep", 341);
		return;
	}
	ZEPHIR_OBS_VAR(cipher);
	zephir_read_property_this(&cipher, this_ptr, SL("_cipher"), PH_NOISY_CC);
	ZEPHIR_SINIT_VAR(_0);
	ZVAL_STRING(&_0, "-", 0);
	ZEPHIR_CALL_FUNCTION(&_1, "strrpos", NULL, 152, cipher, &_0);
	zephir_check_call_status();
	ZEPHIR_SINIT_NVAR(_0);
	ZVAL_LONG(&_0, (zephir_get_numberval(_1) - zephir_fast_strlen_ev(cipher)));
	ZEPHIR_INIT_VAR(_2);
	zephir_substr(_2, cipher, zephir_get_intval(&_0), 0, ZEPHIR_SUBSTR_NO_LENGTH);
	ZEPHIR_INIT_VAR(mode);
	zephir_fast_strtolower(mode, _2);
	ZEPHIR_CALL_FUNCTION(&_3, "openssl_get_cipher_methods", NULL, 153, ZEPHIR_GLOBAL(global_true));
	zephir_check_call_status();
	if (!(zephir_fast_in_array(cipher, _3 TSRMLS_CC))) {
		ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_crypt_exception_ce, "Cipher algorithm is unknown", "phalcon/crypt.zep", 348);
		return;
	}
	ZEPHIR_CALL_FUNCTION(&ivSize, "openssl_cipher_iv_length", &_4, 154, cipher);
	zephir_check_call_status();
	if (ZEPHIR_GT_LONG(ivSize, 0)) {
		ZEPHIR_CPY_WRT(blockSize, ivSize);
	} else {
		ZEPHIR_INIT_VAR(_5$$9);
		ZEPHIR_CONCAT_SV(_5$$9, "-", mode);
		ZEPHIR_INIT_VAR(_6$$9);
		ZVAL_STRING(_6$$9, "", ZEPHIR_TEMP_PARAM_COPY);
		ZEPHIR_CALL_FUNCTION(&_7$$9, "str_ireplace", NULL, 155, _5$$9, _6$$9, cipher);
		zephir_check_temp_parameter(_6$$9);
		zephir_check_call_status();
		ZEPHIR_CALL_FUNCTION(&blockSize, "openssl_cipher_iv_length", &_4, 154, _7$$9);
		zephir_check_call_status();
	}
	ZEPHIR_INIT_VAR(_8);
	zephir_substr(_8, text, zephir_get_intval(ivSize), 0, ZEPHIR_SUBSTR_NO_LENGTH);
	ZEPHIR_SINIT_VAR(_9);
	ZVAL_LONG(&_9, 0);
	ZEPHIR_INIT_VAR(_10);
	zephir_substr(_10, text, 0 , zephir_get_intval(ivSize), 0);
	ZEPHIR_SINIT_VAR(_11);
	ZVAL_LONG(&_11, 1);
	ZEPHIR_CALL_FUNCTION(&decrypted, "openssl_decrypt", NULL, 158, _8, cipher, decryptKey, &_11, _10);
	zephir_check_call_status();
	ZEPHIR_OBS_VAR(paddingType);
	zephir_read_property_this(&paddingType, this_ptr, SL("_padding"), PH_NOISY_CC);
	_12 = ZEPHIR_IS_STRING(mode, "cbc");
	if (!(_12)) {
		_12 = ZEPHIR_IS_STRING(mode, "ecb");
	}
	if (_12) {
		ZEPHIR_RETURN_CALL_METHOD(this_ptr, "_cryptunpadtext", NULL, 0, decrypted, mode, blockSize, paddingType);
		zephir_check_call_status();
		RETURN_MM();
	}
	RETURN_CCTOR(decrypted);

}
Example #16
0
/**
 * Commits the active transaction in the connection
 */
PHP_METHOD(Phalcon_Db_Adapter_Pdo, commit) {

	int ZEPHIR_LAST_CALL_STATUS, transactionLevel = 0;
	zval *nesting_param = NULL, *pdo = NULL, *eventsManager = NULL, *savepointName = NULL, *_0, *_1$$5, *_2$$6, *_5$$7 = NULL, *_6$$8, *_7$$9;
	zend_bool nesting, _3$$7, _4$$7;

	ZEPHIR_MM_GROW();
	zephir_fetch_params(1, 0, 1, &nesting_param);

	if (!nesting_param) {
		nesting = 1;
	} else {
		nesting = zephir_get_boolval(nesting_param);
	}


	ZEPHIR_OBS_VAR(pdo);
	zephir_read_property_this(&pdo, this_ptr, SL("_pdo"), PH_NOISY_CC);
	if (Z_TYPE_P(pdo) != IS_OBJECT) {
		RETURN_MM_BOOL(0);
	}
	ZEPHIR_OBS_VAR(_0);
	zephir_read_property_this(&_0, this_ptr, SL("_transactionLevel"), PH_NOISY_CC);
	transactionLevel = zephir_get_intval(_0);
	if (!(transactionLevel)) {
		ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_db_exception_ce, "There is no active transaction", "phalcon/db/adapter/pdo.zep", 662);
		return;
	}
	if (transactionLevel == 1) {
		_1$$5 = zephir_fetch_nproperty_this(this_ptr, SL("_eventsManager"), PH_NOISY_CC);
		ZEPHIR_CPY_WRT(eventsManager, _1$$5);
		if (Z_TYPE_P(eventsManager) == IS_OBJECT) {
			ZEPHIR_INIT_VAR(_2$$6);
			ZVAL_STRING(_2$$6, "db:commitTransaction", ZEPHIR_TEMP_PARAM_COPY);
			ZEPHIR_CALL_METHOD(NULL, eventsManager, "fire", NULL, 0, _2$$6, this_ptr);
			zephir_check_temp_parameter(_2$$6);
			zephir_check_call_status();
		}
		RETURN_ON_FAILURE(zephir_property_decr(this_ptr, SL("_transactionLevel") TSRMLS_CC));
		ZEPHIR_RETURN_CALL_METHOD(pdo, "commit", NULL, 0);
		zephir_check_call_status();
		RETURN_MM();
	} else {
		_3$$7 = (transactionLevel) ? 1 : 0;
		if (_3$$7) {
			_3$$7 = nesting;
		}
		_4$$7 = _3$$7;
		if (_4$$7) {
			ZEPHIR_CALL_METHOD(&_5$$7, this_ptr, "isnestedtransactionswithsavepoints", NULL, 0);
			zephir_check_call_status();
			_4$$7 = zephir_is_true(_5$$7);
		}
		if (_4$$7) {
			_6$$8 = zephir_fetch_nproperty_this(this_ptr, SL("_eventsManager"), PH_NOISY_CC);
			ZEPHIR_CPY_WRT(eventsManager, _6$$8);
			ZEPHIR_CALL_METHOD(&savepointName, this_ptr, "getnestedtransactionsavepointname", NULL, 0);
			zephir_check_call_status();
			if (Z_TYPE_P(eventsManager) == IS_OBJECT) {
				ZEPHIR_INIT_VAR(_7$$9);
				ZVAL_STRING(_7$$9, "db:releaseSavepoint", ZEPHIR_TEMP_PARAM_COPY);
				ZEPHIR_CALL_METHOD(NULL, eventsManager, "fire", NULL, 0, _7$$9, this_ptr, savepointName);
				zephir_check_temp_parameter(_7$$9);
				zephir_check_call_status();
			}
			RETURN_ON_FAILURE(zephir_property_decr(this_ptr, SL("_transactionLevel") TSRMLS_CC));
			ZEPHIR_RETURN_CALL_METHOD(this_ptr, "releasesavepoint", NULL, 0, savepointName);
			zephir_check_call_status();
			RETURN_MM();
		}
	}
	if (transactionLevel > 0) {
		RETURN_ON_FAILURE(zephir_property_decr(this_ptr, SL("_transactionLevel") TSRMLS_CC));
	}
	RETURN_MM_BOOL(0);

}
Example #17
0
/**
 * Decrypt a text that is coded as a base64 string
 */
PHP_METHOD(Phalcon_Crypt, decryptBase64) {

	zephir_fcall_cache_entry *_6 = NULL, *_7 = NULL;
	zend_long ZEPHIR_LAST_CALL_STATUS;
	zend_bool safe;
	zval *text_param = NULL, *key = NULL, *safe_param = NULL, _0$$3 = zval_used_for_init, _1$$3 = zval_used_for_init, *_2$$3 = NULL, *_3$$3, *_4$$3, *_5$$3 = NULL, *_8 = NULL;
	zval *text = NULL;

	ZEPHIR_MM_GROW();
	zephir_fetch_params(1, 1, 2, &text_param, &key, &safe_param);

	if (UNEXPECTED(Z_TYPE_P(text_param) != IS_STRING && Z_TYPE_P(text_param) != IS_NULL)) {
		zephir_throw_exception_string(spl_ce_InvalidArgumentException, SL("Parameter 'text' must be a string") TSRMLS_CC);
		RETURN_MM_NULL();
	}
	if (EXPECTED(Z_TYPE_P(text_param) == IS_STRING)) {
		zephir_get_strval(text, text_param);
	} else {
		ZEPHIR_INIT_VAR(text);
		ZVAL_EMPTY_STRING(text);
	}
	if (!key) {
		key = ZEPHIR_GLOBAL(global_null);
	}
	if (!safe_param) {
		safe = 0;
	} else {
	if (UNEXPECTED(Z_TYPE_P(safe_param) != IS_BOOL)) {
		zephir_throw_exception_string(spl_ce_InvalidArgumentException, SL("Parameter 'safe' must be a bool") TSRMLS_CC);
		RETURN_MM_NULL();
	}
	safe = Z_BVAL_P(safe_param);
	}


	if (safe == 1) {
		ZEPHIR_SINIT_VAR(_0$$3);
		ZVAL_STRING(&_0$$3, "-_", 0);
		ZEPHIR_SINIT_VAR(_1$$3);
		ZVAL_STRING(&_1$$3, "+/", 0);
		ZEPHIR_CALL_FUNCTION(&_2$$3, "strtr", NULL, 27, text, &_0$$3, &_1$$3);
		zephir_check_call_status();
		ZEPHIR_SINIT_NVAR(_0$$3);
		ZVAL_STRING(&_0$$3, "===", 0);
		ZEPHIR_SINIT_NVAR(_1$$3);
		ZVAL_DOUBLE(&_1$$3, zephir_safe_mod_long_long(((zephir_fast_strlen_ev(text) + 3)), 4 TSRMLS_CC));
		ZEPHIR_INIT_VAR(_3$$3);
		zephir_substr(_3$$3, &_0$$3, zephir_get_intval(&_1$$3), 0, ZEPHIR_SUBSTR_NO_LENGTH);
		ZEPHIR_INIT_VAR(_4$$3);
		ZEPHIR_CONCAT_VV(_4$$3, _2$$3, _3$$3);
		ZEPHIR_CALL_FUNCTION(&_5$$3, "base64_decode", &_6, 133, _4$$3);
		zephir_check_call_status();
		ZEPHIR_RETURN_CALL_METHOD(this_ptr, "decrypt", &_7, 0, _5$$3, key);
		zephir_check_call_status();
		RETURN_MM();
	}
	ZEPHIR_CALL_FUNCTION(&_8, "base64_decode", &_6, 133, text);
	zephir_check_call_status();
	ZEPHIR_RETURN_CALL_METHOD(this_ptr, "decrypt", &_7, 0, _8, key);
	zephir_check_call_status();
	RETURN_MM();

}
Example #18
0
/**
 * Autoloads the registered classes
 */
PHP_METHOD(Phalcon_Loader, autoLoad) {

	zephir_fcall_cache_entry *_10 = NULL, *_12 = NULL, *_13 = NULL, *_23 = NULL, *_24 = NULL, *_31 = NULL, *_32 = NULL;
	HashTable *_2, *_7, *_15, *_21, *_26, *_29;
	HashPosition _1, _6, _14, _20, _25, _28;
	int ZEPHIR_LAST_CALL_STATUS;
	zval *className_param = NULL, *eventsManager, *classes, *extensions, *filePath = NULL, *ds, *fixedDirectory = NULL, *prefixes, *directories, *namespaceSeparator, *namespaces, *nsPrefix = NULL, *directory = NULL, *fileName = NULL, *extension = NULL, *prefix = NULL, *dsClassName, *nsClassName, *_0 = NULL, **_3, *_4 = NULL, _5 = zval_used_for_init, **_8, *_9 = NULL, *_11 = NULL, **_16, *_17 = NULL, _18 = zval_used_for_init, _19 = zval_used_for_init, **_22, **_27, **_30;
	zval *className = NULL;

	ZEPHIR_MM_GROW();
	zephir_fetch_params(1, 1, 0, &className_param);

	if (unlikely(Z_TYPE_P(className_param) != IS_STRING && Z_TYPE_P(className_param) != IS_NULL)) {
		zephir_throw_exception_string(spl_ce_InvalidArgumentException, SL("Parameter 'className' must be a string") TSRMLS_CC);
		RETURN_MM_NULL();
	}

	if (likely(Z_TYPE_P(className_param) == IS_STRING)) {
		zephir_get_strval(className, className_param);
	} else {
		ZEPHIR_INIT_VAR(className);
		ZVAL_EMPTY_STRING(className);
	}


	ZEPHIR_OBS_VAR(eventsManager);
	zephir_read_property_this(&eventsManager, this_ptr, SL("_eventsManager"), PH_NOISY_CC);
	if (Z_TYPE_P(eventsManager) == IS_OBJECT) {
		ZEPHIR_INIT_VAR(_0);
		ZVAL_STRING(_0, "loader:beforeCheckClass", ZEPHIR_TEMP_PARAM_COPY);
		ZEPHIR_CALL_METHOD(NULL, eventsManager, "fire", NULL, 0, _0, this_ptr, className);
		zephir_check_temp_parameter(_0);
		zephir_check_call_status();
	}
	ZEPHIR_OBS_VAR(classes);
	zephir_read_property_this(&classes, this_ptr, SL("_classes"), PH_NOISY_CC);
	if (Z_TYPE_P(classes) == IS_ARRAY) {
		ZEPHIR_OBS_VAR(filePath);
		if (zephir_array_isset_fetch(&filePath, classes, className, 0 TSRMLS_CC)) {
			if (Z_TYPE_P(eventsManager) == IS_OBJECT) {
				zephir_update_property_this(this_ptr, SL("_foundPath"), filePath TSRMLS_CC);
				ZEPHIR_INIT_NVAR(_0);
				ZVAL_STRING(_0, "loader:pathFound", ZEPHIR_TEMP_PARAM_COPY);
				ZEPHIR_CALL_METHOD(NULL, eventsManager, "fire", NULL, 0, _0, this_ptr, filePath);
				zephir_check_temp_parameter(_0);
				zephir_check_call_status();
			}
			if (zephir_require_zval(filePath TSRMLS_CC) == FAILURE) {
				RETURN_MM_NULL();
			}
			RETURN_MM_BOOL(1);
		}
	}
	ZEPHIR_OBS_VAR(extensions);
	zephir_read_property_this(&extensions, this_ptr, SL("_extensions"), PH_NOISY_CC);
	ZEPHIR_INIT_VAR(ds);
	ZVAL_STRING(ds, "/", 1);
	ZEPHIR_INIT_VAR(namespaceSeparator);
	ZVAL_STRING(namespaceSeparator, "\\", 1);
	ZEPHIR_OBS_VAR(namespaces);
	zephir_read_property_this(&namespaces, this_ptr, SL("_namespaces"), PH_NOISY_CC);
	if (Z_TYPE_P(namespaces) == IS_ARRAY) {
		zephir_is_iterable(namespaces, &_2, &_1, 0, 0, "phalcon/loader.zep", 347);
		for (
		  ; zephir_hash_get_current_data_ex(_2, (void**) &_3, &_1) == SUCCESS
		  ; zephir_hash_move_forward_ex(_2, &_1)
		) {
			ZEPHIR_GET_HMKEY(nsPrefix, _2, _1);
			ZEPHIR_GET_HVALUE(directory, _3);
			if (zephir_start_with(className, nsPrefix, NULL)) {
				ZEPHIR_INIT_LNVAR(_4);
				ZEPHIR_CONCAT_VV(_4, nsPrefix, namespaceSeparator);
				ZEPHIR_SINIT_NVAR(_5);
				ZVAL_LONG(&_5, zephir_fast_strlen_ev(_4));
				ZEPHIR_INIT_NVAR(fileName);
				zephir_substr(fileName, className, zephir_get_intval(&_5), 0, ZEPHIR_SUBSTR_NO_LENGTH);
				ZEPHIR_INIT_NVAR(_0);
				zephir_fast_str_replace(&_0, namespaceSeparator, ds, fileName TSRMLS_CC);
				ZEPHIR_CPY_WRT(fileName, _0);
				if (zephir_is_true(fileName)) {
					ZEPHIR_INIT_NVAR(_0);
					zephir_fast_trim(_0, directory, ds, ZEPHIR_TRIM_RIGHT TSRMLS_CC);
					ZEPHIR_INIT_NVAR(fixedDirectory);
					ZEPHIR_CONCAT_VV(fixedDirectory, _0, ds);
					zephir_is_iterable(extensions, &_7, &_6, 0, 0, "phalcon/loader.zep", 344);
					for (
					  ; zephir_hash_get_current_data_ex(_7, (void**) &_8, &_6) == SUCCESS
					  ; zephir_hash_move_forward_ex(_7, &_6)
					) {
						ZEPHIR_GET_HVALUE(extension, _8);
						ZEPHIR_INIT_NVAR(filePath);
						ZEPHIR_CONCAT_VVSV(filePath, fixedDirectory, fileName, ".", extension);
						if (Z_TYPE_P(eventsManager) == IS_OBJECT) {
							zephir_update_property_this(this_ptr, SL("_checkedPath"), filePath TSRMLS_CC);
							ZEPHIR_INIT_NVAR(_9);
							ZVAL_STRING(_9, "loader:beforeCheckPath", ZEPHIR_TEMP_PARAM_COPY);
							ZEPHIR_CALL_METHOD(NULL, eventsManager, "fire", &_10, 0, _9, this_ptr);
							zephir_check_temp_parameter(_9);
							zephir_check_call_status();
						}
						ZEPHIR_CALL_FUNCTION(&_11, "is_file", &_12, 279, filePath);
						zephir_check_call_status();
						if (zephir_is_true(_11)) {
							if (Z_TYPE_P(eventsManager) == IS_OBJECT) {
								zephir_update_property_this(this_ptr, SL("_foundPath"), filePath TSRMLS_CC);
								ZEPHIR_INIT_NVAR(_9);
								ZVAL_STRING(_9, "loader:pathFound", ZEPHIR_TEMP_PARAM_COPY);
								ZEPHIR_CALL_METHOD(NULL, eventsManager, "fire", &_13, 0, _9, this_ptr, filePath);
								zephir_check_temp_parameter(_9);
								zephir_check_call_status();
							}
							if (zephir_require_zval(filePath TSRMLS_CC) == FAILURE) {
								RETURN_MM_NULL();
							}
							RETURN_MM_BOOL(1);
						}
					}
				}
			}
		}
	}
	ZEPHIR_OBS_VAR(prefixes);
	zephir_read_property_this(&prefixes, this_ptr, SL("_prefixes"), PH_NOISY_CC);
	if (Z_TYPE_P(prefixes) == IS_ARRAY) {
		zephir_is_iterable(prefixes, &_15, &_14, 0, 0, "phalcon/loader.zep", 402);
		for (
		  ; zephir_hash_get_current_data_ex(_15, (void**) &_16, &_14) == SUCCESS
		  ; zephir_hash_move_forward_ex(_15, &_14)
		) {
			ZEPHIR_GET_HMKEY(prefix, _15, _14);
			ZEPHIR_GET_HVALUE(directory, _16);
			if (zephir_start_with(className, prefix, NULL)) {
				ZEPHIR_INIT_LNVAR(_4);
				ZEPHIR_CONCAT_VV(_4, prefix, namespaceSeparator);
				ZEPHIR_SINIT_NVAR(_5);
				ZVAL_STRING(&_5, "", 0);
				ZEPHIR_INIT_NVAR(fileName);
				zephir_fast_str_replace(&fileName, _4, &_5, className TSRMLS_CC);
				ZEPHIR_INIT_NVAR(_0);
				ZEPHIR_INIT_LNVAR(_17);
				ZEPHIR_CONCAT_VS(_17, prefix, "_");
				ZEPHIR_SINIT_NVAR(_18);
				ZVAL_STRING(&_18, "", 0);
				zephir_fast_str_replace(&_0, _17, &_18, fileName TSRMLS_CC);
				ZEPHIR_CPY_WRT(fileName, _0);
				ZEPHIR_INIT_NVAR(_0);
				ZEPHIR_SINIT_NVAR(_19);
				ZVAL_STRING(&_19, "_", 0);
				zephir_fast_str_replace(&_0, &_19, ds, fileName TSRMLS_CC);
				ZEPHIR_CPY_WRT(fileName, _0);
				if (zephir_is_true(fileName)) {
					ZEPHIR_INIT_NVAR(_0);
					zephir_fast_trim(_0, directory, ds, ZEPHIR_TRIM_RIGHT TSRMLS_CC);
					ZEPHIR_INIT_NVAR(fixedDirectory);
					ZEPHIR_CONCAT_VV(fixedDirectory, _0, ds);
					zephir_is_iterable(extensions, &_21, &_20, 0, 0, "phalcon/loader.zep", 399);
					for (
					  ; zephir_hash_get_current_data_ex(_21, (void**) &_22, &_20) == SUCCESS
					  ; zephir_hash_move_forward_ex(_21, &_20)
					) {
						ZEPHIR_GET_HVALUE(extension, _22);
						ZEPHIR_INIT_NVAR(filePath);
						ZEPHIR_CONCAT_VVSV(filePath, fixedDirectory, fileName, ".", extension);
						if (Z_TYPE_P(eventsManager) == IS_OBJECT) {
							zephir_update_property_this(this_ptr, SL("_checkedPath"), filePath TSRMLS_CC);
							ZEPHIR_INIT_NVAR(_9);
							ZVAL_STRING(_9, "loader:beforeCheckPath", ZEPHIR_TEMP_PARAM_COPY);
							ZEPHIR_CALL_METHOD(NULL, eventsManager, "fire", &_23, 0, _9, this_ptr, filePath);
							zephir_check_temp_parameter(_9);
							zephir_check_call_status();
						}
						ZEPHIR_CALL_FUNCTION(&_11, "is_file", &_12, 279, filePath);
						zephir_check_call_status();
						if (zephir_is_true(_11)) {
							if (Z_TYPE_P(eventsManager) == IS_OBJECT) {
								zephir_update_property_this(this_ptr, SL("_foundPath"), filePath TSRMLS_CC);
								ZEPHIR_INIT_NVAR(_9);
								ZVAL_STRING(_9, "loader:pathFound", ZEPHIR_TEMP_PARAM_COPY);
								ZEPHIR_CALL_METHOD(NULL, eventsManager, "fire", &_24, 0, _9, this_ptr, filePath);
								zephir_check_temp_parameter(_9);
								zephir_check_call_status();
							}
							if (zephir_require_zval(filePath TSRMLS_CC) == FAILURE) {
								RETURN_MM_NULL();
							}
							RETURN_MM_BOOL(1);
						}
					}
				}
			}
		}
	}
	ZEPHIR_SINIT_NVAR(_5);
	ZVAL_STRING(&_5, "_", 0);
	ZEPHIR_INIT_VAR(dsClassName);
	zephir_fast_str_replace(&dsClassName, &_5, ds, className TSRMLS_CC);
	ZEPHIR_SINIT_NVAR(_18);
	ZVAL_STRING(&_18, "\\", 0);
	ZEPHIR_INIT_VAR(nsClassName);
	zephir_fast_str_replace(&nsClassName, &_18, ds, dsClassName TSRMLS_CC);
	ZEPHIR_OBS_VAR(directories);
	zephir_read_property_this(&directories, this_ptr, SL("_directories"), PH_NOISY_CC);
	if (Z_TYPE_P(directories) == IS_ARRAY) {
		zephir_is_iterable(directories, &_26, &_25, 0, 0, "phalcon/loader.zep", 464);
		for (
		  ; zephir_hash_get_current_data_ex(_26, (void**) &_27, &_25) == SUCCESS
		  ; zephir_hash_move_forward_ex(_26, &_25)
		) {
			ZEPHIR_GET_HVALUE(directory, _27);
			ZEPHIR_INIT_NVAR(_0);
			zephir_fast_trim(_0, directory, ds, ZEPHIR_TRIM_RIGHT TSRMLS_CC);
			ZEPHIR_INIT_NVAR(fixedDirectory);
			ZEPHIR_CONCAT_VV(fixedDirectory, _0, ds);
			zephir_is_iterable(extensions, &_29, &_28, 0, 0, "phalcon/loader.zep", 463);
			for (
			  ; zephir_hash_get_current_data_ex(_29, (void**) &_30, &_28) == SUCCESS
			  ; zephir_hash_move_forward_ex(_29, &_28)
			) {
				ZEPHIR_GET_HVALUE(extension, _30);
				ZEPHIR_INIT_NVAR(filePath);
				ZEPHIR_CONCAT_VVSV(filePath, fixedDirectory, nsClassName, ".", extension);
				if (Z_TYPE_P(eventsManager) == IS_OBJECT) {
					zephir_update_property_this(this_ptr, SL("_checkedPath"), filePath TSRMLS_CC);
					ZEPHIR_INIT_NVAR(_9);
					ZVAL_STRING(_9, "loader:beforeCheckPath", ZEPHIR_TEMP_PARAM_COPY);
					ZEPHIR_CALL_METHOD(NULL, eventsManager, "fire", &_31, 0, _9, this_ptr, filePath);
					zephir_check_temp_parameter(_9);
					zephir_check_call_status();
				}
				ZEPHIR_CALL_FUNCTION(&_11, "is_file", &_12, 279, filePath);
				zephir_check_call_status();
				if (zephir_is_true(_11)) {
					if (Z_TYPE_P(eventsManager) == IS_OBJECT) {
						zephir_update_property_this(this_ptr, SL("_foundPath"), filePath TSRMLS_CC);
						ZEPHIR_INIT_NVAR(_9);
						ZVAL_STRING(_9, "loader:pathFound", ZEPHIR_TEMP_PARAM_COPY);
						ZEPHIR_CALL_METHOD(NULL, eventsManager, "fire", &_32, 0, _9, this_ptr, filePath);
						zephir_check_temp_parameter(_9);
						zephir_check_call_status();
					}
					if (zephir_require_zval(filePath TSRMLS_CC) == FAILURE) {
						RETURN_MM_NULL();
					}
					RETURN_MM_BOOL(1);
				}
			}
		}
	}
	if (Z_TYPE_P(eventsManager) == IS_OBJECT) {
		ZEPHIR_INIT_NVAR(_0);
		ZVAL_STRING(_0, "loader:afterCheckClass", ZEPHIR_TEMP_PARAM_COPY);
		ZEPHIR_CALL_METHOD(NULL, eventsManager, "fire", NULL, 0, _0, this_ptr, className);
		zephir_check_temp_parameter(_0);
		zephir_check_call_status();
	}
	RETURN_MM_BOOL(0);

}
Example #19
0
/**
 * Sets a cookie to be sent at the end of the request
 * This method overrides any cookie set before with the same name
 *
 * @param string name
 * @param mixed value
 * @param int expire
 * @param string path
 * @param boolean secure
 * @param string domain
 * @param boolean httpOnly
 * @return Phalcon\Http\Response\Cookies
 */
PHP_METHOD(Phalcon_Http_Response_Cookies, set) {

	int expire, ZEPHIR_LAST_CALL_STATUS;
	zval *name_param = NULL, *value = NULL, *expire_param = NULL, *path_param = NULL, *secure = NULL, *domain_param = NULL, *httpOnly = NULL, *cookie = NULL, *encryption, *dependencyInjector, *response = NULL, *_0, *_1 = NULL, *_2;
	zval *name = NULL, *path = NULL, *domain = NULL;

	ZEPHIR_MM_GROW();
	zephir_fetch_params(1, 1, 6, &name_param, &value, &expire_param, &path_param, &secure, &domain_param, &httpOnly);

	if (unlikely(Z_TYPE_P(name_param) != IS_STRING && Z_TYPE_P(name_param) != IS_NULL)) {
		zephir_throw_exception_string(spl_ce_InvalidArgumentException, SL("Parameter 'name' must be a string") TSRMLS_CC);
		RETURN_MM_NULL();
	}

	if (likely(Z_TYPE_P(name_param) == IS_STRING)) {
		zephir_get_strval(name, name_param);
	} else {
		ZEPHIR_INIT_VAR(name);
		ZVAL_EMPTY_STRING(name);
	}
	if (!value) {
		value = ZEPHIR_GLOBAL(global_null);
	}
	if (!expire_param) {
		expire = 0;
	} else {
		expire = zephir_get_intval(expire_param);
	}
	if (!path_param) {
		ZEPHIR_INIT_VAR(path);
		ZVAL_STRING(path, "/", 1);
	} else {
		zephir_get_strval(path, path_param);
	}
	if (!secure) {
		secure = ZEPHIR_GLOBAL(global_null);
	}
	if (!domain_param) {
		ZEPHIR_INIT_VAR(domain);
		ZVAL_EMPTY_STRING(domain);
	} else {
	if (unlikely(Z_TYPE_P(domain_param) != IS_STRING && Z_TYPE_P(domain_param) != IS_NULL)) {
		zephir_throw_exception_string(spl_ce_InvalidArgumentException, SL("Parameter 'domain' must be a string") TSRMLS_CC);
		RETURN_MM_NULL();
	}

	if (likely(Z_TYPE_P(domain_param) == IS_STRING)) {
		zephir_get_strval(domain, domain_param);
	} else {
		ZEPHIR_INIT_VAR(domain);
		ZVAL_EMPTY_STRING(domain);
	}
	}
	if (!httpOnly) {
		httpOnly = ZEPHIR_GLOBAL(global_null);
	}


	ZEPHIR_OBS_VAR(encryption);
	zephir_read_property_this(&encryption, this_ptr, SL("_useEncryption"), PH_NOISY_CC);
	ZEPHIR_OBS_VAR(cookie);
	_0 = zephir_fetch_nproperty_this(this_ptr, SL("_cookies"), PH_NOISY_CC);
	if (!(zephir_array_isset_fetch(&cookie, _0, name, 0 TSRMLS_CC))) {
		ZEPHIR_INIT_NVAR(cookie);
		object_init_ex(cookie, phalcon_http_cookie_ce);
		ZEPHIR_INIT_VAR(_1);
		ZVAL_LONG(_1, expire);
		ZEPHIR_CALL_METHOD(NULL, cookie, "__construct", NULL, 215, name, value, _1, path, secure, domain, httpOnly);
		zephir_check_call_status();
		_2 = zephir_fetch_nproperty_this(this_ptr, SL("_dependencyInjector"), PH_NOISY_CC);
		ZEPHIR_CALL_METHOD(NULL, cookie, "setdi", NULL, 216, _2);
		zephir_check_call_status();
		if (zephir_is_true(encryption)) {
			ZEPHIR_CALL_METHOD(NULL, cookie, "useencryption", NULL, 217, encryption);
			zephir_check_call_status();
		}
		zephir_update_property_array(this_ptr, SL("_cookies"), name, cookie TSRMLS_CC);
	} else {
		ZEPHIR_CALL_METHOD(NULL, cookie, "setvalue", NULL, 218, value);
		zephir_check_call_status();
		ZEPHIR_INIT_NVAR(_1);
		ZVAL_LONG(_1, expire);
		ZEPHIR_CALL_METHOD(NULL, cookie, "setexpiration", NULL, 219, _1);
		zephir_check_call_status();
		ZEPHIR_CALL_METHOD(NULL, cookie, "setpath", NULL, 220, path);
		zephir_check_call_status();
		ZEPHIR_CALL_METHOD(NULL, cookie, "setsecure", NULL, 221, secure);
		zephir_check_call_status();
		ZEPHIR_CALL_METHOD(NULL, cookie, "setdomain", NULL, 222, domain);
		zephir_check_call_status();
		ZEPHIR_CALL_METHOD(NULL, cookie, "sethttponly", NULL, 223, httpOnly);
		zephir_check_call_status();
	}
	_2 = zephir_fetch_nproperty_this(this_ptr, SL("_registered"), PH_NOISY_CC);
	if (ZEPHIR_IS_FALSE_IDENTICAL(_2)) {
		ZEPHIR_OBS_VAR(dependencyInjector);
		zephir_read_property_this(&dependencyInjector, this_ptr, SL("_dependencyInjector"), PH_NOISY_CC);
		if (Z_TYPE_P(dependencyInjector) != IS_OBJECT) {
			ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_http_cookie_exception_ce, "A dependency injection object is required to access the 'response' service", "phalcon/http/response/cookies.zep", 138);
			return;
		}
		ZEPHIR_INIT_NVAR(_1);
		ZVAL_STRING(_1, "response", ZEPHIR_TEMP_PARAM_COPY);
		ZEPHIR_CALL_METHOD(&response, dependencyInjector, "getshared", NULL, 0, _1);
		zephir_check_temp_parameter(_1);
		zephir_check_call_status();
		ZEPHIR_CALL_METHOD(NULL, response, "setcookies", NULL, 0, this_ptr);
		zephir_check_call_status();
	}
	RETURN_THIS();

}
Example #20
0
/**
 * Internal sanitize wrapper to filter_var
 */
PHP_METHOD(Phalcon_Filter, _sanitize) {

	zval *_2$$4, *_9$$10;
	zend_bool _1$$3;
	zephir_fcall_cache_entry *_5 = NULL;
	int ZEPHIR_LAST_CALL_STATUS;
	zval *filter = NULL, *_14$$19;
	zval *value, *filter_param = NULL, *filterObject = NULL, *_0, _3$$5, *_4$$5 = NULL, _6$$6, _7$$8, _8$$9, _10$$10, *_11$$12, *_12$$12, *_13$$19;

	ZEPHIR_MM_GROW();
	zephir_fetch_params(1, 2, 0, &value, &filter_param);

	if (unlikely(Z_TYPE_P(filter_param) != IS_STRING && Z_TYPE_P(filter_param) != IS_NULL)) {
		zephir_throw_exception_string(spl_ce_InvalidArgumentException, SL("Parameter 'filter' must be a string") TSRMLS_CC);
		RETURN_MM_NULL();
	}
	if (likely(Z_TYPE_P(filter_param) == IS_STRING)) {
		zephir_get_strval(filter, filter_param);
	} else {
		ZEPHIR_INIT_VAR(filter);
		ZVAL_EMPTY_STRING(filter);
	}


	ZEPHIR_OBS_VAR(filterObject);
	_0 = zephir_fetch_nproperty_this(this_ptr, SL("_filters"), PH_NOISY_CC);
	if (zephir_array_isset_fetch(&filterObject, _0, filter, 0 TSRMLS_CC)) {
		_1$$3 = zephir_instance_of_ev(filterObject, zend_ce_closure TSRMLS_CC);
		if (!(_1$$3)) {
			_1$$3 = zephir_is_callable(filterObject TSRMLS_CC);
		}
		if (_1$$3) {
			ZEPHIR_INIT_VAR(_2$$4);
			zephir_create_array(_2$$4, 1, 0 TSRMLS_CC);
			zephir_array_fast_append(_2$$4, value);
			ZEPHIR_CALL_USER_FUNC_ARRAY(return_value, filterObject, _2$$4);
			zephir_check_call_status();
			RETURN_MM();
		}
		ZEPHIR_RETURN_CALL_METHOD(filterObject, "filter", NULL, 0, value);
		zephir_check_call_status();
		RETURN_MM();
	}
	do {
		if (ZEPHIR_IS_STRING(filter, "email")) {
			ZEPHIR_SINIT_VAR(_3$$5);
			ZVAL_STRING(&_3$$5, "FILTER_SANITIZE_EMAIL", 0);
			ZEPHIR_CALL_FUNCTION(&_4$$5, "constant", NULL, 187, &_3$$5);
			zephir_check_call_status();
			ZEPHIR_RETURN_CALL_FUNCTION("filter_var", &_5, 188, value, _4$$5);
			zephir_check_call_status();
			RETURN_MM();
		}
		if (ZEPHIR_IS_STRING(filter, "int")) {
			ZEPHIR_SINIT_VAR(_6$$6);
			ZVAL_LONG(&_6$$6, 519);
			ZEPHIR_RETURN_CALL_FUNCTION("filter_var", &_5, 188, value, &_6$$6);
			zephir_check_call_status();
			RETURN_MM();
		}
		if (ZEPHIR_IS_STRING(filter, "int!")) {
			RETURN_MM_LONG(zephir_get_intval(value));
		}
		if (ZEPHIR_IS_STRING(filter, "absint")) {
			ZEPHIR_SINIT_VAR(_7$$8);
			ZVAL_LONG(&_7$$8, zephir_get_intval(value));
			ZEPHIR_RETURN_CALL_FUNCTION("abs", NULL, 189, &_7$$8);
			zephir_check_call_status();
			RETURN_MM();
		}
		if (ZEPHIR_IS_STRING(filter, "string")) {
			ZEPHIR_SINIT_VAR(_8$$9);
			ZVAL_LONG(&_8$$9, 513);
			ZEPHIR_RETURN_CALL_FUNCTION("filter_var", &_5, 188, value, &_8$$9);
			zephir_check_call_status();
			RETURN_MM();
		}
		if (ZEPHIR_IS_STRING(filter, "float")) {
			ZEPHIR_INIT_VAR(_9$$10);
			zephir_create_array(_9$$10, 1, 0 TSRMLS_CC);
			add_assoc_long_ex(_9$$10, SS("flags"), 4096);
			ZEPHIR_SINIT_VAR(_10$$10);
			ZVAL_LONG(&_10$$10, 520);
			ZEPHIR_RETURN_CALL_FUNCTION("filter_var", &_5, 188, value, &_10$$10, _9$$10);
			zephir_check_call_status();
			RETURN_MM();
		}
		if (ZEPHIR_IS_STRING(filter, "float!")) {
			RETURN_MM_DOUBLE(zephir_get_doubleval(value));
		}
		if (ZEPHIR_IS_STRING(filter, "alphanum")) {
			ZEPHIR_INIT_VAR(_11$$12);
			ZVAL_STRING(_11$$12, "/[^A-Za-z0-9]/", ZEPHIR_TEMP_PARAM_COPY);
			ZEPHIR_INIT_VAR(_12$$12);
			ZVAL_STRING(_12$$12, "", ZEPHIR_TEMP_PARAM_COPY);
			ZEPHIR_RETURN_CALL_FUNCTION("preg_replace", NULL, 29, _11$$12, _12$$12, value);
			zephir_check_temp_parameter(_11$$12);
			zephir_check_temp_parameter(_12$$12);
			zephir_check_call_status();
			RETURN_MM();
		}
		if (ZEPHIR_IS_STRING(filter, "trim")) {
			zephir_fast_trim(return_value, value, NULL , ZEPHIR_TRIM_BOTH TSRMLS_CC);
			RETURN_MM();
		}
		if (ZEPHIR_IS_STRING(filter, "striptags")) {
			ZEPHIR_RETURN_CALL_FUNCTION("strip_tags", NULL, 190, value);
			zephir_check_call_status();
			RETURN_MM();
		}
		if (ZEPHIR_IS_STRING(filter, "lower")) {
			if ((zephir_function_exists_ex(SS("mb_strtolower") TSRMLS_CC) == SUCCESS)) {
				ZEPHIR_RETURN_CALL_FUNCTION("mb_strtolower", NULL, 191, value);
				zephir_check_call_status();
				RETURN_MM();
			}
			zephir_fast_strtolower(return_value, value);
			RETURN_MM();
		}
		if (ZEPHIR_IS_STRING(filter, "upper")) {
			if ((zephir_function_exists_ex(SS("mb_strtoupper") TSRMLS_CC) == SUCCESS)) {
				ZEPHIR_RETURN_CALL_FUNCTION("mb_strtoupper", NULL, 192, value);
				zephir_check_call_status();
				RETURN_MM();
			}
			zephir_fast_strtoupper(return_value, value);
			RETURN_MM();
		}
		ZEPHIR_INIT_VAR(_13$$19);
		object_init_ex(_13$$19, phalcon_filter_exception_ce);
		ZEPHIR_INIT_VAR(_14$$19);
		ZEPHIR_CONCAT_SVS(_14$$19, "Sanitize filter '", filter, "' is not supported");
		ZEPHIR_CALL_METHOD(NULL, _13$$19, "__construct", NULL, 9, _14$$19);
		zephir_check_call_status();
		zephir_throw_exception_debug(_13$$19, "phalcon/filter.zep", 213 TSRMLS_CC);
		ZEPHIR_MM_RESTORE();
		return;
	} while(0);

	ZEPHIR_MM_RESTORE();

}
Example #21
0
/**
 * Applies a format to a message before sending it to the log
 *
 * @param string $message
 * @param int $type
 * @param int $timestamp
 * @param array $context
 *
 * @return string
 */
PHP_METHOD(Phalcon_Logger_Formatter_Firephp, format) {

	HashTable *_7$$4;
	HashPosition _6$$4;
	zval *_18;
	zend_bool _11, _14;
	int type, timestamp, ZEPHIR_LAST_CALL_STATUS;
	zval *message_param = NULL, *type_param = NULL, *timestamp_param = NULL, *context = NULL, *meta = NULL, *body = NULL, *backtrace = NULL, *encoded = NULL, *len = NULL, *lastTrace = NULL, *_1 = NULL, *_2, *_3, *_9, *_10, *_12, *_13, *_15, *_0$$3 = NULL, *param$$4 = NULL, *backtraceItem$$4 = NULL, *key$$4 = NULL, **_8$$4, *_4$$5, *_5$$6, *_16$$11, *_17$$11;
	zval *message = NULL;

	ZEPHIR_MM_GROW();
	zephir_fetch_params(1, 3, 1, &message_param, &type_param, &timestamp_param, &context);

	zephir_get_strval(message, message_param);
	type = zephir_get_intval(type_param);
	timestamp = zephir_get_intval(timestamp_param);
	if (!context) {
		context = ZEPHIR_GLOBAL(global_null);
	}


	if (Z_TYPE_P(context) == IS_ARRAY) {
		ZEPHIR_CALL_METHOD(&_0$$3, this_ptr, "interpolate", NULL, 0, message, context);
		zephir_check_call_status();
		zephir_get_strval(message, _0$$3);
	}
	ZEPHIR_INIT_VAR(meta);
	zephir_create_array(meta, 1, 0 TSRMLS_CC);
	ZEPHIR_INIT_VAR(_2);
	ZVAL_LONG(_2, type);
	ZEPHIR_CALL_METHOD(&_1, this_ptr, "gettypestring", NULL, 0, _2);
	zephir_check_call_status();
	zephir_array_update_string(&meta, SL("Type"), &_1, PH_COPY | PH_SEPARATE);
	_3 = zephir_fetch_nproperty_this(this_ptr, SL("_showBacktrace"), PH_NOISY_CC);
	if (zephir_is_true(_3)) {
		ZEPHIR_INIT_VAR(param$$4);
		ZVAL_LONG(param$$4, 2);
		ZEPHIR_CALL_FUNCTION(&backtrace, "debug_backtrace", NULL, 158, param$$4);
		zephir_check_call_status();
		ZEPHIR_MAKE_REF(backtrace);
		ZEPHIR_CALL_FUNCTION(&lastTrace, "end", NULL, 176, backtrace);
		ZEPHIR_UNREF(backtrace);
		zephir_check_call_status();
		if (zephir_array_isset_string(lastTrace, SS("file"))) {
			zephir_array_fetch_string(&_4$$5, lastTrace, SL("file"), PH_NOISY | PH_READONLY, "phalcon/logger/formatter/firephp.zep", 128 TSRMLS_CC);
			zephir_array_update_string(&meta, SL("File"), &_4$$5, PH_COPY | PH_SEPARATE);
		}
		if (zephir_array_isset_string(lastTrace, SS("line"))) {
			zephir_array_fetch_string(&_5$$6, lastTrace, SL("line"), PH_NOISY | PH_READONLY, "phalcon/logger/formatter/firephp.zep", 132 TSRMLS_CC);
			zephir_array_update_string(&meta, SL("Line"), &_5$$6, PH_COPY | PH_SEPARATE);
		}
		zephir_is_iterable(backtrace, &_7$$4, &_6$$4, 1, 0, "phalcon/logger/formatter/firephp.zep", 141);
		for (
		  ; zephir_hash_get_current_data_ex(_7$$4, (void**) &_8$$4, &_6$$4) == SUCCESS
		  ; zephir_hash_move_forward_ex(_7$$4, &_6$$4)
		) {
			ZEPHIR_GET_HMKEY(key$$4, _7$$4, _6$$4);
			ZEPHIR_GET_HVALUE(backtraceItem$$4, _8$$4);
			zephir_array_unset_string(&backtraceItem$$4, SS("object"), PH_SEPARATE);
			zephir_array_unset_string(&backtraceItem$$4, SS("args"), PH_SEPARATE);
			zephir_array_update_zval(&backtrace, key$$4, &backtraceItem$$4, PH_COPY | PH_SEPARATE);
		}
		zend_hash_destroy(_7$$4);
		FREE_HASHTABLE(_7$$4);
	}
	_9 = zephir_fetch_nproperty_this(this_ptr, SL("_enableLabels"), PH_NOISY_CC);
	if (zephir_is_true(_9)) {
		zephir_array_update_string(&meta, SL("Label"), &message, PH_COPY | PH_SEPARATE);
	}
	_10 = zephir_fetch_nproperty_this(this_ptr, SL("_enableLabels"), PH_NOISY_CC);
	_11 = !zephir_is_true(_10);
	if (_11) {
		_12 = zephir_fetch_nproperty_this(this_ptr, SL("_showBacktrace"), PH_NOISY_CC);
		_11 = !zephir_is_true(_12);
	}
	_13 = zephir_fetch_nproperty_this(this_ptr, SL("_enableLabels"), PH_NOISY_CC);
	_14 = zephir_is_true(_13);
	if (_14) {
		_15 = zephir_fetch_nproperty_this(this_ptr, SL("_showBacktrace"), PH_NOISY_CC);
		_14 = !zephir_is_true(_15);
	}
	if (_11) {
		ZEPHIR_CPY_WRT(body, message);
	} else if (_14) {
		ZEPHIR_INIT_NVAR(body);
		ZVAL_STRING(body, "", 1);
	} else {
		ZEPHIR_INIT_NVAR(body);
		array_init(body);
		_16$$11 = zephir_fetch_nproperty_this(this_ptr, SL("_showBacktrace"), PH_NOISY_CC);
		if (zephir_is_true(_16$$11)) {
			zephir_array_update_string(&body, SL("backtrace"), &backtrace, PH_COPY | PH_SEPARATE);
		}
		_17$$11 = zephir_fetch_nproperty_this(this_ptr, SL("_enableLabels"), PH_NOISY_CC);
		if (!(zephir_is_true(_17$$11))) {
			zephir_array_update_string(&body, SL("message"), &message, PH_COPY | PH_SEPARATE);
		}
	}
	ZEPHIR_INIT_VAR(_18);
	zephir_create_array(_18, 2, 0 TSRMLS_CC);
	zephir_array_fast_append(_18, meta);
	zephir_array_fast_append(_18, body);
	ZEPHIR_INIT_VAR(encoded);
	zephir_json_encode(encoded, &(encoded), _18, 0  TSRMLS_CC);
	ZEPHIR_INIT_VAR(len);
	ZVAL_LONG(len, zephir_fast_strlen_ev(encoded));
	ZEPHIR_CONCAT_VSVS(return_value, len, "|", encoded, "|");
	RETURN_MM();

}
Example #22
0
PHP_METHOD(Test_SpectralNorm, process) {

	zend_function *_8 = NULL, *_9 = NULL, *_10 = NULL, *_14 = NULL, *_15 = NULL, *_19 = NULL, *_21 = NULL, *_23 = NULL, *_24 = NULL;
	zend_bool _4, _11, _16;
	zend_class_entry *_0, *_2, *_3;
	zval *n_param = NULL, *u, *v, *w, *_1 = NULL, *_7 = NULL, *_20 = NULL, *_22 = NULL, *_25 = NULL, _26;
	int n, i, vv = 0, vBv = 0, _5, _6, _12, _13, _17, _18;

	ZEPHIR_MM_GROW();
	zephir_fetch_params(1, 1, 0, &n_param);

		n = zephir_get_intval(n_param);


	ZEPHIR_INIT_VAR(u);
	_0 = zend_fetch_class(SL("SplFixedArray"), ZEND_FETCH_CLASS_AUTO TSRMLS_CC);
	object_init_ex(u, _0);
	ZEPHIR_INIT_VAR(_1);
	ZVAL_LONG(_1, n);
	zephir_call_method_p1_noret(u, "__construct", _1);
	ZEPHIR_INIT_VAR(v);
	_2 = zend_fetch_class(SL("SplFixedArray"), ZEND_FETCH_CLASS_AUTO TSRMLS_CC);
	object_init_ex(v, _2);
	ZEPHIR_INIT_BNVAR(_1);
	ZVAL_LONG(_1, n);
	zephir_call_method_p1_noret(v, "__construct", _1);
	ZEPHIR_INIT_VAR(w);
	_3 = zend_fetch_class(SL("SplFixedArray"), ZEND_FETCH_CLASS_AUTO TSRMLS_CC);
	object_init_ex(w, _3);
	ZEPHIR_INIT_BNVAR(_1);
	ZVAL_LONG(_1, n);
	zephir_call_method_p1_noret(w, "__construct", _1);
	_6 = (n - 1);
	_5 = 0;
	_4 = 0;
	if ((_5 <= _6)) {
		while (1) {
			if (_4) {
				_5++;
				if (!((_5 <= _6))) {
					break;
				}
			} else {
				_4 = 1;
			}
			i = _5;
			ZEPHIR_INIT_NVAR(_1);
			ZVAL_LONG(_1, i);
			ZEPHIR_INIT_NVAR(_7);
			ZVAL_LONG(_7, 1);
			zephir_call_method_p2_cache_noret(u, "offsetset", &_8, _1, _7);
			ZEPHIR_INIT_NVAR(_1);
			ZVAL_LONG(_1, i);
			ZEPHIR_INIT_NVAR(_7);
			ZVAL_LONG(_7, 1);
			zephir_call_method_p2_cache_noret(v, "offsetset", &_9, _1, _7);
			ZEPHIR_INIT_NVAR(_1);
			ZVAL_LONG(_1, i);
			ZEPHIR_INIT_NVAR(_7);
			ZVAL_LONG(_7, 1);
			zephir_call_method_p2_cache_noret(w, "offsetset", &_10, _1, _7);
		}
	}
	_13 = 9;
	_12 = 0;
	_11 = 0;
	if ((_12 <= _13)) {
		while (1) {
			if (_11) {
				_12++;
				if (!((_12 <= _13))) {
					break;
				}
			} else {
				_11 = 1;
			}
			i = _12;
			ZEPHIR_INIT_NVAR(_1);
			ZVAL_LONG(_1, n);
			zephir_call_method_p4_cache_noret(this_ptr, "atau", &_14, _1, u, v, w);
			ZEPHIR_INIT_NVAR(_1);
			ZVAL_LONG(_1, n);
			zephir_call_method_p4_cache_noret(this_ptr, "atau", &_15, _1, v, u, w);
		}
	}
	_18 = (n - 1);
	_17 = 0;
	_16 = 0;
	if ((_17 <= _18)) {
		while (1) {
			if (_16) {
				_17++;
				if (!((_17 <= _18))) {
					break;
				}
			} else {
				_16 = 1;
			}
			i = _17;
			ZEPHIR_INIT_NVAR(_1);
			ZEPHIR_INIT_NVAR(_7);
			ZVAL_LONG(_7, i);
			zephir_call_method_p1_cache(_1, u, "offsetget", &_19, _7);
			ZEPHIR_INIT_NVAR(_7);
			ZEPHIR_INIT_NVAR(_20);
			ZVAL_LONG(_20, i);
			zephir_call_method_p1_cache(_7, v, "offsetget", &_21, _20);
			ZEPHIR_INIT_LNVAR(_22);
			mul_function(_22, _1, _7 TSRMLS_CC);
			vBv += zephir_get_numberval(_22);
			ZEPHIR_INIT_NVAR(_1);
			ZEPHIR_INIT_NVAR(_7);
			ZVAL_LONG(_7, i);
			zephir_call_method_p1_cache(_1, v, "offsetget", &_23, _7);
			ZEPHIR_INIT_NVAR(_7);
			ZEPHIR_INIT_NVAR(_20);
			ZVAL_LONG(_20, i);
			zephir_call_method_p1_cache(_7, v, "offsetget", &_24, _20);
			ZEPHIR_INIT_LNVAR(_25);
			mul_function(_25, _1, _7 TSRMLS_CC);
			vv += zephir_get_numberval(_25);
		}
	}
	ZEPHIR_SINIT_VAR(_26);
	ZVAL_LONG(&_26, (vBv / vv));
	zephir_call_func_p1(return_value, "sqrt", &_26);
	RETURN_MM();

}
Example #23
0
/**
 * Returns a cached content
 *
 * @param int|string keyName
 * @param   int lifetime
 * @return  mixed
 */
PHP_METHOD(Phalcon_Cache_Backend_File, get) {

	int ttl, modifiedTime, ZEPHIR_LAST_CALL_STATUS;
	zval *keyName, *lifetime = NULL, *prefixedKey, *cacheDir, *cacheFile, *frontend, *lastLifetime, *cachedContent, *ret = NULL, *_0, *_1 = NULL, *_2, *_3 = NULL, *_4, *_5, *_6, *_7;

	ZEPHIR_MM_GROW();
	zephir_fetch_params(1, 1, 1, &keyName, &lifetime);

	if (!lifetime) {
		lifetime = ZEPHIR_GLOBAL(global_null);
	}


	_0 = zephir_fetch_nproperty_this(this_ptr, SL("_prefix"), PH_NOISY_CC);
	ZEPHIR_CALL_METHOD(&_1, this_ptr, "getkey", NULL, 0, keyName);
	zephir_check_call_status();
	ZEPHIR_INIT_VAR(prefixedKey);
	ZEPHIR_CONCAT_VV(prefixedKey, _0, _1);
	zephir_update_property_this(this_ptr, SL("_lastKey"), prefixedKey TSRMLS_CC);
	ZEPHIR_OBS_VAR(cacheDir);
	_2 = zephir_fetch_nproperty_this(this_ptr, SL("_options"), PH_NOISY_CC);
	if (!(zephir_array_isset_string_fetch(&cacheDir, _2, SS("cacheDir"), 0 TSRMLS_CC))) {
		ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_cache_exception_ce, "Unexpected inconsistency in options", "phalcon/cache/backend/file.zep", 115);
		return;
	}
	ZEPHIR_INIT_VAR(cacheFile);
	ZEPHIR_CONCAT_VV(cacheFile, cacheDir, prefixedKey);
	if ((zephir_file_exists(cacheFile TSRMLS_CC) == SUCCESS) == 1) {
		ZEPHIR_OBS_VAR(frontend);
		zephir_read_property_this(&frontend, this_ptr, SL("_frontend"), PH_NOISY_CC);
		if (!(zephir_is_true(lifetime))) {
			ZEPHIR_OBS_VAR(lastLifetime);
			zephir_read_property_this(&lastLifetime, this_ptr, SL("_lastLifetime"), PH_NOISY_CC);
			if (!(zephir_is_true(lastLifetime))) {
				ZEPHIR_CALL_METHOD(&_3, frontend, "getlifetime", NULL, 0);
				zephir_check_call_status();
				ttl = zephir_get_intval(_3);
			} else {
				ttl = zephir_get_intval(lastLifetime);
			}
		} else {
			ttl = zephir_get_intval(lifetime);
		}
		ZEPHIR_INIT_VAR(_4);
		zephir_filemtime(_4, cacheFile TSRMLS_CC);
		modifiedTime = zephir_get_intval(_4);
		ZEPHIR_INIT_VAR(_5);
		zephir_time(_5);
		if (!((zephir_get_numberval(_5) - ttl) > modifiedTime)) {
			ZEPHIR_INIT_VAR(cachedContent);
			zephir_file_get_contents(cachedContent, cacheFile TSRMLS_CC);
			if (ZEPHIR_IS_FALSE_IDENTICAL(cachedContent)) {
				ZEPHIR_INIT_VAR(_6);
				object_init_ex(_6, phalcon_cache_exception_ce);
				ZEPHIR_INIT_VAR(_7);
				ZEPHIR_CONCAT_SVS(_7, "Cache file ", cacheFile, " could not be opened");
				ZEPHIR_CALL_METHOD(NULL, _6, "__construct", NULL, 2, _7);
				zephir_check_call_status();
				zephir_throw_exception_debug(_6, "phalcon/cache/backend/file.zep", 151 TSRMLS_CC);
				ZEPHIR_MM_RESTORE();
				return;
			}
			if (zephir_is_numeric(cachedContent)) {
				RETURN_CCTOR(cachedContent);
			} else {
				ZEPHIR_CALL_METHOD(&ret, frontend, "afterretrieve", NULL, 0, cachedContent);
				zephir_check_call_status();
				RETURN_CCTOR(ret);
			}
		}
	}
	ZEPHIR_MM_RESTORE();

}
Example #24
0
PHP_METHOD(Test_SpectralNorm, Au) {

	zend_function *_9 = NULL, *_10 = NULL, *_12 = NULL;
	zend_bool _0, _3;
	zval *n_param = NULL, *u, *v, *_6 = NULL, *_7 = NULL, *_8 = NULL, *_11 = NULL;
	int n, t, i, j, _1, _2, _4, _5;

	ZEPHIR_MM_GROW();
	zephir_fetch_params(1, 3, 0, &n_param, &u, &v);

		n = zephir_get_intval(n_param);


	_2 = (n - 1);
	_1 = 0;
	_0 = 0;
	if ((_1 <= _2)) {
		while (1) {
			if (_0) {
				_1++;
				if (!((_1 <= _2))) {
					break;
				}
			} else {
				_0 = 1;
			}
			i = _1;
			t = 0;
			_5 = (n - 1);
			_4 = 0;
			_3 = 0;
			if ((_4 <= _5)) {
				while (1) {
					if (_3) {
						_4++;
						if (!((_4 <= _5))) {
							break;
						}
					} else {
						_3 = 1;
					}
					j = _4;
					ZEPHIR_INIT_NVAR(_6);
					ZEPHIR_INIT_NVAR(_7);
					ZVAL_LONG(_7, i);
					ZEPHIR_INIT_NVAR(_8);
					ZVAL_LONG(_8, j);
					zephir_call_method_p2_cache(_6, this_ptr, "ax", &_9, _7, _8);
					ZEPHIR_INIT_NVAR(_7);
					ZEPHIR_INIT_NVAR(_8);
					ZVAL_LONG(_8, j);
					zephir_call_method_p1_cache(_7, u, "offsetge", &_10, _8);
					ZEPHIR_INIT_LNVAR(_11);
					mul_function(_11, _6, _7 TSRMLS_CC);
					t += zephir_get_numberval(_11);
				}
			}
			ZEPHIR_INIT_NVAR(_6);
			ZVAL_LONG(_6, i);
			ZEPHIR_INIT_NVAR(_7);
			ZVAL_LONG(_7, t);
			zephir_call_method_p2_cache_noret(v, "offsetset", &_12, _6, _7);
		}
	}
	ZEPHIR_MM_RESTORE();

}
Example #25
0
/**
 * Pads texts before encryption
 *
 * @see http://www.di-mgt.com.au/cryptopad.html
 */
PHP_METHOD(Phalcon_Crypt, _cryptPadText) {

	zend_bool _0, _9$$7;
	zephir_fcall_cache_entry *_3 = NULL, *_5 = NULL, *_13 = NULL;
	int blockSize, paddingType, ZEPHIR_LAST_CALL_STATUS, i = 0, paddingSize, _10$$7, _11$$7;
	zval *text_param = NULL, *mode_param = NULL, *blockSize_param = NULL, *paddingType_param = NULL, *padding = NULL, _25, _26, *_27, _1$$5 = zval_used_for_init, *_2$$5 = NULL, *_4$$5 = NULL, *_6$$5 = NULL, _7$$6 = zval_used_for_init, *_8$$6 = NULL, _15$$7, *_16$$7 = NULL, *_12$$8 = NULL, *_14$$8 = NULL, _17$$9 = zval_used_for_init, *_18$$9 = NULL, *_19$$9 = NULL, *_20$$9 = NULL, _21$$10 = zval_used_for_init, *_22$$10 = NULL, _23$$11, _24$$11;
	zval *text = NULL, *mode = NULL;

	ZEPHIR_MM_GROW();
	zephir_fetch_params(1, 4, 0, &text_param, &mode_param, &blockSize_param, &paddingType_param);

	zephir_get_strval(text, text_param);
	if (unlikely(Z_TYPE_P(mode_param) != IS_STRING && Z_TYPE_P(mode_param) != IS_NULL)) {
		zephir_throw_exception_string(spl_ce_InvalidArgumentException, SL("Parameter 'mode' must be a string") TSRMLS_CC);
		RETURN_MM_NULL();
	}
	if (likely(Z_TYPE_P(mode_param) == IS_STRING)) {
		zephir_get_strval(mode, mode_param);
	} else {
		ZEPHIR_INIT_VAR(mode);
		ZVAL_EMPTY_STRING(mode);
	}
	if (unlikely(Z_TYPE_P(blockSize_param) != IS_LONG)) {
		zephir_throw_exception_string(spl_ce_InvalidArgumentException, SL("Parameter 'blockSize' must be a int") TSRMLS_CC);
		RETURN_MM_NULL();
	}
	blockSize = Z_LVAL_P(blockSize_param);
	if (unlikely(Z_TYPE_P(paddingType_param) != IS_LONG)) {
		zephir_throw_exception_string(spl_ce_InvalidArgumentException, SL("Parameter 'paddingType' must be a int") TSRMLS_CC);
		RETURN_MM_NULL();
	}
	paddingType = Z_LVAL_P(paddingType_param);


	paddingSize = 0;
	ZEPHIR_INIT_VAR(padding);
	ZVAL_NULL(padding);
	_0 = ZEPHIR_IS_STRING(mode, "cbc");
	if (!(_0)) {
		_0 = ZEPHIR_IS_STRING(mode, "ecb");
	}
	if (_0) {
		paddingSize = (blockSize - (zephir_safe_mod_long_long(zephir_fast_strlen_ev(text), blockSize TSRMLS_CC)));
		if (paddingSize >= 256) {
			ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_crypt_exception_ce, "Block size is bigger than 256", "phalcon/crypt.zep", 142);
			return;
		}
		do {
			if (paddingType == 1) {
				ZEPHIR_SINIT_VAR(_1$$5);
				ZVAL_LONG(&_1$$5, 0);
				ZEPHIR_CALL_FUNCTION(&_2$$5, "chr", &_3, 132, &_1$$5);
				zephir_check_call_status();
				ZEPHIR_SINIT_NVAR(_1$$5);
				ZVAL_LONG(&_1$$5, (paddingSize - 1));
				ZEPHIR_CALL_FUNCTION(&_4$$5, "str_repeat", &_5, 133, _2$$5, &_1$$5);
				zephir_check_call_status();
				ZEPHIR_SINIT_NVAR(_1$$5);
				ZVAL_LONG(&_1$$5, paddingSize);
				ZEPHIR_CALL_FUNCTION(&_6$$5, "chr", &_3, 132, &_1$$5);
				zephir_check_call_status();
				ZEPHIR_INIT_NVAR(padding);
				ZEPHIR_CONCAT_VV(padding, _4$$5, _6$$5);
				break;
			}
			if (paddingType == 2) {
				ZEPHIR_SINIT_VAR(_7$$6);
				ZVAL_LONG(&_7$$6, paddingSize);
				ZEPHIR_CALL_FUNCTION(&_8$$6, "chr", &_3, 132, &_7$$6);
				zephir_check_call_status();
				ZEPHIR_SINIT_NVAR(_7$$6);
				ZVAL_LONG(&_7$$6, paddingSize);
				ZEPHIR_CALL_FUNCTION(&padding, "str_repeat", &_5, 133, _8$$6, &_7$$6);
				zephir_check_call_status();
				break;
			}
			if (paddingType == 3) {
				ZEPHIR_INIT_NVAR(padding);
				ZVAL_STRING(padding, "", 1);
				_11$$7 = (paddingSize - 2);
				_10$$7 = 0;
				_9$$7 = 0;
				if (_10$$7 <= _11$$7) {
					while (1) {
						if (_9$$7) {
							_10$$7++;
							if (!(_10$$7 <= _11$$7)) {
								break;
							}
						} else {
							_9$$7 = 1;
						}
						i = _10$$7;
						ZEPHIR_CALL_FUNCTION(&_12$$8, "rand", &_13, 111);
						zephir_check_call_status();
						ZEPHIR_CALL_FUNCTION(&_14$$8, "chr", &_3, 132, _12$$8);
						zephir_check_call_status();
						zephir_concat_self(&padding, _14$$8 TSRMLS_CC);
					}
				}
				ZEPHIR_SINIT_VAR(_15$$7);
				ZVAL_LONG(&_15$$7, paddingSize);
				ZEPHIR_CALL_FUNCTION(&_16$$7, "chr", &_3, 132, &_15$$7);
				zephir_check_call_status();
				zephir_concat_self(&padding, _16$$7 TSRMLS_CC);
				break;
			}
			if (paddingType == 4) {
				ZEPHIR_SINIT_VAR(_17$$9);
				ZVAL_LONG(&_17$$9, 0x80);
				ZEPHIR_CALL_FUNCTION(&_18$$9, "chr", &_3, 132, &_17$$9);
				zephir_check_call_status();
				ZEPHIR_SINIT_NVAR(_17$$9);
				ZVAL_LONG(&_17$$9, 0);
				ZEPHIR_CALL_FUNCTION(&_19$$9, "chr", &_3, 132, &_17$$9);
				zephir_check_call_status();
				ZEPHIR_SINIT_NVAR(_17$$9);
				ZVAL_LONG(&_17$$9, (paddingSize - 1));
				ZEPHIR_CALL_FUNCTION(&_20$$9, "str_repeat", &_5, 133, _19$$9, &_17$$9);
				zephir_check_call_status();
				ZEPHIR_INIT_NVAR(padding);
				ZEPHIR_CONCAT_VV(padding, _18$$9, _20$$9);
				break;
			}
			if (paddingType == 5) {
				ZEPHIR_SINIT_VAR(_21$$10);
				ZVAL_LONG(&_21$$10, 0);
				ZEPHIR_CALL_FUNCTION(&_22$$10, "chr", &_3, 132, &_21$$10);
				zephir_check_call_status();
				ZEPHIR_SINIT_NVAR(_21$$10);
				ZVAL_LONG(&_21$$10, paddingSize);
				ZEPHIR_CALL_FUNCTION(&padding, "str_repeat", &_5, 133, _22$$10, &_21$$10);
				zephir_check_call_status();
				break;
			}
			if (paddingType == 6) {
				ZEPHIR_SINIT_VAR(_23$$11);
				ZVAL_STRING(&_23$$11, " ", 0);
				ZEPHIR_SINIT_VAR(_24$$11);
				ZVAL_LONG(&_24$$11, paddingSize);
				ZEPHIR_CALL_FUNCTION(&padding, "str_repeat", &_5, 133, &_23$$11, &_24$$11);
				zephir_check_call_status();
				break;
			}
			paddingSize = 0;
			break;
		} while(0);

	}
	if (!(paddingSize)) {
		RETURN_CTOR(text);
	}
	if (paddingSize > blockSize) {
		ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_crypt_exception_ce, "Invalid padding size", "phalcon/crypt.zep", 186);
		return;
	}
	ZEPHIR_SINIT_VAR(_25);
	ZVAL_LONG(&_25, 0);
	ZEPHIR_SINIT_VAR(_26);
	ZVAL_LONG(&_26, paddingSize);
	ZEPHIR_INIT_VAR(_27);
	zephir_substr(_27, padding, 0 , zephir_get_intval(&_26), 0);
	ZEPHIR_CONCAT_VV(return_value, text, _27);
	RETURN_MM();

}
Example #26
0
/**
 * Sets a cookie to be sent at the end of the request
 * This method overrides any cookie set before with the same name
 */
PHP_METHOD(Phalcon_Http_Response_Cookies, set) {

	zval *_3$$3;
	zend_bool secure, httpOnly;
	int expire, ZEPHIR_LAST_CALL_STATUS;
	zval *name_param = NULL, *value = NULL, *expire_param = NULL, *path_param = NULL, *secure_param = NULL, *domain_param = NULL, *httpOnly_param = NULL, *cookie = NULL, *encryption = NULL, *dependencyInjector = NULL, *response = NULL, *_0, *_8, *_1$$3, *_2$$3 = NULL, *_4$$3 = NULL, *_5$$3, *_6$$5 = NULL, *_7$$5, *_9$$6;
	zval *name = NULL, *path = NULL, *domain = NULL;

	ZEPHIR_MM_GROW();
	zephir_fetch_params(1, 1, 6, &name_param, &value, &expire_param, &path_param, &secure_param, &domain_param, &httpOnly_param);

	if (unlikely(Z_TYPE_P(name_param) != IS_STRING && Z_TYPE_P(name_param) != IS_NULL)) {
		zephir_throw_exception_string(spl_ce_InvalidArgumentException, SL("Parameter 'name' must be a string") TSRMLS_CC);
		RETURN_MM_NULL();
	}
	if (likely(Z_TYPE_P(name_param) == IS_STRING)) {
		zephir_get_strval(name, name_param);
	} else {
		ZEPHIR_INIT_VAR(name);
		ZVAL_EMPTY_STRING(name);
	}
	if (!value) {
		value = ZEPHIR_GLOBAL(global_null);
	}
	if (!expire_param) {
		expire = 0;
	} else {
		expire = zephir_get_intval(expire_param);
	}
	if (!path_param) {
		ZEPHIR_INIT_VAR(path);
		ZVAL_STRING(path, "/", 1);
	} else {
		zephir_get_strval(path, path_param);
	}
	if (!secure_param) {
		secure = 0;
	} else {
		secure = zephir_get_boolval(secure_param);
	}
	if (!domain_param) {
		ZEPHIR_INIT_VAR(domain);
		ZVAL_EMPTY_STRING(domain);
	} else {
	if (unlikely(Z_TYPE_P(domain_param) != IS_STRING && Z_TYPE_P(domain_param) != IS_NULL)) {
		zephir_throw_exception_string(spl_ce_InvalidArgumentException, SL("Parameter 'domain' must be a string") TSRMLS_CC);
		RETURN_MM_NULL();
	}
	if (likely(Z_TYPE_P(domain_param) == IS_STRING)) {
		zephir_get_strval(domain, domain_param);
	} else {
		ZEPHIR_INIT_VAR(domain);
		ZVAL_EMPTY_STRING(domain);
	}
	}
	if (!httpOnly_param) {
		httpOnly = 0;
	} else {
		httpOnly = zephir_get_boolval(httpOnly_param);
	}


	ZEPHIR_OBS_VAR(encryption);
	zephir_read_property_this(&encryption, this_ptr, SL("_useEncryption"), PH_NOISY_CC);
	ZEPHIR_OBS_VAR(cookie);
	_0 = zephir_fetch_nproperty_this(this_ptr, SL("_cookies"), PH_NOISY_CC);
	if (!(zephir_array_isset_fetch(&cookie, _0, name, 0 TSRMLS_CC))) {
		_1$$3 = zephir_fetch_nproperty_this(this_ptr, SL("_dependencyInjector"), PH_NOISY_CC);
		ZEPHIR_INIT_VAR(_3$$3);
		zephir_create_array(_3$$3, 7, 0 TSRMLS_CC);
		zephir_array_fast_append(_3$$3, name);
		zephir_array_fast_append(_3$$3, value);
		ZEPHIR_INIT_VAR(_4$$3);
		ZVAL_LONG(_4$$3, expire);
		zephir_array_fast_append(_3$$3, _4$$3);
		zephir_array_fast_append(_3$$3, path);
		ZEPHIR_INIT_NVAR(_4$$3);
		ZVAL_BOOL(_4$$3, secure);
		zephir_array_fast_append(_3$$3, _4$$3);
		zephir_array_fast_append(_3$$3, domain);
		ZEPHIR_INIT_NVAR(_4$$3);
		ZVAL_BOOL(_4$$3, httpOnly);
		zephir_array_fast_append(_3$$3, _4$$3);
		ZEPHIR_INIT_NVAR(_4$$3);
		ZVAL_STRING(_4$$3, "Phalcon\\Http\\Cookie", ZEPHIR_TEMP_PARAM_COPY);
		ZEPHIR_CALL_METHOD(&_2$$3, _1$$3, "get", NULL, 0, _4$$3, _3$$3);
		zephir_check_temp_parameter(_4$$3);
		zephir_check_call_status();
		ZEPHIR_CPY_WRT(cookie, _2$$3);
		_5$$3 = zephir_fetch_nproperty_this(this_ptr, SL("_dependencyInjector"), PH_NOISY_CC);
		ZEPHIR_CALL_METHOD(NULL, cookie, "setdi", NULL, 0, _5$$3);
		zephir_check_call_status();
		if (zephir_is_true(encryption)) {
			ZEPHIR_CALL_METHOD(NULL, cookie, "useencryption", NULL, 0, encryption);
			zephir_check_call_status();
		}
		zephir_update_property_array(this_ptr, SL("_cookies"), name, cookie TSRMLS_CC);
	} else {
		ZEPHIR_CALL_METHOD(NULL, cookie, "setvalue", NULL, 0, value);
		zephir_check_call_status();
		ZEPHIR_INIT_VAR(_6$$5);
		ZVAL_LONG(_6$$5, expire);
		ZEPHIR_CALL_METHOD(NULL, cookie, "setexpiration", NULL, 0, _6$$5);
		zephir_check_call_status();
		ZEPHIR_CALL_METHOD(NULL, cookie, "setpath", NULL, 0, path);
		zephir_check_call_status();
		ZEPHIR_INIT_NVAR(_6$$5);
		if (secure) {
			ZVAL_BOOL(_6$$5, 1);
		} else {
			ZVAL_BOOL(_6$$5, 0);
		}
		ZEPHIR_CALL_METHOD(NULL, cookie, "setsecure", NULL, 0, _6$$5);
		zephir_check_call_status();
		ZEPHIR_CALL_METHOD(NULL, cookie, "setdomain", NULL, 0, domain);
		zephir_check_call_status();
		ZEPHIR_INIT_VAR(_7$$5);
		if (httpOnly) {
			ZVAL_BOOL(_7$$5, 1);
		} else {
			ZVAL_BOOL(_7$$5, 0);
		}
		ZEPHIR_CALL_METHOD(NULL, cookie, "sethttponly", NULL, 0, _7$$5);
		zephir_check_call_status();
	}
	_8 = zephir_fetch_nproperty_this(this_ptr, SL("_registered"), PH_NOISY_CC);
	if (ZEPHIR_IS_FALSE_IDENTICAL(_8)) {
		ZEPHIR_OBS_VAR(dependencyInjector);
		zephir_read_property_this(&dependencyInjector, this_ptr, SL("_dependencyInjector"), PH_NOISY_CC);
		if (Z_TYPE_P(dependencyInjector) != IS_OBJECT) {
			ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_http_cookie_exception_ce, "A dependency injection object is required to access the 'response' service", "phalcon/http/response/cookies.zep", 130);
			return;
		}
		ZEPHIR_INIT_VAR(_9$$6);
		ZVAL_STRING(_9$$6, "response", ZEPHIR_TEMP_PARAM_COPY);
		ZEPHIR_CALL_METHOD(&response, dependencyInjector, "getshared", NULL, 0, _9$$6);
		zephir_check_temp_parameter(_9$$6);
		zephir_check_call_status();
		ZEPHIR_CALL_METHOD(NULL, response, "setcookies", NULL, 0, this_ptr);
		zephir_check_call_status();
		if (1) {
			zephir_update_property_this(this_ptr, SL("_registered"), ZEPHIR_GLOBAL(global_true) TSRMLS_CC);
		} else {
			zephir_update_property_this(this_ptr, SL("_registered"), ZEPHIR_GLOBAL(global_false) TSRMLS_CC);
		}
	}
	RETURN_THIS();

}
Example #27
0
/**
 * Encrypts a text
 *
 *<code>
 *	$encrypted = $crypt->encrypt("Ultra-secret text", "encrypt password");
 *</code>
 */
PHP_METHOD(Phalcon_Crypt, encrypt) {

	zend_bool _3, _4;
	int ZEPHIR_LAST_CALL_STATUS, _2$$9;
	zval *text_param = NULL, *key_param = NULL, *encryptKey = NULL, *ivSize = NULL, *iv = NULL, *cipher = NULL, *mode = NULL, *blockSize = NULL, *paddingType = NULL, *padded = NULL, _0, *_5 = NULL, *_1$$8 = NULL;
	zval *text = NULL, *key = NULL;

	ZEPHIR_MM_GROW();
	zephir_fetch_params(1, 1, 1, &text_param, &key_param);

	if (unlikely(Z_TYPE_P(text_param) != IS_STRING && Z_TYPE_P(text_param) != IS_NULL)) {
		zephir_throw_exception_string(spl_ce_InvalidArgumentException, SL("Parameter 'text' must be a string") TSRMLS_CC);
		RETURN_MM_NULL();
	}
	if (likely(Z_TYPE_P(text_param) == IS_STRING)) {
		zephir_get_strval(text, text_param);
	} else {
		ZEPHIR_INIT_VAR(text);
		ZVAL_EMPTY_STRING(text);
	}
	if (!key_param) {
		ZEPHIR_INIT_VAR(key);
		ZVAL_EMPTY_STRING(key);
	} else {
	if (unlikely(Z_TYPE_P(key_param) != IS_STRING && Z_TYPE_P(key_param) != IS_NULL)) {
		zephir_throw_exception_string(spl_ce_InvalidArgumentException, SL("Parameter 'key' must be a string") TSRMLS_CC);
		RETURN_MM_NULL();
	}
	if (likely(Z_TYPE_P(key_param) == IS_STRING)) {
		zephir_get_strval(key, key_param);
	} else {
		ZEPHIR_INIT_VAR(key);
		ZVAL_EMPTY_STRING(key);
	}
	}


	if (!((zephir_function_exists_ex(SS("mcrypt_get_iv_size") TSRMLS_CC) == SUCCESS))) {
		ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_crypt_exception_ce, "mcrypt extension is required", "phalcon/crypt.zep", 301);
		return;
	}
	if (ZEPHIR_IS_STRING_IDENTICAL(key, "")) {
		ZEPHIR_OBS_VAR(encryptKey);
		zephir_read_property_this(&encryptKey, this_ptr, SL("_key"), PH_NOISY_CC);
	} else {
		ZEPHIR_CPY_WRT(encryptKey, key);
	}
	if (ZEPHIR_IS_EMPTY(encryptKey)) {
		ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_crypt_exception_ce, "Encryption key cannot be empty", "phalcon/crypt.zep", 311);
		return;
	}
	ZEPHIR_OBS_VAR(cipher);
	zephir_read_property_this(&cipher, this_ptr, SL("_cipher"), PH_NOISY_CC);
	ZEPHIR_OBS_VAR(mode);
	zephir_read_property_this(&mode, this_ptr, SL("_mode"), PH_NOISY_CC);
	ZEPHIR_CALL_FUNCTION(&ivSize, "mcrypt_get_iv_size", NULL, 135, cipher, mode);
	zephir_check_call_status();
	if (ZEPHIR_LT_LONG(ivSize, zephir_fast_strlen_ev(encryptKey))) {
		ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_crypt_exception_ce, "Size of key is too large for this algorithm", "phalcon/crypt.zep", 319);
		return;
	}
	ZEPHIR_SINIT_VAR(_0);
	ZVAL_LONG(&_0, 2);
	ZEPHIR_CALL_FUNCTION(&iv, "mcrypt_create_iv", NULL, 136, ivSize, &_0);
	zephir_check_call_status();
	if (Z_TYPE_P(iv) != IS_STRING) {
		ZEPHIR_CALL_FUNCTION(&_1$$8, "strval", NULL, 21, iv);
		zephir_check_call_status();
		ZEPHIR_CPY_WRT(iv, _1$$8);
	}
	ZEPHIR_CALL_FUNCTION(&blockSize, "mcrypt_get_block_size", NULL, 137, cipher, mode);
	zephir_check_call_status();
	if (Z_TYPE_P(blockSize) != IS_LONG) {
		_2$$9 = zephir_get_intval(blockSize);
		ZEPHIR_INIT_NVAR(blockSize);
		ZVAL_LONG(blockSize, _2$$9);
	}
	ZEPHIR_OBS_VAR(paddingType);
	zephir_read_property_this(&paddingType, this_ptr, SL("_padding"), PH_NOISY_CC);
	_3 = !ZEPHIR_IS_LONG(paddingType, 0);
	if (_3) {
		_4 = ZEPHIR_IS_STRING(mode, "cbc");
		if (!(_4)) {
			_4 = ZEPHIR_IS_STRING(mode, "ecb");
		}
		_3 = _4;
	}
	if (_3) {
		ZEPHIR_CALL_METHOD(&padded, this_ptr, "_cryptpadtext", NULL, 0, text, mode, blockSize, paddingType);
		zephir_check_call_status();
	} else {
		ZEPHIR_CPY_WRT(padded, text);
	}
	ZEPHIR_CALL_FUNCTION(&_5, "mcrypt_encrypt", NULL, 138, cipher, encryptKey, padded, mode, iv);
	zephir_check_call_status();
	ZEPHIR_CONCAT_VV(return_value, iv, _5);
	RETURN_MM();

}
Example #28
0
/**
 * Extracts a slice from a string/array/traversable object value
 */
PHP_METHOD(Phalcon_Mvc_View_Engine_Volt, slice) {

	zend_bool _1$$5;
	zephir_fcall_cache_entry *_3 = NULL, *_4 = NULL, *_7 = NULL;
	int start, ZEPHIR_LAST_CALL_STATUS, position = 0;
	zval *value, *start_param = NULL, *end = NULL, *length = NULL, *slice = NULL, _10, *_0$$3 = NULL, *_2$$6 = NULL, _5$$9, _6$$11, _8$$10, _9$$12;

	ZEPHIR_MM_GROW();
	zephir_fetch_params(1, 1, 2, &value, &start_param, &end);

	if (!start_param) {
		start = 0;
	} else {
		start = zephir_get_intval(start_param);
	}
	if (!end) {
		ZEPHIR_CPY_WRT(end, ZEPHIR_GLOBAL(global_null));
	} else {
		ZEPHIR_SEPARATE_PARAM(end);
	}


	if (Z_TYPE_P(value) == IS_OBJECT) {
		if (Z_TYPE_P(end) == IS_NULL) {
			ZEPHIR_INIT_NVAR(end);
			ZVAL_LONG(end, (zephir_fast_count_int(value TSRMLS_CC) - 1));
		}
		position = 0;
		ZEPHIR_INIT_VAR(slice);
		array_init(slice);
		ZEPHIR_CALL_METHOD(NULL, value, "rewind", NULL, 0);
		zephir_check_call_status();
		while (1) {
			ZEPHIR_CALL_METHOD(&_0$$3, value, "valid", NULL, 0);
			zephir_check_call_status();
			if (!(zephir_is_true(_0$$3))) {
				break;
			}
			_1$$5 = position >= start;
			if (_1$$5) {
				_1$$5 = ZEPHIR_GE_LONG(end, position);
			}
			if (_1$$5) {
				ZEPHIR_CALL_METHOD(&_2$$6, value, "current", &_3, 0);
				zephir_check_call_status();
				zephir_array_append(&slice, _2$$6, PH_SEPARATE, "phalcon/mvc/view/engine/volt.zep", 223);
			}
			ZEPHIR_CALL_METHOD(NULL, value, "next", &_4, 0);
			zephir_check_call_status();
			position++;
		}
		RETURN_CCTOR(slice);
	}
	ZEPHIR_INIT_VAR(length);
	if (Z_TYPE_P(end) != IS_NULL) {
		ZVAL_LONG(length, (((zephir_get_numberval(end) - start)) + 1));
	} else {
		ZVAL_NULL(length);
	}
	if (Z_TYPE_P(value) == IS_ARRAY) {
		ZEPHIR_SINIT_VAR(_5$$9);
		ZVAL_LONG(&_5$$9, start);
		ZEPHIR_RETURN_CALL_FUNCTION("array_slice", NULL, 394, value, &_5$$9, length);
		zephir_check_call_status();
		RETURN_MM();
	}
	if ((zephir_function_exists_ex(SS("mb_substr") TSRMLS_CC) == SUCCESS)) {
		if (Z_TYPE_P(length) != IS_NULL) {
			ZEPHIR_SINIT_VAR(_6$$11);
			ZVAL_LONG(&_6$$11, start);
			ZEPHIR_RETURN_CALL_FUNCTION("mb_substr", &_7, 395, value, &_6$$11, length);
			zephir_check_call_status();
			RETURN_MM();
		}
		ZEPHIR_SINIT_VAR(_8$$10);
		ZVAL_LONG(&_8$$10, start);
		ZEPHIR_RETURN_CALL_FUNCTION("mb_substr", &_7, 395, value, &_8$$10);
		zephir_check_call_status();
		RETURN_MM();
	}
	if (Z_TYPE_P(length) != IS_NULL) {
		ZEPHIR_SINIT_VAR(_9$$12);
		ZVAL_LONG(&_9$$12, start);
		zephir_substr(return_value, value, zephir_get_intval(&_9$$12), zephir_get_intval(length), 0);
		RETURN_MM();
	}
	ZEPHIR_SINIT_VAR(_10);
	ZVAL_LONG(&_10, start);
	zephir_substr(return_value, value, zephir_get_intval(&_10), 0, ZEPHIR_SUBSTR_NO_LENGTH);
	RETURN_MM();

}
Example #29
0
/**
 * Writes the log to the stream itself
 */
PHP_METHOD(Phalcon_Logger_Adapter_Firephp, logInternal) {

	HashTable *_8;
	HashPosition _7;
	zephir_fcall_cache_entry *_2 = NULL;
	zval *context = NULL;
	int type, time, ZEPHIR_LAST_CALL_STATUS;
	zval *message_param = NULL, *type_param = NULL, *time_param = NULL, *context_param = NULL, *chunk = NULL, *format = NULL, *chString = NULL, *content = NULL, *key = NULL, *index = NULL, *_0, *_3 = NULL, *_4, *_5, _6, **_9, _1$$3 = zval_used_for_init;
	zval *message = NULL, *_10$$4 = NULL;

	ZEPHIR_MM_GROW();
	zephir_fetch_params(1, 4, 0, &message_param, &type_param, &time_param, &context_param);

	zephir_get_strval(message, message_param);
	type = zephir_get_intval(type_param);
	time = zephir_get_intval(time_param);
	zephir_get_arrval(context, context_param);


	_0 = zephir_fetch_nproperty_this(this_ptr, SL("_initialized"), PH_NOISY_CC);
	if (!(zephir_is_true(_0))) {
		ZEPHIR_SINIT_VAR(_1$$3);
		ZVAL_STRING(&_1$$3, "X-Wf-Protocol-1: http://meta.wildfirehq.org/Protocol/JsonStream/0.2", 0);
		ZEPHIR_CALL_FUNCTION(NULL, "header", &_2, 248, &_1$$3);
		zephir_check_call_status();
		ZEPHIR_SINIT_NVAR(_1$$3);
		ZVAL_STRING(&_1$$3, "X-Wf-1-Plugin-1: http://meta.firephp.org/Wildfire/Plugin/FirePHP/Library-FirePHPCore/0.3", 0);
		ZEPHIR_CALL_FUNCTION(NULL, "header", &_2, 248, &_1$$3);
		zephir_check_call_status();
		ZEPHIR_SINIT_NVAR(_1$$3);
		ZVAL_STRING(&_1$$3, "X-Wf-Structure-1: http://meta.firephp.org/Wildfire/Structure/FirePHP/FirebugConsole/0.1", 0);
		ZEPHIR_CALL_FUNCTION(NULL, "header", &_2, 248, &_1$$3);
		zephir_check_call_status();
		if (1) {
			zephir_update_property_this(this_ptr, SL("_initialized"), ZEPHIR_GLOBAL(global_true) TSRMLS_CC);
		} else {
			zephir_update_property_this(this_ptr, SL("_initialized"), ZEPHIR_GLOBAL(global_false) TSRMLS_CC);
		}
	}
	ZEPHIR_CALL_METHOD(&_3, this_ptr, "getformatter", NULL, 0);
	zephir_check_call_status();
	ZEPHIR_INIT_VAR(_4);
	ZVAL_LONG(_4, type);
	ZEPHIR_INIT_VAR(_5);
	ZVAL_LONG(_5, time);
	ZEPHIR_CALL_METHOD(&format, _3, "format", NULL, 0, message, _4, _5, context);
	zephir_check_call_status();
	ZEPHIR_SINIT_VAR(_6);
	ZVAL_LONG(&_6, 4500);
	ZEPHIR_CALL_FUNCTION(&chunk, "str_split", NULL, 74, format, &_6);
	zephir_check_call_status();
	ZEPHIR_OBS_VAR(index);
	zephir_read_property_this(&index, this_ptr, SL("_index"), PH_NOISY_CC);
	zephir_is_iterable(chunk, &_8, &_7, 0, 0, "phalcon/logger/adapter/firephp.zep", 92);
	for (
	  ; zephir_hash_get_current_data_ex(_8, (void**) &_9, &_7) == SUCCESS
	  ; zephir_hash_move_forward_ex(_8, &_7)
	) {
		ZEPHIR_GET_HMKEY(key, _8, _7);
		ZEPHIR_GET_HVALUE(chString, _9);
		zephir_get_strval(_10$$4, index);
		ZEPHIR_INIT_NVAR(content);
		ZEPHIR_CONCAT_SVSV(content, "X-Wf-1-1-1-", _10$$4, ": ", chString);
		if (zephir_array_isset_long(chunk, (zephir_get_numberval(key) + 1))) {
			zephir_concat_self_str(&content, SL("|\\") TSRMLS_CC);
		}
		ZEPHIR_CALL_FUNCTION(NULL, "header", &_2, 248, content);
		zephir_check_call_status();
		ZEPHIR_SEPARATE(index);
		zephir_increment(index);
	}
	zephir_update_property_this(this_ptr, SL("_index"), index TSRMLS_CC);
	ZEPHIR_MM_RESTORE();

}
Example #30
0
/**
 * @param array ids
 * @param bool concurrent Only for entities fetched in this query
 * @return \Ouchbase\Entity[]
 */
PHP_METHOD(Ouchbase_Repository, findAll) {

	zephir_fcall_cache_entry *_7 = NULL;
	HashTable *_3;
	HashPosition _2;
	int ZEPHIR_LAST_CALL_STATUS;
	zval *_0;
	zend_bool concurrent;
	zval *ids, *concurrent_param = NULL, *entity = NULL, *entities, *cas, *data, *dataWithCas = NULL, *id = NULL, *entityData = NULL, *_1 = NULL, **_4, *_5, *_6, *_8, *_9, *_10 = NULL;

	ZEPHIR_MM_GROW();
	zephir_fetch_params(1, 1, 1, &ids, &concurrent_param);

	if (!concurrent_param) {
		concurrent = 0;
	} else {
		concurrent = zephir_get_boolval(concurrent_param);
	}


	ZEPHIR_INIT_VAR(entities);
	array_init(entities);
	ZEPHIR_INIT_VAR(_0);
	array_init_size(_0, 2);
	zephir_array_fast_append(_0, ids);
	ZEPHIR_INIT_VAR(_1);
	ZVAL_STRING(_1, "__getMultiWithCas", 0);
	ZEPHIR_CALL_METHOD(&dataWithCas, this_ptr, "executewithouttimeouts", NULL, _1, _0);
	zephir_check_temp_parameter(_1);
	zephir_check_call_status();
	ZEPHIR_OBS_VAR(data);
	zephir_array_fetch_string(&data, dataWithCas, SL("data"), PH_NOISY TSRMLS_CC);
	ZEPHIR_OBS_VAR(cas);
	zephir_array_fetch_string(&cas, dataWithCas, SL("cas"), PH_NOISY TSRMLS_CC);
	zephir_is_iterable(data, &_3, &_2, 0, 0);
	for (
	  ; zephir_hash_get_current_data_ex(_3, (void**) &_4, &_2) == SUCCESS
	  ; zephir_hash_move_forward_ex(_3, &_2)
	) {
		ZEPHIR_GET_HMKEY(id, _3, _2);
		ZEPHIR_GET_HVALUE(entityData, _4);
		_5 = zephir_fetch_nproperty_this(this_ptr, SL("im"), PH_NOISY_CC);
		_6 = zephir_fetch_nproperty_this(this_ptr, SL("className"), PH_NOISY_CC);
		ZEPHIR_CALL_METHOD(&entity, _5, "getentity", NULL, _6, id);
		zephir_check_call_status();
		if (zephir_is_true(entity)) {
			zephir_array_append(&entities, entity, PH_SEPARATE);
			continue;
		}
		if (!(Z_TYPE_P(entityData) == IS_ARRAY)) {
			ZEPHIR_INIT_NVAR(_1);
			zephir_json_decode(_1, &(_1), entityData, zephir_get_intval(ZEPHIR_GLOBAL(global_true))  TSRMLS_CC);
			ZEPHIR_CPY_WRT(entityData, _1);
		}
		ZEPHIR_CALL_METHOD(&entity, this_ptr, "toobject", &_7, entityData);
		zephir_check_call_status();
		_8 = zephir_fetch_nproperty_this(this_ptr, SL("im"), PH_NOISY_CC);
		ZEPHIR_CALL_METHOD(NULL, _8, "register", NULL, entity, entityData);
		zephir_check_call_status();
		_9 = zephir_fetch_nproperty_this(this_ptr, SL("uow"), PH_NOISY_CC);
		ZEPHIR_INIT_LNVAR(_10);
		if (concurrent) {
			ZEPHIR_OBS_NVAR(_10);
			zephir_array_fetch(&_10, cas, id, PH_NOISY TSRMLS_CC);
		} else {
			ZEPHIR_INIT_NVAR(_10);
			ZVAL_NULL(_10);
		}
		ZEPHIR_CALL_METHOD(NULL, _9, "persist", NULL, entity, _10);
		zephir_check_call_status();
		zephir_array_append(&entities, entity, PH_SEPARATE);
	}
	RETURN_CCTOR(entities);

}