예제 #1
0
PHP_METHOD(OAuth_V1_Service, getAuthorizationUri) {

	zend_function *_6 = NULL;
	HashTable *_4;
	HashPosition _3;
	zend_class_entry *_1;
	zval *params = NULL, *uri, *endpoint, *key = NULL, *value = NULL, *_0, *_2, **_5;

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

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


	if (((Z_TYPE_P(params) != IS_ARRAY) && (Z_TYPE_P(params) != IS_NULL))) {
		ZEPHIR_INIT_VAR(_0);
		_1 = zend_fetch_class(SL("InvalidArgumentException"), ZEND_FETCH_CLASS_AUTO TSRMLS_CC);
		object_init_ex(_0, _1);
		ZEPHIR_INIT_VAR(_2);
		ZVAL_STRING(_2, "The params must be an Array", 1);
		zephir_call_method_p1_noret(_0, "__construct", _2);
		zephir_throw_exception(_0 TSRMLS_CC);
		ZEPHIR_MM_RESTORE();
		return;
	}
	ZEPHIR_INIT_VAR(endpoint);
	object_init_ex(endpoint, oauth_uri_ce);
	zephir_call_method_noret(endpoint, "__construct");
	ZEPHIR_INIT_VAR(uri);
	if (zephir_clone(uri, endpoint TSRMLS_CC) == FAILURE) {
		RETURN_MM();
	}
	if ((Z_TYPE_P(params) != IS_ARRAY)) {
		zephir_is_iterable(params, &_4, &_3, 0, 0);
		for (
			; zend_hash_get_current_data_ex(_4, (void**) &_5, &_3) == SUCCESS
			; zend_hash_move_forward_ex(_4, &_3)
		) {
			ZEPHIR_GET_HMKEY(key, _4, _3);
			ZEPHIR_GET_HVALUE(value, _5);
			zephir_call_method_p2_cache_noret(uri, "addtoquery", &_6, key, value);
		}
	}
	RETURN_CCTOR(uri);

}
예제 #2
0
/**
 * Sets a Expires header to use HTTP cache
 *
 *<code>
 *	$this->response->setExpires(new DateTime());
 *</code>
 */
PHP_METHOD(Phalcon_Http_Response, setExpires) {

	int ZEPHIR_LAST_CALL_STATUS;
	zval *datetime, *date, *_0, *_1 = NULL, *_2 = NULL, *_3;

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



	ZEPHIR_INIT_VAR(date);
	if (zephir_clone(date, datetime TSRMLS_CC) == FAILURE) {
		RETURN_MM();
	}
	ZEPHIR_INIT_VAR(_0);
	object_init_ex(_0, php_date_get_timezone_ce());
	ZEPHIR_INIT_VAR(_1);
	ZVAL_STRING(_1, "UTC", ZEPHIR_TEMP_PARAM_COPY);
	ZEPHIR_CALL_METHOD(NULL, _0, "__construct", NULL, 0, _1);
	zephir_check_temp_parameter(_1);
	zephir_check_call_status();
	ZEPHIR_CALL_METHOD(NULL, date, "settimezone", NULL, 0, _0);
	zephir_check_call_status();
	ZEPHIR_INIT_NVAR(_1);
	ZVAL_STRING(_1, "D, d M Y H:i:s", ZEPHIR_TEMP_PARAM_COPY);
	ZEPHIR_CALL_METHOD(&_2, date, "format", NULL, 0, _1);
	zephir_check_temp_parameter(_1);
	zephir_check_call_status();
	ZEPHIR_INIT_VAR(_3);
	ZEPHIR_CONCAT_VS(_3, _2, " GMT");
	ZEPHIR_INIT_NVAR(_1);
	ZVAL_STRING(_1, "Expires", ZEPHIR_TEMP_PARAM_COPY);
	ZEPHIR_CALL_METHOD(NULL, this_ptr, "setheader", NULL, 0, _1, _3);
	zephir_check_temp_parameter(_1);
	zephir_check_call_status();
	RETURN_THIS();

}
예제 #3
0
/**
 * Listens for notifications from the models manager
 */
