本文整理汇总了C#中PHP.Core.PhpArray类的典型用法代码示例。如果您正苦于以下问题:C# PhpArray类的具体用法?C# PhpArray怎么用?C# PhpArray使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PhpArray类属于PHP.Core命名空间,在下文中一共展示了PhpArray类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddVariables
/// <summary>
/// Adds variables from one auto-global array to another.
/// </summary>
/// <param name="dst">The target array.</param>
/// <param name="src">The source array.</param>
/// <remarks>Variable values are deeply copied.</remarks>
/// <exception cref="ArgumentNullException"><paramref name="dst"/> is a <B>null</B> reference.</exception>
/// <exception cref="ArgumentNullException"><paramref name="src"/> is a <B>null</B> reference.</exception>
private static void AddVariables(PhpArray/*!*/ dst, PhpArray/*!*/ src)
{
Debug.Assert(dst != null && src != null);
foreach (KeyValuePair<IntStringKey, object> entry in src)
dst[entry.Key] = PhpVariable.DeepCopy(entry.Value);
}
示例2: BindParams
public object[] BindParams(MethodInfo mi, PhpArray parameters, bool wrappedArgs)
{
var resultParams = new List<object>();
var parameterInfos = mi.GetParameters();
object value;
if (!wrappedArgs)
{
//TODO: make sure: When arguments are not wrapped soap method parameter is only one
Debug.Assert(parameterInfos.Length == 1);
resultParams.Add(Bind(parameters, parameterInfos[0].ParameterType));
}
else
{
foreach (var pi in parameterInfos)
{
if (SetSpecifiedParameter(resultParams, pi))
continue;
if (parameters.TryGetValue(pi.Name, out value))
{
resultParams.Add(Bind(value, pi.ParameterType));
}
}
}
lastPrimitive = false;
return resultParams.ToArray();
}
示例3: Create
public static CurlForm Create(PhpArray arr)
{
string type = null;
string filename;
CurlForm form = new CurlForm();
//go through items and if item starts with @ we have to treat it as file
foreach (var item in arr)
{
var strValue = PHP.Core.Convert.ObjectToString(item.Value);
if (!string.IsNullOrEmpty(strValue) && strValue[0] == '@')
{
int index = strValue.IndexOf(";type=");
if (index != -1)
type = strValue.Substring(index + ";type=".Length);
index = strValue.IndexOf(";filename=");
if (index != -1)
{
filename = strValue.Substring(index + ";filename=".Length);
//filename = Path.Combine(ScriptContext.CurrentContext.WorkingDirectory, filename);
}
else
{
//filename = Path.Combine(ScriptContext.CurrentContext.WorkingDirectory, strValue.Substring(1));
filename = strValue.Substring(1);
}
form.AddFile(item.Key.String,
filename,
type != null ? type : "application/octet-stream",
item.Value
);
//Code from PHP CURL extension:
//error = curl_formadd(&first, &last,
// CURLFORM_COPYNAME, string_key,
// CURLFORM_NAMELENGTH, (long)string_key_len - 1,
// CURLFORM_FILENAME, filename ? filename + sizeof(";filename=") - 1 : postval,
// CURLFORM_CONTENTTYPE, type ? type + sizeof(";type=") - 1 : "application/octet-stream",
// CURLFORM_FILE, postval,
// CURLFORM_END);
}
else
{
form.AddData(item.Key.String, item.Value);
//Code from PHP CURL extension:
//error = curl_formadd(&first, &last,
// CURLFORM_COPYNAME, string_key,
// CURLFORM_NAMELENGTH, (long)string_key_len - 1,
// CURLFORM_COPYCONTENTS, postval,
// CURLFORM_CONTENTSLENGTH, (long)Z_STRLEN_PP(current),
// CURLFORM_END);
}
}
return form;
}
示例4: BuildErrorInfo
public static PhpArray BuildErrorInfo(string sqlstate, object driver_error, string message)
{
PhpArray arr = new PhpArray();
arr.Add(0, sqlstate);
arr.Add(1, driver_error);
arr.Add(2, message);
return arr;
}
示例5: PrintFormatted
public static int PrintFormatted(string format, PhpArray args)
{
string formattedString = PhpStrings.Format(format, args);
ScriptContext.CurrentContext.Output.Write(formattedString);
return formattedString.Length;
}
示例6: PhpArray
public static PhpArray/*!*/SplClasses()
{
var array = new PhpArray(32);
// TODO: (J) list SPL classes http://www.php.net/manual/en/function.spl-classes.php
// array.Add( "class_name", "class_name" );
return array;
}
示例7: WrapToStdClass
private static stdClass WrapToStdClass(object obj, string name)
{
var runtimeFields = new PhpArray(1);
runtimeFields[name] = obj;
return new stdClass()
{
RuntimeFields = runtimeFields
};
}
示例8: Closure
/// <summary>
/// Constructor of PHP closure.
/// </summary>
/// <param name="context">Current <see cref="ScriptContext"/></param>
/// <param name="lambda">Delegate to lambda function itself.</param>
/// <param name="parameter"><see cref="PhpArray"/> of closure <c>parameter</c> field. Can be <c>null</c> if there are no parameters.</param>
/// <param name="static"><see cref="PhpArray"/> of closure <c>parameter</c> field. Can be <c>null</c> if there is no <c>use</c> of scope variables.</param>
public Closure(ScriptContext/*!*/context, RoutineDelegate/*!*/lambda, PhpArray parameter, PhpArray @static)
:this(context, true)
{
Debug.Assert(context != null);
Debug.Assert(lambda != null);
this.lambda = lambda;
this.parameter = parameter;
[email protected] = @static;
}
示例9: PrintFunctions
public static PhpArray PrintFunctions()
{
PhpArray result = new PhpArray();
result.Add("name", new PhpArray());
result.Add("type", new PhpArray());
result.Add("method", new PhpArray());
Assembly assembly = typeof(PhpDocumentation).Assembly;
//PhpLibraryModule.EnumerateFunctions(assembly, new PhpLibraryModule.FunctionsEnumCallback(FunctionsCallback), result);
return result;
}
示例10: CallUserFunctionArray
public static object CallUserFunctionArray(DTypeDesc caller, PhpCallback function, PhpArray args)
{
object[] args_array;
if (args != null)
{
args_array = new object[args.Count];
args.CopyValuesTo(args_array, 0);
}
else
{
args_array = ArrayUtils.EmptyObjects;
}
return CallUserFunction(caller, function, args_array);
}
示例11: BindServerParameters
internal static object BindServerParameters(object[] parameters, MethodInfo mi)
{
var runtimeFields = new PhpArray();
//I can also just return CLR type and wrap it with PHP.Core.Reflection.ClrObject.WrapDynamic
int i = 0;
foreach (var p in mi.GetParameters().Where(a => !a.IsOut))
{
var name = WsdlHelper.GetParameterSoapName(p);
var value = Bind(parameters[i++]);
runtimeFields[name] = value;
}
return new stdClass()
{
RuntimeFields = runtimeFields
};
}
示例12: BindObject
private static object BindObject(object obj, Type type)
{
FieldInfo[] fi = type.GetFields(BindingFlags.Public | BindingFlags.Instance);
var runtimeFields = new PhpArray(fi.Length);
object value;
bool specified = true;
FieldInfo field;
for (int i = 0; i < fi.Length; ++i)
{
field = fi[i];
specified = true;
if (i + 1 < fi.Length && Attribute.IsDefined(fi[i + 1], typeof(XmlIgnoreAttribute)))
{
value = fi[i + 1].GetValue(obj);
if (value == null)
specified = false;
else
specified = (bool)value;
i++;
}
if (specified)
{
var fieldValue = field.GetValue(obj);
value = Bind(fieldValue, field);
if (value != null)
{
if (fieldValue != null && fieldValue.GetType().IsArray && ((Array) fieldValue).Length > 0)
fieldValue = ((Array) fieldValue).GetValue(0);
var attr = Attribute.GetCustomAttributes(field, typeof(XmlElementAttribute)).Cast<XmlElementAttribute>().FirstOrDefault(a => a.Type == null || a.Type.IsInstanceOfType(fieldValue));
var name = field.Name;
if (attr != null && !string.IsNullOrWhiteSpace(attr.ElementName))
name = attr.ElementName;
runtimeFields.Add(name, value);
}
}
}
return new stdClass()
{
RuntimeFields = runtimeFields
};
}
示例13: GetFunctions
public static PhpArray GetFunctions()
{
var context = ScriptContext.CurrentContext;
if (context.IsSplAutoloadEnabled)
{
PhpArray result = new PhpArray();
foreach (var func in context.SplAutoloadFunctions)
result.Add(func.ToPhpRepresentation());
return result;
}
else
{
return null;
}
}
示例14: InvokeCall
/// <summary>
/// Invokes the call.
/// </summary>
/// <returns></returns>
public object InvokeCall(string methodName ,PhpArray parameters)
{
var soapProxy = (SoapHttpClientProtocolExtended)proxyInstance;
var mi = WsdlHelper.GetMethodBySoapName(methodName, soapProxy.GetType());
bool wrappedArgs = true;
object[] attr = mi.GetCustomAttributes(typeof(System.Web.Services.Protocols.SoapDocumentMethodAttribute), false);
if (attr.Length > 0 && attr[0].GetType() == typeof(System.Web.Services.Protocols.SoapDocumentMethodAttribute))
{
var soapMethodAttr = (System.Web.Services.Protocols.SoapDocumentMethodAttribute)attr[0];
if (soapMethodAttr.ParameterStyle == System.Web.Services.Protocols.SoapParameterStyle.Bare)
{
wrappedArgs = false;
}
}
var paramBinder = new ParameterBinder();
object[] transformedParameters = paramBinder.BindParams(mi, parameters, wrappedArgs);
object[] resArray = soapProxy.Invoke(mi.Name, transformedParameters);
if (resArray[0] != null)
{
var returnName = WsdlHelper.GetParameterSoapName(mi.ReturnParameter);
resArray[0] = ResultBinder.BindResult(
resArray[0],
returnName,
wrappedArgs);
}
//object result = mi.Invoke(proxyInstance, (object[])methodParams.ToArray(typeof(object)));
//foreach (ParameterInfo pi in mi.GetParameters())
//{
// if (pi.IsOut) outParams.Add(methodParams[i]);
// i++;
//}
return resArray[0];
}
示例15: Apply
public static int Apply(ScriptContext/*!*/context, PHP.Core.Reflection.DTypeDesc caller, Iterator/*!*/iterator, PhpCallback function, PhpArray args)
{
// check parameters:
Debug.Assert(context != null);
Debug.Assert(iterator != null, "Phalanger should not pass a null here.");
if (function == null)
{
PhpException.ArgumentNull("function");
return -1;
}
// copy args into object array:
object[] args_array;
if (args != null)
{
args_array = new object[args.Count];
args.Values.CopyTo(args_array, 0);
}
else
{
args_array = ArrayUtils.EmptyObjects;
}
// iterate through the iterator:
int n = 0;
iterator.rewind(context);
while (PHP.Core.Convert.ObjectToBoolean(iterator.valid(context)))
{
if (!PHP.Core.Convert.ObjectToBoolean(function.Invoke(caller, args_array)))
break;
n++;
iterator.next(context);
}
// return amount of iterated elements:
return n;
}