本文整理汇总了C#中PhpReference类的典型用法代码示例。如果您正苦于以下问题:C# PhpReference类的具体用法?C# PhpReference怎么用?C# PhpReference使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PhpReference类属于命名空间,在下文中一共展示了PhpReference类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Open
private static PhpResource Open(string filename, int mode, PhpReference error, bool persistent)
{
if (persistent) PhpException.FunctionNotSupported(PhpError.Notice);
SQLiteConnectionStringBuilder csb = new SQLiteConnectionStringBuilder();
csb.DataSource = filename;
csb.Version = 3;
try
{
PhpSQLiteDbConnection connection = new PhpSQLiteDbConnection(csb.ConnectionString);
if (error != null)
{
error.Value = null;
}
return connection;
}
catch (Exception ex)
{
if (error != null)
{
error.Value = ex.Message;
}
return null;
}
}
示例2: Binding
public Binding(PhpReference/*!*/ variable, IDataParameter/*!*/ parameter, ParameterType type)
{
Debug.Assert(variable != null && parameter != null && type != ParameterType.Invalid);
this.Variable = variable;
this.Parameter = parameter;
this.Type = type;
}
示例3: notsetOperation
static PhpReference notsetOperation(DObject self, string name, DTypeDesc caller, PhpReference refrnc)
{
bool getter_exists;
// the CT property has been unset -> try to invoke __get
PhpReference get_ref = self.InvokeGetterRef(name, caller, out getter_exists);
if (getter_exists) return get_ref ?? new PhpReference();
Debug.Assert(refrnc != null);
refrnc.IsAliased = true;
refrnc.IsSet = true;
return refrnc;
}
示例4: query
public object query(ScriptContext context, object query, object resultType, PhpReference error)
{
SQLite.QueryResultKeys rt = SQLite.QueryResultKeys.Both;
int vRt = PHP.Core.Convert.ObjectToInteger(resultType);
if (Enum.IsDefined(typeof(SQLite.QueryResultKeys), vRt))
{
rt = (SQLite.QueryResultKeys)vRt;
}
PhpSQLiteDbResult result = (PhpSQLiteDbResult)SQLite.Query(this.m_con, query, rt, error);
if (result != null)
{
return new SQLiteResult(result);
}
else
{
return null;
}
}
示例5: Map
public static PhpArray Map(PHP.Core.Reflection.DTypeDesc caller, PhpCallback map, [PhpRw] params PhpArray[] arrays)
{
if (!PhpArgument.CheckCallback(map, caller, "map", 0, true)) return null;
if (arrays == null || arrays.Length == 0)
{
PhpException.InvalidArgument("arrays", LibResources.GetString("arg:null_or_emtpy"));
return null;
}
// if callback has not been specified uses the default one:
if (map == null)
map = new PhpCallback(new RoutineDelegate(MapIdentity), ScriptContext.CurrentContext);
int count = arrays.Length;
bool preserve_keys = count == 1;
PhpReference[] args = new PhpReference[count];
IEnumerator<KeyValuePair<IntStringKey, object>>[] iterators = new IEnumerator<KeyValuePair<IntStringKey, object>>[count];
PhpArray result;
// initializes iterators and args array, computes length of the longest array:
int max_count = 0;
for (int i = 0; i < arrays.Length; i++)
{
var array = arrays[i];
if (array == null)
{
PhpException.Throw(PhpError.Warning, LibResources.GetString("argument_not_array", i + 2));// +2 (first arg is callback)
return null;
}
args[i] = new PhpReference();
iterators[i] = array.GetEnumerator();
if (array.Count > max_count) max_count = array.Count;
}
// keys are preserved in a case of a single array and re-indexed otherwise:
if (preserve_keys)
result = new PhpArray(arrays[0].IntegerCount, arrays[0].StringCount);
else
result = new PhpArray(max_count, 0);
for (; ; )
{
// fills args[] with items from arrays:
for (int i = 0; i < arrays.Length; i++)
{
if (iterators[i] != null)
{
// an element is available:
if (iterators[i].MoveNext())
{
// note: deep copy is not necessary since a function copies its arguments if needed:
object value = iterators[i].Current.Value;
PhpReference valueref = (value != null) ? value as PhpReference : null;
args[i].Value = (valueref != null) ? valueref.value : value;
//args[i].Value = iterators[i].Current.Value; // TODO: throws if the current Value is PhpReference
}
else
{
// the i-th iterator has stopped:
count--;
iterators[i] = null;
args[i].Value = null;
}
}
}
if (count == 0) break;
// invokes callback:
object return_value = map.Invoke(args);
// return value is not deeply copied:
if (preserve_keys)
result.Add(iterators[0].Current.Key, return_value);
else
result.Add(return_value);
// loads new values (callback may modify some by ref arguments):
for (int i = 0; i < arrays.Length; i++)
{
if (iterators[i] != null)
{
object item = iterators[i].Current.Value;
PhpReference ref_item = item as PhpReference;
if (ref_item != null)
{
ref_item.Value = args[i].Value;
}
else
{
arrays[i][iterators[i].Current.Key] = args[i].Value;
}
}
}
}
return result;
}
示例6: SetObjectFieldDirectRef
public static void SetObjectFieldDirectRef(PhpReference value, DObject/*!*/ obj, ref PhpReference/*!*/ field,
string/*!*/ name, DTypeDesc caller)
{
Debug.Assert(obj != null && field != null && name != null);
if (field.IsSet)
{
field = value;
}
else
{
SetObjectProperty(obj, name, value, caller);
}
}
示例7: GetObjectFieldDirect
public static object GetObjectFieldDirect(DObject/*!*/ obj, PhpReference/*!*/ field,
string/*!*/ name, DTypeDesc caller, bool quiet)
{
Debug.Assert(obj != null && field != null && name != null);
if (field.IsSet)
{
return field.Value;
}
else
{
return GetObjectProperty(obj, name, caller, quiet);
}
}
示例8: EnsurePropertyIsObjectInternal
/// <summary>
/// Ensures that a property value is of <see cref="DObject"/> type.
/// </summary>
/// <param name="obj">The object whose property is to be checked.</param>
/// <param name="name">The property name.</param>
/// <param name="caller"><see cref="Type"/> of the object that request the operation.</param>
/// <param name="propValue">The property value (might get updated).</param>
/// <param name="context">The current <see cref="ScriptContext"/>.</param>
/// <returns>The new property value (dereferenced) or <B>null</B> if evaluation of this compound
/// statement should not proceed.</returns>
internal static DObject EnsurePropertyIsObjectInternal(DObject obj, string name, DTypeDesc caller, ref object propValue,
ScriptContext context)
{
DObject result;
PhpReference reference = propValue as PhpReference;
object value;
if (reference != null && !reference.IsSet)
{
// this CT property has been unset
if (obj.TypeDesc.GetMethod(Name.SpecialMethodNames.Set) != null &&
obj.TypeDesc.RealType.Namespace != null &&
obj.TypeDesc.RealType.Namespace.StartsWith(Namespaces.Library))
{
// create a chain of arguments to be passed to the setter
context.BeginSetterChain(obj);
context.ExtendSetterChain(new RuntimeChainProperty(name));
return ScriptContext.SetterChainSingletonObject;
}
// try to invoke __get
bool getter_exists;
reference = obj.InvokeGetterRef(name, caller, out getter_exists);
if (!getter_exists)
{
result = stdClass.CreateDefaultObject(context);
propValue = new PhpReference(result);
return result;
}
else if (reference == null) return null; // error
value = reference.Value;
}
else value = PhpVariable.Dereference(propValue);
// if property value is a DObject, nothing has to be done
result = value as DObject;
if (result != null) return result;
// if the property is "empty"?
if (IsEmptyForEnsure(value))
{
// create a new stdClass and update the reference
result = stdClass.CreateDefaultObject(context);
if (reference != null)
{
reference.Value = result;
reference.IsSet = true;
}
else propValue = result;
return result;
}
// error - the property is a scalar or a PhpArray or a non-empty string
PhpException.VariableMisusedAsObject(value, false);
return null;
}
示例9: SetItemRefEpilogue
private static void SetItemRefEpilogue(PhpReference value, object key, ref object var)
{
// object behaving as array:
DObject dobj = var as DObject;
if (dobj != null && dobj.RealObject is Library.SPL.ArrayAccess)
{
PhpStack stack = ScriptContext.CurrentContext.Stack;
stack.AddFrame(key, value);
dobj.InvokeMethod(Library.SPL.PhpArrayObject.offsetSet, null, stack.Context);
return;
}
// errors - non-empty string, DObject, scalar:
PhpException.VariableMisusedAsArray(var, true);
}
示例10: GetItemRef
public static PhpReference/*!*/ GetItemRef(string key, ref object var)
{
Debug.Assert(!(var is PhpReference));
Debug.Assert(!(var is PhpArrayString), "ensures and end-of-chain operators only");
// PhpArray:
if (var != null && var.GetType() == typeof(PhpArray)) // fast check for PhpArray, not derived types
return ((PhpArray)var).GetArrayItemRef(key);
// creates a new reference and adds it to an a new array:
if (IsEmptyForEnsure(var))
{
PhpArray array;
var = array = new PhpArray(0, 1);
PhpReference result = new PhpReference();
array.SetArrayItemRef(key, result);
return result;
}
return GetItemRefEpilogue(key, ref var);
}
示例11: ParseReference
/// <summary>
/// Parses the <B>R</B> token.
/// </summary>
private void ParseReference()
{
Consume(Tokens.Colon);
int seq_number = (unchecked((int)ReadInteger())) - 1;
Consume(Tokens.Semicolon);
if (seq_number < 0 || seq_number >= sequenceMap.Count) ThrowInvalidReference();
int index = sequenceMap[seq_number];
// make the referenced atom a PhpReference
PhpReference reference = atoms[index] as PhpReference;
if (reference == null)
{
reference = new PhpReference(atoms[index]);
atoms[index] = reference;
}
atoms.Add(new BackReference(index, true));
}
示例12: ParseStr
public static bool ParseStr(string encoded_string, PhpReference array)
{
try
{
PhpArray result = new PhpArray();
foreach (var x in ParseUrlEncodedGetParameters(encoded_string))
result.Add(x.Key, x.Value);
array.Value = result;
return true;
}
catch
{
return false;
}
}
示例13: ReadLineFormat
public static int ReadLineFormat(PhpResource handle, string format, PhpReference arg, params PhpReference[] arguments)
{
PhpStream stream = PhpStream.GetValid(handle);
if (stream == null) return -1;
string line = stream.ReadLine(-1, null);
return PhpStrings.ScanFormat(line, format, arg, arguments);
}
示例14: EnsurePropertyIsArrayInternal
/// <summary>
/// Ensures that a property value is of <see cref="PhpArray"/> type.
/// </summary>
/// <param name="obj">The object whose property is to be checked.</param>
/// <param name="name">The property name.</param>
/// <param name="caller"><see cref="Type"/> of the object that request the operation.</param>
/// <param name="propValue">The property value (might get updated).</param>
/// <returns>The new property value (dereferenced) or <B>null</B> if evaluation of this compound
/// statement should not proceed.</returns>
internal static PhpArray EnsurePropertyIsArrayInternal(DObject obj, string name, DTypeDesc caller, ref object propValue)
{
PhpArray result;
PhpReference reference = propValue as PhpReference;
object value;
if (reference != null && !reference.IsSet)
{
// this CT property has been unset
if (obj.TypeDesc.GetMethod(DObject.SpecialMethodNames.Set) != null &&
obj.TypeDesc.RealType.Namespace != null &&
obj.TypeDesc.RealType.Namespace.StartsWith(Namespaces.Library))
{
ScriptContext context = ScriptContext.CurrentContext;
// create a chain of arguments to be passed to the setter
context.BeginSetterChain(obj);
context.ExtendSetterChain(new RuntimeChainProperty(name));
return ScriptContext.SetterChainSingletonArray;
}
// try to invoke __get
bool getter_exists;
reference = obj.InvokeGetterRef(name, caller, out getter_exists);
if (!getter_exists)
{
result = new PhpArray();
propValue = new PhpReference(result);
return result;
}
else if (reference == null) return null; // error
value = reference.Value;
}
else value = PhpVariable.Dereference(propValue);
// if the property is PhpArray, nothing has to be done
result = value as PhpArray;
if (result != null) return result;
// checks an object behaving like an array:
DObject dobj = value as DObject;
if (dobj != null && dobj.RealObject is Library.SPL.ArrayAccess)
return new Library.SPL.PhpArrayObject(dobj);
// if the property is "empty"
if (IsEmptyForEnsure(value))
{
// create a new PhpArray and update the reference
result = new PhpArray();
if (reference != null)
{
reference.Value = result;
reference.IsSet = true;
}
else propValue = result;
return result;
}
// non-empty immutable string:
string str_value = value as string;
if (str_value != null)
{
PhpString str = new PhpString(str_value);
if (reference != null) reference.Value = str;
else propValue = str;
return new PhpArrayString(str);
}
// non-empty mutable string:
if (value is PhpString || value is PhpBytes)
return new PhpArrayString(value);
// error - the property is a scalar or a PhpObject:
PhpException.VariableMisusedAsArray(value, false);
return null;
}
示例15: getimagesize
private static PhpArray getimagesize(Stream stream, PhpReference imageinfo)
{
PhpArray exif;
PhpArray result = GetImageSize(stream, imageinfo != null, out exif);
if (imageinfo != null) imageinfo.value = exif ?? new PhpArray();
return result;
}