PHP_METHOD(Phalcon_Mvc_Collection_Behavior_SoftDelete, notify) {

	HashTable *_5$$7;
	HashPosition _4$$7;
	zephir_fcall_cache_entry *_7 = NULL;
	int ZEPHIR_LAST_CALL_STATUS;
	zval *type_param = NULL, *model, *options = NULL, *value = NULL, *field = NULL, *updateModel = NULL, *message = NULL, *_0$$3, *_1$$3 = NULL, *_2$$6 = NULL, *_3$$7 = NULL, **_6$$7;
	zval *type = NULL;

	ZEPHIR_MM_GROW();
	zephir_fetch_params(1, 2, 0, &type_param, &model);

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


	if (ZEPHIR_IS_STRING(type, "beforeDelete")) {
		ZEPHIR_CALL_METHOD(&options, this_ptr, "getoptions", NULL, 0);
		zephir_check_call_status();
		ZEPHIR_OBS_VAR(value);
		if (!(zephir_array_isset_string_fetch(&value, options, SS("value"), 0 TSRMLS_CC))) {
			ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_mvc_collection_exception_ce, "The option 'value' is required", "phalcon/mvc/collection/behavior/softdelete.zep", 51);
			return;
		}
		ZEPHIR_OBS_VAR(field);
		if (!(zephir_array_isset_string_fetch(&field, options, SS("field"), 0 TSRMLS_CC))) {
			ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_mvc_collection_exception_ce, "The option 'field' is required", "phalcon/mvc/collection/behavior/softdelete.zep", 58);
			return;
		}
		ZEPHIR_INIT_VAR(_0$$3);
		ZVAL_BOOL(_0$$3, 1);
		ZEPHIR_CALL_METHOD(NULL, model, "skipoperation", NULL, 0, _0$$3);
		zephir_check_call_status();
		ZEPHIR_CALL_METHOD(&_1$$3, model, "readattribute", NULL, 0, field);
		zephir_check_call_status();
		if (!ZEPHIR_IS_EQUAL(_1$$3, value)) {
			ZEPHIR_INIT_VAR(updateModel);
			if (zephir_clone(updateModel, model TSRMLS_CC) == FAILURE) {
				RETURN_MM();
			}
			ZEPHIR_CALL_METHOD(NULL, updateModel, "writeattribute", NULL, 0, field, value);
			zephir_check_call_status();
			ZEPHIR_CALL_METHOD(&_2$$6, updateModel, "save", NULL, 0);
			zephir_check_call_status();
			if (!(zephir_is_true(_2$$6))) {
				ZEPHIR_CALL_METHOD(&_3$$7, updateModel, "getmessages", NULL, 0);
				zephir_check_call_status();
				zephir_is_iterable(_3$$7, &_5$$7, &_4$$7, 0, 0, "phalcon/mvc/collection/behavior/softdelete.zep", 90);
				for (
				  ; zephir_hash_get_current_data_ex(_5$$7, (void**) &_6$$7, &_4$$7) == SUCCESS
				  ; zephir_hash_move_forward_ex(_5$$7, &_4$$7)
				) {
					ZEPHIR_GET_HVALUE(message, _6$$7);
					ZEPHIR_CALL_METHOD(NULL, model, "appendmessage", &_7, 0, message);
					zephir_check_call_status();
				}
				RETURN_MM_BOOL(0);
			}
			ZEPHIR_CALL_METHOD(NULL, model, "writeattribute", NULL, 0, field, value);
			zephir_check_call_status();
		}
	}
	ZEPHIR_MM_RESTORE();

}
예제 #4
0
/**
 * Returns a slice of the resultset to show in the pagination
 */
