示例#1
0
PHP_COM_DOTNET_API void php_com_variant_from_zval(VARIANT *v, zval *z, int codepage TSRMLS_DC)
{
	OLECHAR *olestring;
	php_com_dotnet_object *obj;
	
	switch (Z_TYPE_P(z)) {
		case IS_NULL:
			V_VT(v) = VT_NULL;
			break;

		case IS_BOOL:
			V_VT(v) = VT_BOOL;
			V_BOOL(v) = Z_BVAL_P(z) ? VARIANT_TRUE : VARIANT_FALSE;
			break;

		case IS_OBJECT:
			if (php_com_is_valid_object(z TSRMLS_CC)) {
				obj = CDNO_FETCH(z);
				if (V_VT(&obj->v) == VT_DISPATCH) {
					/* pass the underlying object */
					V_VT(v) = VT_DISPATCH;
					if (V_DISPATCH(&obj->v)) {
						IDispatch_AddRef(V_DISPATCH(&obj->v));
					}
					V_DISPATCH(v) = V_DISPATCH(&obj->v);
				} else {
					/* pass the variant by reference */
					V_VT(v) = VT_VARIANT | VT_BYREF;
					V_VARIANTREF(v) = &obj->v;
				}
			} else {
				/* export the PHP object using our COM wrapper */
				V_VT(v) = VT_DISPATCH;
				V_DISPATCH(v) = php_com_wrapper_export(z TSRMLS_CC);
			}
			break;
			
		case IS_ARRAY:
			/* map as safe array */
			safe_array_from_zval(v, z, codepage TSRMLS_CC);
			break;

		case IS_LONG:
			V_VT(v) = VT_I4;
			V_I4(v) = Z_LVAL_P(z);
			break;

		case IS_DOUBLE:
			V_VT(v) = VT_R8;
			V_R8(v) = Z_DVAL_P(z);
			break;

		case IS_STRING:
			V_VT(v) = VT_BSTR;
			olestring = php_com_string_to_olestring(Z_STRVAL_P(z), Z_STRLEN_P(z), codepage TSRMLS_CC);
			V_BSTR(v) = SysAllocStringByteLen((char*)olestring, Z_STRLEN_P(z) * sizeof(OLECHAR));
			efree(olestring);
			break;

		case IS_RESOURCE:
		case IS_CONSTANT:
		case IS_CONSTANT_ARRAY:
		default:
			V_VT(v) = VT_NULL;
			break;
	}
}
示例#2
0
PHP_COM_DOTNET_API void php_com_variant_from_zval(VARIANT *v, zval *z, int codepage)
{
	OLECHAR *olestring;
	php_com_dotnet_object *obj;
	zend_uchar ztype = IS_NULL;

	if (z) {
		ZVAL_DEREF(z);
		ztype = Z_TYPE_P(z);
	}

	switch (ztype) {
		case IS_NULL:
			V_VT(v) = VT_NULL;
			break;

		case IS_FALSE:
			V_VT(v) = VT_BOOL;
			V_BOOL(v) = VARIANT_FALSE;
			break;

		case IS_TRUE:
			V_VT(v) = VT_BOOL;
			V_BOOL(v) = VARIANT_TRUE;
			break;

		case IS_OBJECT:
			if (php_com_is_valid_object(z)) {
				obj = CDNO_FETCH(z);
				if (V_VT(&obj->v) == VT_DISPATCH) {
					/* pass the underlying object */
					V_VT(v) = VT_DISPATCH;
					if (V_DISPATCH(&obj->v)) {
						IDispatch_AddRef(V_DISPATCH(&obj->v));
					}
					V_DISPATCH(v) = V_DISPATCH(&obj->v);
				} else {
					/* pass the variant by reference */
					V_VT(v) = VT_VARIANT | VT_BYREF;
					V_VARIANTREF(v) = &obj->v;
				}
			} else {
				/* export the PHP object using our COM wrapper */
				V_VT(v) = VT_DISPATCH;
				V_DISPATCH(v) = php_com_wrapper_export(z);
			}
			break;

		case IS_ARRAY:
			/* map as safe array */
			safe_array_from_zval(v, z, codepage);
			break;

		case IS_LONG:
#if SIZEOF_ZEND_LONG == 4
			V_VT(v) = VT_I4;
			V_I4(v) = Z_LVAL_P(z);
#else
			V_VT(v) = VT_I8;
			V_I8(v) = Z_LVAL_P(z);
#endif
			break;

		case IS_DOUBLE:
			V_VT(v) = VT_R8;
			V_R8(v) = Z_DVAL_P(z);
			break;

		case IS_STRING:
			V_VT(v) = VT_BSTR;
			olestring = php_com_string_to_olestring(Z_STRVAL_P(z), Z_STRLEN_P(z), codepage);
			if (CP_UTF8 == codepage) {
				V_BSTR(v) = SysAllocStringByteLen((char*)olestring, (UINT)(wcslen(olestring) * sizeof(OLECHAR)));
			} else {
				V_BSTR(v) = SysAllocStringByteLen((char*)olestring, (UINT)(Z_STRLEN_P(z) * sizeof(OLECHAR)));
			}
			efree(olestring);
			break;

		case IS_RESOURCE:
		case IS_CONSTANT_AST:
		default:
			V_VT(v) = VT_NULL;
			break;
	}
}