Beispiel #1
0
/* {{{ php_register_server_variables
 */
static inline void php_register_server_variables(void)
{
	zval_ptr_dtor(&PG(http_globals)[TRACK_VARS_SERVER]);
	array_init(&PG(http_globals)[TRACK_VARS_SERVER]);

	/* Server variables */
	if (sapi_module.register_server_variables) {
		sapi_module.register_server_variables(&PG(http_globals)[TRACK_VARS_SERVER]);
	}

	/* PHP Authentication support */
	if (SG(request_info).auth_user) {
		php_register_variable("PHP_AUTH_USER", SG(request_info).auth_user, &PG(http_globals)[TRACK_VARS_SERVER]);
	}
	if (SG(request_info).auth_password) {
		php_register_variable("PHP_AUTH_PW", SG(request_info).auth_password, &PG(http_globals)[TRACK_VARS_SERVER]);
	}
	if (SG(request_info).auth_digest) {
		php_register_variable("PHP_AUTH_DIGEST", SG(request_info).auth_digest, &PG(http_globals)[TRACK_VARS_SERVER]);
	}
	/* store request init time */
	{
		zval request_time_float, request_time_long;
		ZVAL_DOUBLE(&request_time_float, sapi_get_request_time());
		php_register_variable_ex("REQUEST_TIME_FLOAT", &request_time_float, &PG(http_globals)[TRACK_VARS_SERVER]);
		ZVAL_LONG(&request_time_long, zend_dval_to_lval(Z_DVAL(request_time_float)));
		php_register_variable_ex("REQUEST_TIME", &request_time_long, &PG(http_globals)[TRACK_VARS_SERVER]);
	}

}
Beispiel #2
0
PHP_METHOD(Money, multiply)
{
	double factor;
	volatile double dresult;
	long rounding_mode = PHP_ROUND_HALF_UP, lresult;

	if (zend_parse_parameters(ZEND_NUM_ARGS(), "d|l", &factor, &rounding_mode) == FAILURE) {
		return;
	}

	if (UNEXPECTED(rounding_mode < 0 || rounding_mode > PHP_ROUND_HALF_ODD)) {
		zend_throw_exception(spl_ce_InvalidArgumentException, "$roundingMode must be a valid rounding mode (PHP_ROUND_*)", 0);
		return;
	}

	dresult = _php_math_round(factor * Z_LVAL_P(zend_read_property(money_ce, getThis(), MONEY_PROP_AMOUNT_WS, 0)), 0, rounding_mode);
	lresult = zend_dval_to_lval(dresult);

	if (UNEXPECTED(lresult & LONG_SIGN_MASK)) {
		zend_throw_exception(spl_ce_OverflowException, "Integer overflow", 0);
		return;
	}

	CREATE_NEW_MONEY_OBJ(return_value, lresult, zend_read_property(money_ce, getThis(), MONEY_PROP_CURRENCY_WS, 0));
}
Beispiel #3
0
/* {{{ php_register_server_variables
 */
static inline void php_register_server_variables(void)
{
	zval tmp;
	zval *arr = &PG(http_globals)[TRACK_VARS_SERVER];
	HashTable *ht;

	zval_ptr_dtor_nogc(arr);
	array_init(arr);

	/* Server variables */
	if (sapi_module.register_server_variables) {
		sapi_module.register_server_variables(arr);
	}
	ht = Z_ARRVAL_P(arr);

	/* PHP Authentication support */
	if (SG(request_info).auth_user) {
		ZVAL_STRING(&tmp, SG(request_info).auth_user);
		php_register_variable_quick("PHP_AUTH_USER", sizeof("PHP_AUTH_USER")-1, &tmp, ht);
	}
	if (SG(request_info).auth_password) {
		ZVAL_STRING(&tmp, SG(request_info).auth_password);
		php_register_variable_quick("PHP_AUTH_PW", sizeof("PHP_AUTH_PW")-1, &tmp, ht);
	}
	if (SG(request_info).auth_digest) {
		ZVAL_STRING(&tmp, SG(request_info).auth_digest);
		php_register_variable_quick("PHP_AUTH_DIGEST", sizeof("PHP_AUTH_DIGEST")-1, &tmp, ht);
	}

	/* store request init time */
	ZVAL_DOUBLE(&tmp, sapi_get_request_time());
	php_register_variable_quick("REQUEST_TIME_FLOAT", sizeof("REQUEST_TIME_FLOAT")-1, &tmp, ht);
	ZVAL_LONG(&tmp, zend_dval_to_lval(Z_DVAL(tmp)));
	php_register_variable_quick("REQUEST_TIME", sizeof("REQUEST_TIME")-1, &tmp, ht);
}
Beispiel #4
0
PHP_METHOD(Money, extractPercentage)
{
	long percentage;
	double result;
	zval *new_money_percentage, *amount, *new_money_subtotal;

	if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &percentage) == FAILURE) {
		return;
	}

	ALLOC_INIT_ZVAL(new_money_percentage);ALLOC_INIT_ZVAL(new_money_subtotal);

	amount = zend_read_property(money_ce, getThis(), MONEY_PROP_AMOUNT_WS, 0);
	result = Z_LVAL_P(amount) / (100 + percentage) * percentage;

	CREATE_NEW_MONEY_OBJ(new_money_percentage, zend_dval_to_lval(result), zend_read_property(money_ce, getThis(), MONEY_PROP_CURRENCY_WS, 0))

	array_init(return_value);
	add_assoc_zval(return_value, "percentage", new_money_percentage);

	money_handler_do_operation(ZEND_SUB, new_money_subtotal, getThis(), new_money_percentage);

	add_assoc_zval(return_value, "subtotal", new_money_subtotal);
}