PHP_METHOD(Phalcon_Paginator_Adapter_QueryBuilder, getPaginate) {

	zval *_6$$14, *_8$$15;
	zend_bool hasHaving = 0, hasGroup = 0, _2;
	zval *originalBuilder = NULL, *builder = NULL, *totalBuilder = NULL, *totalPages = NULL, *limit = NULL, *number = NULL, *query = NULL, *page = NULL, *items = NULL, *totalQuery = NULL, *result = NULL, *row = NULL, *rowcount = NULL, *next = NULL, *sql = NULL, *columns = NULL, *db = NULL, *_0, *_1 = NULL, *groups = NULL, *_10, *_22, *_3$$10, *groupColumn$$11 = NULL, *_4$$14 = NULL, *_5$$14, *_7$$14, *_9$$15, *_11$$16 = NULL, *_12$$16 = NULL, *_13$$16, *_14$$16, *_15$$16, *_16$$16, _17$$16, _18$$16, *_19$$17, _20$$17, _21$$17;
	zend_long ZEPHIR_LAST_CALL_STATUS, numberPage = 0, before = 0;

	ZEPHIR_MM_GROW();

	ZEPHIR_OBS_VAR(originalBuilder);
	zephir_read_property_this(&originalBuilder, this_ptr, SL("_builder"), PH_NOISY_CC);
	ZEPHIR_OBS_VAR(columns);
	zephir_read_property_this(&columns, this_ptr, SL("_columns"), PH_NOISY_CC);
	ZEPHIR_INIT_VAR(builder);
	if (zephir_clone(builder, originalBuilder TSRMLS_CC) == FAILURE) {
		RETURN_MM();
	}
	ZEPHIR_INIT_VAR(totalBuilder);
	if (zephir_clone(totalBuilder, builder TSRMLS_CC) == FAILURE) {
		RETURN_MM();
	}
	ZEPHIR_OBS_VAR(limit);
	zephir_read_property_this(&limit, this_ptr, SL("_limitRows"), PH_NOISY_CC);
	ZEPHIR_OBS_VAR(_0);
	zephir_read_property_this(&_0, this_ptr, SL("_page"), PH_NOISY_CC);
	numberPage = zephir_get_intval(_0);
	if (!(numberPage)) {
		numberPage = 1;
	}
	ZEPHIR_INIT_VAR(number);
	ZVAL_LONG(number, (zephir_get_numberval(limit) * ((numberPage - 1))));
	if (ZEPHIR_LT(number, limit)) {
		ZEPHIR_CALL_METHOD(NULL, builder, "limit", NULL, 0, limit);
		zephir_check_call_status();
	} else {
		ZEPHIR_CALL_METHOD(NULL, builder, "limit", NULL, 0, limit, number);
		zephir_check_call_status();
	}
	ZEPHIR_CALL_METHOD(&query, builder, "getquery", NULL, 0);
	zephir_check_call_status();
	if (numberPage == 1) {
		before = 1;
	} else {
		before = (numberPage - 1);
	}
	ZEPHIR_CALL_METHOD(&items, query, "execute", NULL, 0);
	zephir_check_call_status();
	ZEPHIR_CALL_METHOD(&_1, totalBuilder, "gethaving", NULL, 0);
	zephir_check_call_status();
	hasHaving = !(ZEPHIR_IS_EMPTY(_1));
	ZEPHIR_CALL_METHOD(&groups, totalBuilder, "getgroupby", NULL, 0);
	zephir_check_call_status();
	hasGroup = !(ZEPHIR_IS_EMPTY(groups));
	_2 = hasHaving;
	if (_2) {
		_2 = !hasGroup;
	}
	if (_2) {
		if (ZEPHIR_IS_EMPTY(columns)) {
			ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_paginator_exception_ce, "When having is set there should be columns option provided for which calculate row count", "phalcon/paginator/adapter/querybuilder.zep", 186);
			return;
		}
		ZEPHIR_CALL_METHOD(NULL, totalBuilder, "columns", NULL, 0, columns);
		zephir_check_call_status();
	} else {
		ZEPHIR_INIT_VAR(_3$$10);
		ZVAL_STRING(_3$$10, "COUNT(*) [rowcount]", ZEPHIR_TEMP_PARAM_COPY);
		ZEPHIR_CALL_METHOD(NULL, totalBuilder, "columns", NULL, 0, _3$$10);
		zephir_check_temp_parameter(_3$$10);
		zephir_check_call_status();
	}
	if (hasGroup) {
		if (Z_TYPE_P(groups) == IS_ARRAY) {
			ZEPHIR_INIT_VAR(groupColumn$$11);
			zephir_fast_join_str(groupColumn$$11, SL(", "), groups TSRMLS_CC);
		} else {
			ZEPHIR_CPY_WRT(groupColumn$$11, groups);
		}
		if (!(hasHaving)) {
			ZEPHIR_INIT_VAR(_5$$14);
			ZVAL_NULL(_5$$14);
			ZEPHIR_CALL_METHOD(&_4$$14, totalBuilder, "groupby", NULL, 0, _5$$14);
			zephir_check_call_status();
			ZEPHIR_INIT_VAR(_6$$14);
			zephir_create_array(_6$$14, 1, 0 TSRMLS_CC);
			ZEPHIR_INIT_VAR(_7$$14);
			ZEPHIR_CONCAT_SVS(_7$$14, "COUNT(DISTINCT ", groupColumn$$11, ") AS rowcount");
			zephir_array_fast_append(_6$$14, _7$$14);
			ZEPHIR_CALL_METHOD(NULL, _4$$14, "columns", NULL, 0, _6$$14);
			zephir_check_call_status();
		} else {
			ZEPHIR_INIT_VAR(_8$$15);
			zephir_create_array(_8$$15, 1, 0 TSRMLS_CC);
			ZEPHIR_INIT_VAR(_9$$15);
			ZEPHIR_CONCAT_SV(_9$$15, "DISTINCT ", groupColumn$$11);
			zephir_array_fast_append(_8$$15, _9$$15);
			ZEPHIR_CALL_METHOD(NULL, totalBuilder, "columns", NULL, 0, _8$$15);
			zephir_check_call_status();
		}
	}
	ZEPHIR_INIT_VAR(_10);
	ZVAL_NULL(_10);
	ZEPHIR_CALL_METHOD(NULL, totalBuilder, "orderby", NULL, 0, _10);
	zephir_check_call_status();
	ZEPHIR_CALL_METHOD(&totalQuery, totalBuilder, "getquery", NULL, 0);
	zephir_check_call_status();
	ZEPHIR_INIT_VAR(rowcount);
	if (hasHaving) {
		ZEPHIR_CALL_METHOD(&sql, totalQuery, "getsql", NULL, 0);
		zephir_check_call_status();
		ZEPHIR_CALL_METHOD(&_11$$16, totalBuilder, "getdi", NULL, 0);
		zephir_check_call_status();
		ZEPHIR_INIT_VAR(_12$$16);
		ZVAL_STRING(_12$$16, "db", ZEPHIR_TEMP_PARAM_COPY);
		ZEPHIR_CALL_METHOD(&db, _11$$16, "get", NULL, 0, _12$$16);
		zephir_check_temp_parameter(_12$$16);
		zephir_check_call_status();
		zephir_array_fetch_string(&_13$$16, sql, SL("sql"), PH_NOISY | PH_READONLY, "phalcon/paginator/adapter/querybuilder.zep", 228 TSRMLS_CC);
		ZEPHIR_INIT_VAR(_14$$16);
		ZEPHIR_CONCAT_SVS(_14$$16, "SELECT COUNT(*) as rowcount FROM (", _13$$16, ") as T1");
		zephir_array_fetch_string(&_15$$16, sql, SL("bind"), PH_NOISY | PH_READONLY, "phalcon/paginator/adapter/querybuilder.zep", 228 TSRMLS_CC);
		ZEPHIR_INIT_NVAR(_12$$16);
		ZVAL_LONG(_12$$16, 2);
		ZEPHIR_CALL_METHOD(&row, db, "fetchone", NULL, 0, _14$$16, _12$$16, _15$$16);
		zephir_check_call_status();
		if (zephir_is_true(row)) {
			zephir_array_fetch_string(&_16$$16, row, SL("rowcount"), PH_NOISY | PH_READONLY, "phalcon/paginator/adapter/querybuilder.zep", 229 TSRMLS_CC);
			ZVAL_LONG(rowcount, zephir_get_intval(_16$$16));
		} else {
			ZVAL_LONG(rowcount, 0);
		}
		ZEPHIR_SINIT_VAR(_17$$16);
		div_function(&_17$$16, rowcount, limit TSRMLS_CC);
		ZEPHIR_SINIT_VAR(_18$$16);
		ZVAL_DOUBLE(&_18$$16, zephir_ceil(&_17$$16 TSRMLS_CC));
		ZEPHIR_INIT_VAR(totalPages);
		ZVAL_LONG(totalPages, zephir_get_intval(&_18$$16));
	} else {
		ZEPHIR_CALL_METHOD(&result, totalQuery, "execute", NULL, 0);
		zephir_check_call_status();
		ZEPHIR_CALL_METHOD(&row, result, "getfirst", NULL, 0);
		zephir_check_call_status();
		if (zephir_is_true(row)) {
			ZEPHIR_OBS_VAR(_19$$17);
			zephir_read_property(&_19$$17, row, SL("rowcount"), PH_NOISY_CC);
			ZEPHIR_INIT_NVAR(rowcount);
			ZVAL_LONG(rowcount, zephir_get_intval(_19$$17));
		} else {
			ZEPHIR_INIT_NVAR(rowcount);
			ZVAL_LONG(rowcount, 0);
		}
		ZEPHIR_SINIT_VAR(_20$$17);
		div_function(&_20$$17, rowcount, limit TSRMLS_CC);
		ZEPHIR_SINIT_VAR(_21$$17);
		ZVAL_DOUBLE(&_21$$17, zephir_ceil(&_20$$17 TSRMLS_CC));
		ZEPHIR_INIT_NVAR(totalPages);
		ZVAL_LONG(totalPages, zephir_get_intval(&_21$$17));
	}
	if (ZEPHIR_GT_LONG(totalPages, numberPage)) {
		ZEPHIR_INIT_VAR(next);
		ZVAL_LONG(next, (numberPage + 1));
	} else {
		ZEPHIR_CPY_WRT(next, totalPages);
	}
	ZEPHIR_INIT_VAR(page);
	object_init(page);
	zephir_update_property_zval(page, SL("items"), items TSRMLS_CC);
	ZEPHIR_INIT_ZVAL_NREF(_22);
	ZVAL_LONG(_22, 1);
	zephir_update_property_zval(page, SL("first"), _22 TSRMLS_CC);
	ZEPHIR_INIT_ZVAL_NREF(_22);
	ZVAL_LONG(_22, before);
	zephir_update_property_zval(page, SL("before"), _22 TSRMLS_CC);
	ZEPHIR_INIT_ZVAL_NREF(_22);
	ZVAL_LONG(_22, numberPage);
	zephir_update_property_zval(page, SL("current"), _22 TSRMLS_CC);
	zephir_update_property_zval(page, SL("last"), totalPages TSRMLS_CC);
	zephir_update_property_zval(page, SL("next"), next TSRMLS_CC);
	zephir_update_property_zval(page, SL("total_pages"), totalPages TSRMLS_CC);
	zephir_update_property_zval(page, SL("total_items"), rowcount TSRMLS_CC);
	_22 = zephir_fetch_nproperty_this(this_ptr, SL("_limitRows"), PH_NOISY_CC);
	zephir_update_property_zval(page, SL("limit"), _22 TSRMLS_CC);
	RETURN_CCTOR(page);

}
예제 #5
0
/**
 * Listens for notifications from the models manager
 */
PHP_METHOD(Phalcon_Mvc_Model_Behavior_SoftDelete, notify) {

	HashTable *_5$$7;
	HashPosition _4$$7;
	zend_bool _9$$6;
	zephir_fcall_cache_entry *_7 = NULL;
	zend_long ZEPHIR_LAST_CALL_STATUS;
	zval *type_param = NULL, *model, *options = NULL, *value = NULL, *field = NULL, *updateModel = NULL, *message = NULL, *modelsManager = NULL, *metaData = NULL, *columnMap = NULL, *_0$$3, *_1$$3 = NULL, *_2$$6 = NULL, *_8$$6 = NULL, *_3$$7 = NULL, **_6$$7, *_10$$9 = NULL, *_11$$9 = NULL;
	zval *type = NULL;

	ZEPHIR_MM_GROW();
	zephir_fetch_params(1, 2, 0, &type_param, &model);

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


	if (ZEPHIR_IS_STRING(type, "beforeDelete")) {
		ZEPHIR_CALL_METHOD(&options, this_ptr, "getoptions", NULL, 0);
		zephir_check_call_status();
		ZEPHIR_OBS_VAR(value);
		if (!(zephir_array_isset_string_fetch(&value, options, SS("value"), 0 TSRMLS_CC))) {
			ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_mvc_model_exception_ce, "The option 'value' is required", "phalcon/mvc/model/behavior/softdelete.zep", 50);
			return;
		}
		ZEPHIR_OBS_VAR(field);
		if (!(zephir_array_isset_string_fetch(&field, options, SS("field"), 0 TSRMLS_CC))) {
			ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_mvc_model_exception_ce, "The option 'field' is required", "phalcon/mvc/model/behavior/softdelete.zep", 57);
			return;
		}
		ZEPHIR_INIT_VAR(_0$$3);
		ZVAL_BOOL(_0$$3, 1);
		ZEPHIR_CALL_METHOD(NULL, model, "skipoperation", NULL, 0, _0$$3);
		zephir_check_call_status();
		ZEPHIR_CALL_METHOD(&_1$$3, model, "readattribute", NULL, 0, field);
		zephir_check_call_status();
		if (!ZEPHIR_IS_EQUAL(_1$$3, value)) {
			ZEPHIR_CALL_METHOD(&modelsManager, model, "getmodelsmanager", NULL, 0);
			zephir_check_call_status();
			ZEPHIR_INIT_VAR(updateModel);
			if (zephir_clone(updateModel, model TSRMLS_CC) == FAILURE) {
				RETURN_MM();
			}
			ZEPHIR_CALL_METHOD(NULL, updateModel, "writeattribute", NULL, 0, field, value);
			zephir_check_call_status();
			ZEPHIR_CALL_METHOD(&_2$$6, updateModel, "save", NULL, 0);
			zephir_check_call_status();
			if (!(zephir_is_true(_2$$6))) {
				ZEPHIR_CALL_METHOD(&_3$$7, updateModel, "getmessages", NULL, 0);
				zephir_check_call_status();
				zephir_is_iterable(_3$$7, &_5$$7, &_4$$7, 0, 0, "phalcon/mvc/model/behavior/softdelete.zep", 91);
				for (
				  ; zend_hash_get_current_data_ex(_5$$7, (void**) &_6$$7, &_4$$7) == SUCCESS
				  ; zend_hash_move_forward_ex(_5$$7, &_4$$7)
				) {
					ZEPHIR_GET_HVALUE(message, _6$$7);
					ZEPHIR_CALL_METHOD(NULL, model, "appendmessage", &_7, 0, message);
					zephir_check_call_status();
				}
				RETURN_MM_BOOL(0);
			}
			ZEPHIR_CALL_METHOD(NULL, model, "writeattribute", NULL, 0, field, value);
			zephir_check_call_status();
			ZEPHIR_CALL_METHOD(&_8$$6, modelsManager, "iskeepingsnapshots", NULL, 0, model);
			zephir_check_call_status();
			_9$$6 = zephir_is_true(_8$$6);
			if (_9$$6) {
				_9$$6 = ZEPHIR_GLOBAL(orm).update_snapshot_on_save;
			}
			if (_9$$6) {
				ZEPHIR_CALL_METHOD(&metaData, model, "getmodelsmetadata", NULL, 0);
				zephir_check_call_status();
				ZEPHIR_CALL_METHOD(&columnMap, metaData, "getcolumnmap", NULL, 0, model);
				zephir_check_call_status();
				ZEPHIR_CALL_METHOD(&_10$$9, updateModel, "getsnapshotdata", NULL, 0);
				zephir_check_call_status();
				ZEPHIR_CALL_METHOD(NULL, model, "setsnapshotdata", NULL, 0, _10$$9, columnMap);
				zephir_check_call_status();
				ZEPHIR_CALL_METHOD(&_11$$9, updateModel, "getoldsnapshotdata", NULL, 0);
				zephir_check_call_status();
				ZEPHIR_CALL_METHOD(NULL, model, "setoldsnapshotdata", NULL, 0, _11$$9, columnMap);
				zephir_check_call_status();
			}
		}
	}
	ZEPHIR_MM_RESTORE();

}
예제 #6
0
/**
 * Internal handler to call a queue of events
 *
 * @param \SplPriorityQueue|array queue
 * @param \Phalcon\Events\Event event
 * @return mixed
 */
PHP_METHOD(Phalcon_Events_Manager, fireQueue) {

	HashTable *_12$$21;
	HashPosition _11$$21;
	zend_bool collect = 0, cancelable = 0;
	zephir_fcall_cache_entry *_7 = NULL, *_8 = NULL;
	int ZEPHIR_LAST_CALL_STATUS;
	zval *queue, *event, *status = NULL, *arguments = NULL, *eventName = NULL, *data = NULL, *iterator = NULL, *source = NULL, *handler = NULL, *_4 = NULL, *_5, *_0$$5, *_1$$5, _2$$5, *_3$$5 = NULL, *_6$$8 = NULL, *_9$$14 = NULL, *_10$$19 = NULL, **_13$$21, *_14$$27 = NULL, *_15$$32 = NULL;

	ZEPHIR_MM_GROW();
	zephir_fetch_params(1, 2, 0, &queue, &event);



	if (Z_TYPE_P(queue) != IS_ARRAY) {
		if (Z_TYPE_P(queue) == IS_OBJECT) {
			if (!(zephir_instance_of_ev(queue, spl_ce_SplPriorityQueue TSRMLS_CC))) {
				ZEPHIR_INIT_VAR(_0$$5);
				object_init_ex(_0$$5, phalcon_events_exception_ce);
				ZEPHIR_INIT_VAR(_1$$5);
				zephir_get_class(_1$$5, queue, 0 TSRMLS_CC);
				ZEPHIR_SINIT_VAR(_2$$5);
				ZVAL_STRING(&_2$$5, "Unexpected value type: expected object of type SplPriorityQueue, %s given", 0);
				ZEPHIR_CALL_FUNCTION(&_3$$5, "sprintf", NULL, 193, &_2$$5, _1$$5);
				zephir_check_call_status();
				ZEPHIR_CALL_METHOD(NULL, _0$$5, "__construct", NULL, 9, _3$$5);
				zephir_check_call_status();
				zephir_throw_exception_debug(_0$$5, "phalcon/events/manager.zep", 205 TSRMLS_CC);
				ZEPHIR_MM_RESTORE();
				return;
			}
		} else {
			ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_events_exception_ce, "The queue is not valid", "phalcon/events/manager.zep", 208);
			return;
		}
	}
	ZEPHIR_INIT_VAR(status);
	ZVAL_NULL(status);
	ZEPHIR_INIT_VAR(arguments);
	ZVAL_NULL(arguments);
	ZEPHIR_CALL_METHOD(&eventName, event, "gettype", NULL, 0);
	zephir_check_call_status();
	if (Z_TYPE_P(eventName) != IS_STRING) {
		ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_events_exception_ce, "The event type not valid", "phalcon/events/manager.zep", 217);
		return;
	}
	ZEPHIR_CALL_METHOD(&source, event, "getsource", NULL, 0);
	zephir_check_call_status();
	ZEPHIR_CALL_METHOD(&data, event, "getdata", NULL, 0);
	zephir_check_call_status();
	ZEPHIR_CALL_METHOD(&_4, event, "iscancelable", NULL, 0);
	zephir_check_call_status();
	cancelable = zephir_get_boolval(_4);
	ZEPHIR_OBS_VAR(_5);
	zephir_read_property_this(&_5, this_ptr, SL("_collect"), PH_NOISY_CC);
	collect = zephir_get_boolval(_5);
	if (Z_TYPE_P(queue) == IS_OBJECT) {
		ZEPHIR_INIT_VAR(iterator);
		if (zephir_clone(iterator, queue TSRMLS_CC) == FAILURE) {
			RETURN_MM();
		}
		ZEPHIR_CALL_METHOD(NULL, iterator, "top", NULL, 0);
		zephir_check_call_status();
		while (1) {
			ZEPHIR_CALL_METHOD(&_6$$8, iterator, "valid", NULL, 0);
			zephir_check_call_status();
			if (!(zephir_is_true(_6$$8))) {
				break;
			}
			ZEPHIR_CALL_METHOD(&handler, iterator, "current", &_7, 0);
			zephir_check_call_status();
			ZEPHIR_CALL_METHOD(NULL, iterator, "next", &_8, 0);
			zephir_check_call_status();
			if (Z_TYPE_P(handler) == IS_OBJECT) {
				if (zephir_instance_of_ev(handler, zend_ce_closure TSRMLS_CC)) {
					if (Z_TYPE_P(arguments) == IS_NULL) {
						ZEPHIR_INIT_NVAR(arguments);
						zephir_create_array(arguments, 3, 0 TSRMLS_CC);
						zephir_array_fast_append(arguments, event);
						zephir_array_fast_append(arguments, source);
						zephir_array_fast_append(arguments, data);
					}
					ZEPHIR_INIT_NVAR(status);
					ZEPHIR_CALL_USER_FUNC_ARRAY(status, handler, arguments);
					zephir_check_call_status();
					if (collect) {
						zephir_update_property_array_append(this_ptr, SL("_responses"), status TSRMLS_CC);
					}
					if (cancelable) {
						ZEPHIR_CALL_METHOD(&_9$$14, event, "isstopped", NULL, 0);
						zephir_check_call_status();
						if (zephir_is_true(_9$$14)) {
							break;
						}
					}
				} else {
					if ((zephir_method_exists(handler, eventName TSRMLS_CC)  == SUCCESS)) {
						ZEPHIR_CALL_METHOD_ZVAL(&status, handler, eventName, NULL, 0, event, source, data);
						zephir_check_call_status();
						if (collect) {
							zephir_update_property_array_append(this_ptr, SL("_responses"), status TSRMLS_CC);
						}
						if (cancelable) {
							ZEPHIR_CALL_METHOD(&_10$$19, event, "isstopped", NULL, 0);
							zephir_check_call_status();
							if (zephir_is_true(_10$$19)) {
								break;
							}
						}
					}
				}
			}
		}
	} else {
		zephir_is_iterable(queue, &_12$$21, &_11$$21, 0, 0, "phalcon/events/manager.zep", 353);
		for (
		  ; zephir_hash_get_current_data_ex(_12$$21, (void**) &_13$$21, &_11$$21) == SUCCESS
		  ; zephir_hash_move_forward_ex(_12$$21, &_11$$21)
		) {
			ZEPHIR_GET_HVALUE(handler, _13$$21);
			if (Z_TYPE_P(handler) == IS_OBJECT) {
				if (zephir_instance_of_ev(handler, zend_ce_closure TSRMLS_CC)) {
					if (Z_TYPE_P(arguments) == IS_NULL) {
						ZEPHIR_INIT_NVAR(arguments);
						zephir_create_array(arguments, 3, 0 TSRMLS_CC);
						zephir_array_fast_append(arguments, event);
						zephir_array_fast_append(arguments, source);
						zephir_array_fast_append(arguments, data);
					}
					ZEPHIR_INIT_NVAR(status);
					ZEPHIR_CALL_USER_FUNC_ARRAY(status, handler, arguments);
					zephir_check_call_status();
					if (collect) {
						zephir_update_property_array_append(this_ptr, SL("_responses"), status TSRMLS_CC);
					}
					if (cancelable) {
						ZEPHIR_CALL_METHOD(&_14$$27, event, "isstopped", NULL, 0);
						zephir_check_call_status();
						if (zephir_is_true(_14$$27)) {
							break;
						}
					}
				} else {
					if ((zephir_method_exists(handler, eventName TSRMLS_CC)  == SUCCESS)) {
						ZEPHIR_CALL_METHOD_ZVAL(&status, handler, eventName, NULL, 0, event, source, data);
						zephir_check_call_status();
						if (collect) {
							zephir_update_property_array_append(this_ptr, SL("_responses"), status TSRMLS_CC);
						}
						if (cancelable) {
							ZEPHIR_CALL_METHOD(&_15$$32, event, "isstopped", NULL, 0);
							zephir_check_call_status();
							if (zephir_is_true(_15$$32)) {
								break;
							}
						}
					}
				}
			}
		}
	}
	RETURN_CCTOR(status);

}
예제 #7
0
/**
 * Returns a slice of the resultset to show in the pagination
 */
PHP_METHOD(Phalcon_Paginator_Adapter_QueryBuilder, getPaginate) {

	zval *_4$$8;
	zval *originalBuilder = NULL, *builder = NULL, *totalBuilder = NULL, *totalPages = NULL, *limit = NULL, *number = NULL, *query = NULL, *page = NULL, *items = NULL, *totalQuery = NULL, *result = NULL, *row = NULL, *rowcount = NULL, *next = NULL, *_0, *_1 = NULL, *groups = NULL, *_6, _7, _8, *_9, *groupColumn$$8 = NULL, *_2$$8 = NULL, *_3$$8, *_5$$8;
	int ZEPHIR_LAST_CALL_STATUS, numberPage = 0, before = 0;

	ZEPHIR_MM_GROW();

	ZEPHIR_OBS_VAR(originalBuilder);
	zephir_read_property_this(&originalBuilder, this_ptr, SL("_builder"), PH_NOISY_CC);
	ZEPHIR_INIT_VAR(builder);
	if (zephir_clone(builder, originalBuilder TSRMLS_CC) == FAILURE) {
		RETURN_MM();
	}
	ZEPHIR_INIT_VAR(totalBuilder);
	if (zephir_clone(totalBuilder, builder TSRMLS_CC) == FAILURE) {
		RETURN_MM();
	}
	ZEPHIR_OBS_VAR(limit);
	zephir_read_property_this(&limit, this_ptr, SL("_limitRows"), PH_NOISY_CC);
	ZEPHIR_OBS_VAR(_0);
	zephir_read_property_this(&_0, this_ptr, SL("_page"), PH_NOISY_CC);
	numberPage = zephir_get_intval(_0);
	if (!(numberPage)) {
		numberPage = 1;
	}
	ZEPHIR_INIT_VAR(number);
	ZVAL_LONG(number, (zephir_get_numberval(limit) * ((numberPage - 1))));
	if (ZEPHIR_LT(number, limit)) {
		ZEPHIR_CALL_METHOD(NULL, builder, "limit", NULL, 0, limit);
		zephir_check_call_status();
	} else {
		ZEPHIR_CALL_METHOD(NULL, builder, "limit", NULL, 0, limit, number);
		zephir_check_call_status();
	}
	ZEPHIR_CALL_METHOD(&query, builder, "getquery", NULL, 0);
	zephir_check_call_status();
	if (numberPage == 1) {
		before = 1;
	} else {
		before = (numberPage - 1);
	}
	ZEPHIR_CALL_METHOD(&items, query, "execute", NULL, 0);
	zephir_check_call_status();
	ZEPHIR_INIT_VAR(_1);
	ZVAL_STRING(_1, "COUNT(*) [rowcount]", ZEPHIR_TEMP_PARAM_COPY);
	ZEPHIR_CALL_METHOD(NULL, totalBuilder, "columns", NULL, 0, _1);
	zephir_check_temp_parameter(_1);
	zephir_check_call_status();
	ZEPHIR_CALL_METHOD(&groups, totalBuilder, "getgroupby", NULL, 0);
	zephir_check_call_status();
	if (!(ZEPHIR_IS_EMPTY(groups))) {
		if (Z_TYPE_P(groups) == IS_ARRAY) {
			ZEPHIR_INIT_VAR(groupColumn$$8);
			zephir_fast_join_str(groupColumn$$8, SL(", "), groups TSRMLS_CC);
		} else {
			ZEPHIR_CPY_WRT(groupColumn$$8, groups);
		}
		ZEPHIR_INIT_VAR(_3$$8);
		ZVAL_NULL(_3$$8);
		ZEPHIR_CALL_METHOD(&_2$$8, totalBuilder, "groupby", NULL, 0, _3$$8);
		zephir_check_call_status();
		ZEPHIR_INIT_VAR(_4$$8);
		zephir_create_array(_4$$8, 1, 0 TSRMLS_CC);
		ZEPHIR_INIT_VAR(_5$$8);
		ZEPHIR_CONCAT_SVS(_5$$8, "COUNT(DISTINCT ", groupColumn$$8, ") AS rowcount");
		zephir_array_fast_append(_4$$8, _5$$8);
		ZEPHIR_CALL_METHOD(NULL, _2$$8, "columns", NULL, 0, _4$$8);
		zephir_check_call_status();
	}
	ZEPHIR_INIT_NVAR(_1);
	ZVAL_NULL(_1);
	ZEPHIR_CALL_METHOD(NULL, totalBuilder, "orderby", NULL, 0, _1);
	zephir_check_call_status();
	ZEPHIR_CALL_METHOD(&totalQuery, totalBuilder, "getquery", NULL, 0);
	zephir_check_call_status();
	ZEPHIR_CALL_METHOD(&result, totalQuery, "execute", NULL, 0);
	zephir_check_call_status();
	ZEPHIR_CALL_METHOD(&row, result, "getfirst", NULL, 0);
	zephir_check_call_status();
	if (zephir_is_true(row)) {
		ZEPHIR_OBS_VAR(_6);
		zephir_read_property(&_6, row, SL("rowcount"), PH_NOISY_CC);
		ZEPHIR_INIT_VAR(rowcount);
		ZVAL_LONG(rowcount, zephir_get_intval(_6));
	} else {
		ZEPHIR_INIT_NVAR(rowcount);
		ZVAL_LONG(rowcount, 0);
	}
	ZEPHIR_SINIT_VAR(_7);
	div_function(&_7, rowcount, limit TSRMLS_CC);
	ZEPHIR_SINIT_VAR(_8);
	ZVAL_DOUBLE(&_8, zephir_ceil(&_7 TSRMLS_CC));
	ZEPHIR_INIT_VAR(totalPages);
	ZVAL_LONG(totalPages, zephir_get_intval(&_8));
	if (ZEPHIR_GT_LONG(totalPages, numberPage)) {
		ZEPHIR_INIT_VAR(next);
		ZVAL_LONG(next, (numberPage + 1));
	} else {
		ZEPHIR_CPY_WRT(next, totalPages);
	}
	ZEPHIR_INIT_VAR(page);
	object_init(page);
	zephir_update_property_zval(page, SL("items"), items TSRMLS_CC);
	ZEPHIR_INIT_ZVAL_NREF(_9);
	ZVAL_LONG(_9, 1);
	zephir_update_property_zval(page, SL("first"), _9 TSRMLS_CC);
	ZEPHIR_INIT_ZVAL_NREF(_9);
	ZVAL_LONG(_9, before);
	zephir_update_property_zval(page, SL("before"), _9 TSRMLS_CC);
	ZEPHIR_INIT_ZVAL_NREF(_9);
	ZVAL_LONG(_9, numberPage);
	zephir_update_property_zval(page, SL("current"), _9 TSRMLS_CC);
	zephir_update_property_zval(page, SL("last"), totalPages TSRMLS_CC);
	zephir_update_property_zval(page, SL("next"), next TSRMLS_CC);
	zephir_update_property_zval(page, SL("total_pages"), totalPages TSRMLS_CC);
	zephir_update_property_zval(page, SL("total_items"), rowcount TSRMLS_CC);
	_9 = zephir_fetch_nproperty_this(this_ptr, SL("_limitRows"), PH_NOISY_CC);
	zephir_update_property_zval(page, SL("limit"), _9 TSRMLS_CC);
	RETURN_CCTOR(page);

}
예제 #8
0
/**
 * Returns a slice of the resultset to show in the pagination
 */
PHP_METHOD(Phalcon_Paginator_Adapter_QueryBuilder, getPaginate) {

	int numberPage, before, ZEPHIR_LAST_CALL_STATUS;
	zval *originalBuilder, *builder, *totalBuilder, *totalPages, *limit, *number, *query = NULL, *page, *items = NULL, *totalQuery = NULL, *result = NULL, *row = NULL, *rowcount, *next = NULL, *_0, *_1 = NULL, *_2, _3, _4, *_5;

	ZEPHIR_MM_GROW();

	ZEPHIR_OBS_VAR(originalBuilder);
	zephir_read_property_this(&originalBuilder, this_ptr, SL("_builder"), PH_NOISY_CC);
	ZEPHIR_INIT_VAR(builder);
	if (zephir_clone(builder, originalBuilder TSRMLS_CC) == FAILURE) {
		RETURN_MM();
	}
	ZEPHIR_INIT_VAR(totalBuilder);
	if (zephir_clone(totalBuilder, builder TSRMLS_CC) == FAILURE) {
		RETURN_MM();
	}
	ZEPHIR_OBS_VAR(limit);
	zephir_read_property_this(&limit, this_ptr, SL("_limitRows"), PH_NOISY_CC);
	ZEPHIR_OBS_VAR(_0);
	zephir_read_property_this(&_0, this_ptr, SL("_page"), PH_NOISY_CC);
	numberPage = zephir_get_intval(_0);
	if (!(numberPage)) {
		numberPage = 1;
	}
	ZEPHIR_INIT_VAR(number);
	ZVAL_LONG(number, (zephir_get_numberval(limit) * ((numberPage - 1))));
	if (ZEPHIR_LT(number, limit)) {
		ZEPHIR_CALL_METHOD(NULL, builder, "limit", NULL, 0, limit);
		zephir_check_call_status();
	} else {
		ZEPHIR_CALL_METHOD(NULL, builder, "limit", NULL, 0, limit, number);
		zephir_check_call_status();
	}
	ZEPHIR_CALL_METHOD(&query, builder, "getquery", NULL, 0);
	zephir_check_call_status();
	if (numberPage == 1) {
		before = 1;
	} else {
		before = (numberPage - 1);
	}
	ZEPHIR_CALL_METHOD(&items, query, "execute", NULL, 0);
	zephir_check_call_status();
	ZEPHIR_INIT_VAR(_1);
	ZVAL_STRING(_1, "COUNT(*) [rowcount]", ZEPHIR_TEMP_PARAM_COPY);
	ZEPHIR_CALL_METHOD(NULL, totalBuilder, "columns", NULL, 0, _1);
	zephir_check_temp_parameter(_1);
	zephir_check_call_status();
	ZEPHIR_INIT_NVAR(_1);
	ZVAL_NULL(_1);
	ZEPHIR_CALL_METHOD(NULL, totalBuilder, "orderby", NULL, 0, _1);
	zephir_check_call_status();
	ZEPHIR_CALL_METHOD(&totalQuery, totalBuilder, "getquery", NULL, 0);
	zephir_check_call_status();
	ZEPHIR_CALL_METHOD(&result, totalQuery, "execute", NULL, 0);
	zephir_check_call_status();
	ZEPHIR_CALL_METHOD(&row, result, "getfirst", NULL, 0);
	zephir_check_call_status();
	ZEPHIR_OBS_VAR(_2);
	zephir_read_property(&_2, row, SL("rowcount"), PH_NOISY_CC);
	ZEPHIR_INIT_VAR(rowcount);
	ZVAL_LONG(rowcount, zephir_get_intval(_2));
	ZEPHIR_SINIT_VAR(_3);
	div_function(&_3, rowcount, limit TSRMLS_CC);
	ZEPHIR_SINIT_VAR(_4);
	ZVAL_DOUBLE(&_4, zephir_ceil(&_3 TSRMLS_CC));
	ZEPHIR_INIT_VAR(totalPages);
	ZVAL_LONG(totalPages, zephir_get_intval(&_4));
	if (ZEPHIR_GT_LONG(totalPages, numberPage)) {
		ZEPHIR_INIT_VAR(next);
		ZVAL_LONG(next, (numberPage + 1));
	} else {
		ZEPHIR_CPY_WRT(next, totalPages);
	}
	ZEPHIR_INIT_VAR(page);
	object_init(page);
	zephir_update_property_zval(page, SL("items"), items TSRMLS_CC);
	ZEPHIR_INIT_ZVAL_NREF(_5);
	ZVAL_LONG(_5, 1);
	zephir_update_property_zval(page, SL("first"), _5 TSRMLS_CC);
	ZEPHIR_INIT_ZVAL_NREF(_5);
	ZVAL_LONG(_5, before);
	zephir_update_property_zval(page, SL("before"), _5 TSRMLS_CC);
	ZEPHIR_INIT_ZVAL_NREF(_5);
	ZVAL_LONG(_5, numberPage);
	zephir_update_property_zval(page, SL("current"), _5 TSRMLS_CC);
	zephir_update_property_zval(page, SL("last"), totalPages TSRMLS_CC);
	zephir_update_property_zval(page, SL("next"), next TSRMLS_CC);
	zephir_update_property_zval(page, SL("total_pages"), totalPages TSRMLS_CC);
	zephir_update_property_zval(page, SL("total_items"), rowcount TSRMLS_CC);
	_5 = zephir_fetch_nproperty_this(this_ptr, SL("_limitRows"), PH_NOISY_CC);
	zephir_update_property_zval(page, SL("limit"), _5 TSRMLS_CC);
	RETURN_CCTOR(page);

}