public static ConversionCost ToInt32(PhpValue value) => ToInt64(value);
public virtual PhpValue key() { return(PhpValue.Create(_index)); }
/// <summary> /// Adds an object inside the storage, and optionally associate it to some data. /// </summary> public virtual void attach(object @object, PhpValue data = default(PhpValue)) => Keys.AttachImpl(storage, @object, data);
public void setStaticPropertyValue(string name, PhpValue value) { throw new NotImplementedException(); }
public ReflectionClass(Context ctx, PhpValue @class) { __construct(ctx, @class); }
PhpValue Iterator.key() => PhpValue.Create(_list[_element].localName);
public ArrayIterator(Context /*!*/ ctx, PhpValue array, int flags = 0) : this(ctx) { __construct(ctx, array, flags); }
/// <summary> /// Whether an offset exists. /// </summary> /// <remarks>This method is executed when using isset() or empty().</remarks> public bool offsetExists(PhpValue offset) { var i = offset.ToLong(); return(i >= 0 && _array != null && i < _array.Length && _array[i].IsSet); }
static string Export(Context ctx, PhpValue value) => Library.Variables.print_r(ctx, value, true).ToString(ctx).Trim();
/// <inheritDoc /> public override bool TrySetAttribute(Dictionary <PDO.PDO_ATTR, PhpValue> attributes, int attribute, PhpValue value) { return(false); }
/// <summary> /// Unsets an offset. /// </summary> public void offsetUnset(PhpValue offset) => offsetSet(offset, PhpValue.Void);
public ReflectionFunction(Context ctx, PhpValue name) { __construct(ctx, name); }
/// <summary> /// Retrieves the length of the output buffer. /// </summary> /// <returns>The length of the contents in the output buffer or <B>false</B>, if output buffering isn't active.</returns> public static PhpValue ob_get_length(Context ctx) { var length = ctx.BufferedOutput.Length; return((length >= 0) ? PhpValue.Create(length) : PhpValue.False); }
internal static bool TrySetOption(this CURLResource ch, int option, PhpValue value) { switch (option) { case CURLOPT_URL: return((ch.Url = value.AsString()) != null); case CURLOPT_DEFAULT_PROTOCOL: return((ch.DefaultSheme = value.AsString()) != null); case CURLOPT_HTTPGET: if (value.ToBoolean()) { ch.Method = WebRequestMethods.Http.Get; } break; case CURLOPT_POST: if (value.ToBoolean()) { ch.Method = WebRequestMethods.Http.Post; } break; case CURLOPT_PUT: if (value.ToBoolean()) { ch.Method = WebRequestMethods.Http.Put; } break; case CURLOPT_NOBODY: if (value.ToBoolean()) { ch.Method = WebRequestMethods.Http.Head; } break; case CURLOPT_CUSTOMREQUEST: return((ch.Method = value.AsString()) != null); case CURLOPT_POSTFIELDS: ch.PostFields = value.GetValue().DeepCopy(); break; case CURLOPT_FOLLOWLOCATION: ch.FollowLocation = value.ToBoolean(); break; case CURLOPT_MAXREDIRS: ch.MaxRedirects = (int)value.ToLong(); break; case CURLOPT_REFERER: return((ch.Referer = value.AsString()) != null); case CURLOPT_RETURNTRANSFER: ch.ProcessingResponse = value.ToBoolean() ? ProcessMethod.Return : ProcessMethod.StdOut; break; case CURLOPT_HEADER: ch.ProcessingHeaders = value.ToBoolean() ? ProcessMethod.StdOut // NOTE: if ProcessingResponse is RETURN, RETURN headers as well : ProcessMethod.Ignore; break; case CURLOPT_HTTPHEADER: ch.Headers = value.GetValue().DeepCopy().ToArray(); break; case CURLOPT_COOKIE: return((ch.CookieHeader = value.AsString()) != null); case CURLOPT_COOKIEFILE: ch.CookieFileSet = true; break; case CURLOPT_FILE: return(TryProcessMethodFromStream(value, ProcessMethod.StdOut, ref ch.ProcessingResponse)); case CURLOPT_INFILE: return(TryProcessMethodFromStream(value, ProcessMethod.Ignore, ref ch.ProcessingRequest, readable: true)); case CURLOPT_WRITEHEADER: return(TryProcessMethodFromStream(value, ProcessMethod.Ignore, ref ch.ProcessingHeaders)); //case CURLOPT_STDERR: return TryProcessMethodFromStream(value, ProcessMethod.Ignore, ref ch.ProcessingErr); case CURLOPT_HEADERFUNCTION: return(TryProcessMethodFromCallable(value, ProcessMethod.Ignore, ref ch.ProcessingHeaders)); case CURLOPT_WRITEFUNCTION: return(TryProcessMethodFromCallable(value, ProcessMethod.StdOut, ref ch.ProcessingResponse)); //case CURLOPT_READFUNCTION: //case CURLOPT_PROGRESSFUNCTION: case CURLOPT_USERAGENT: return((ch.UserAgent = value.AsString()) != null); case CURLOPT_BINARYTRANSFER: break; // no effect case CURLOPT_PRIVATE: ch.Private = value.GetValue().DeepCopy(); break; case CURLOPT_TIMEOUT: { if (value.IsLong(out long l)) { ch.Timeout = (int)l * 1000; } break; } case CURLOPT_TIMEOUT_MS: { if (value.IsLong(out long l)) { ch.Timeout = (int)l; } break; } case CURLOPT_CONNECTTIMEOUT: return(false); // TODO: is there an alternative in .NET ? case CURLOPT_CONNECTTIMEOUT_MS: return(false); // TODO: is there an alternative in .NET ? case CURLOPT_BUFFERSIZE: { if (value.IsLong(out long l) && l < int.MaxValue && l >= 0) { ch.BufferSize = (int)l; return(true); } return(false); } case CURLOPT_EXPECT_100_TIMEOUT_MS: { if (value.IsLong(out long l)) { ch.ContinueTimeout = (int)l; } break; } case CURLOPT_HTTP_VERSION: switch ((int)value.ToLong()) { case CURL_HTTP_VERSION_NONE: ch.ProtocolVersion = null; break; case CURL_HTTP_VERSION_1_0: ch.ProtocolVersion = HttpVersion.Version10; break; case CURL_HTTP_VERSION_1_1: ch.ProtocolVersion = HttpVersion.Version11; break; //case CURL_HTTP_VERSION_2: case CURL_HTTP_VERSION_2_0: case CURL_HTTP_VERSION_2TLS: ch.ProtocolVersion = new Version(2, 0); break; // HttpVersion.Version20 default: return(false); } break; case CURLOPT_USERNAME: ch.Username = value.ToString(); break; case CURLOPT_USERPWD: (ch.Username, ch.Password) = SplitUserPwd(value.ToString()); break; default: PhpException.ArgumentValueNotSupported(nameof(option), TryGetOptionName(option)); return(false); } return(true); }
public static ConversionCost ToPhpNumber(PhpValue value) { switch (value.TypeCode) { case PhpTypeCode.Int32: case PhpTypeCode.Long: case PhpTypeCode.Double: return ConversionCost.Pass; case PhpTypeCode.Boolean: return ConversionCost.ImplicitCast; case PhpTypeCode.WritableString: case PhpTypeCode.String: return ConversionCost.LoosingPrecision; case PhpTypeCode.PhpArray: return ConversionCost.Warning; default: return ConversionCost.NoConversion; } }
public ReflectionMethod(Context ctx, PhpValue @class, string name) { __construct(ctx, @class, name); }
/// <summary> /// Sets property value dynamically on the newly instantiated object. /// </summary> protected static void SetProperty(object /*!*/ instance, PhpTypeInfo tinfo, string /*!*/ name, PhpValue value, Context /*!*/ context) { // the property name might encode its visibility and "classification" -> use these // information for suitable property desc lookups FieldAttributes visibility; string type_name; string property_name = Serialization.ParseSerializedPropertyName(name, out type_name, out visibility); var declarer = (type_name == null) ? tinfo : context.GetDeclaredType(type_name, true) ?? tinfo; // try to find a suitable property var property = tinfo.GetDeclaredProperty(property_name); if (property != null && !property.IsStatic && property.IsVisible(declarer.Type.AsType())) { if (property.IsPrivate && declarer != property.ContainingType) { // if certain conditions are met, don't use the handle even if it was found // (this is to precisely mimic the PHP behavior) property = null; } } if (property != null) { property.SetValue(context, instance, value); } else if (tinfo.RuntimeFieldsHolder != null) { // suitable CT field not found -> add it to RT fields // (note: care must be taken so that the serialize(unserialize($x)) round // trip returns $x even if user classes specified in $x are not declared) var runtime_fields = tinfo.GetRuntimeFields(instance); if (runtime_fields == null) { runtime_fields = new PhpArray(1); tinfo.RuntimeFieldsHolder.SetValue(instance, runtime_fields); } runtime_fields[name] = value; } else { throw new ArgumentException(); } }
/// <summary> /// Tries to get or set an option given its PHP name and value. /// </summary> /// <param name="config">Configuration to be read or set.</param> /// <param name="name">The option name.</param> /// <param name="value">The option new value if applicable.</param> /// <param name="action">The action to be taken.</param> /// <param name="error"><B>true</B>, on failure.</param> /// <returns>The option old value.</returns> /// <exception cref="PhpException">The option not supported (Warning).</exception> /// <exception cref="PhpException">The option is read only but action demands write access (Warning).</exception> internal static PhpValue TryGetSet(IPhpConfigurationService config, string name, PhpValue value, IniAction action, out bool error) { Debug.Assert(name != null); error = true; var def = GetOption(name); // option not found: if (def.Gsr == null) { PhpException.Throw(PhpError.Warning, string.Format(Resources.LibResources.unknown_option, name)); return(PhpValue.Null); } // the option is known but not supported: if ((def.Flags & IniFlags.Supported) == 0) { PhpException.Throw(PhpError.Warning, string.Format(Resources.LibResources.option_not_supported, name)); return(PhpValue.Null); } // the option is global thus cannot be changed: if ((def.Flags & IniFlags.Local) == 0 && action != IniAction.Get) { PhpException.Throw(PhpError.Warning, string.Format(Resources.LibResources.option_readonly, name)); return(PhpValue.Null); } error = false; return(def.Gsr(config, name, value, action)); }
PhpValue Iterator.current() => PhpValue.FromClass(_list[_element]);
/// <summary> /// Formats a state of the specified option into <see cref="PhpArray"/>. /// </summary> /// <param name="flags">The option's flag.</param> /// <param name="defaultValue">A default value of the option.</param> /// <param name="localValue">A script local value of the option.</param> /// <returns>An array containig keys <c>"global_value"</c>, <c>"local_value"</c>, <c>"access"</c>.</returns> public static PhpArray FormatOptionState(IniFlags flags, PhpValue defaultValue, PhpValue localValue) { var result = new PhpArray(3); result.Add("global_value", defaultValue); result.Add("local_value", localValue); result.Add("access", (int)((flags & IniFlags.Local) != 0 ? IniAccessability.Local : IniAccessability.Global)); return(result); }
public virtual void offsetUnset(PhpValue index) { throw new NotImplementedException(); }
/// <summary> /// Gets or sets option. /// </summary> public static IPhpCallable GetSet(ref IPhpCallable option, IPhpCallable defaultValue, PhpValue newValue, IniAction action) { var oldValue = option; if (action == IniAction.Set) { option = newValue.AsCallable(default(RuntimeTypeHandle)); } return(oldValue); }
public static string export(PhpValue argument, bool @return = false) { throw new NotImplementedException(); }
public static string ini_alter(Context ctx, string option, PhpValue value) => ini_set(ctx, option, value);
public virtual void __construct(Context ctx, PhpValue @class) { Debug.Assert(_tinfo == null, "Subsequent call not allowed."); _tinfo = ReflectionUtils.ResolvePhpTypeInfo(ctx, @class); }
/// <summary> /// Sets an option on the given cURL session handle. /// </summary> public static bool curl_setopt(CURLResource ch, int option, PhpValue value) => ch.TrySetOption(option, value);
/// <summary> /// Checks whether an object exists in the storage. /// </summary> /// <remarks>Alias for <see cref="contains(object)"/>.</remarks> public virtual bool offsetExists(PhpValue offset) => contains(offset.AsObject());
/// <summary> /// Defines a constant. /// </summary> /// <param name="ctx">Current runtime context.</param> /// <param name="name">The name of the constant. Can be arbitrary string.</param> /// <param name="value">The value of the constant. Can be <B>null</B> or a scalar or array.</param> /// <param name="caseInsensitive">Whether the name is case insensitive.</param> /// <returns>Whether the new constant has been defined.</returns> public static bool define(Context ctx, string name, PhpValue value, bool caseInsensitive = false) => ctx.DefineConstant(name, value, caseInsensitive);
/// <summary> /// Tries to set a driver specific attribute value. /// </summary> /// <param name="attributes">The current attributes collection.</param> /// <param name="attribute">The attribute to set.</param> /// <param name="value">The value.</param> /// <returns>true if value is valid, or false if value can't be set.</returns> public virtual bool TrySetAttribute(Dictionary <PDO.PDO_ATTR, PhpValue> attributes, PDO.PDO_ATTR attribute, PhpValue value) { return(false); }
/// <summary> /// Output WBMP image to browser or file /// </summary> public static bool image2wbmp(Context ctx, PhpResource im, PhpValue to, int threshold = 0) { throw new NotImplementedException(); //return imagesave(ctx, im, filename, (img, stream) => img.SaveAsWirelessBmp(stream)); }
public static ConversionCost ToString(PhpValue value) { switch (value.TypeCode) { case PhpTypeCode.Int32: case PhpTypeCode.Long: case PhpTypeCode.Boolean: case PhpTypeCode.Double: case PhpTypeCode.Object: return ConversionCost.ImplicitCast; case PhpTypeCode.WritableString: return value.WritableString.ContainsBinaryData ? ConversionCost.ImplicitCast : ConversionCost.PassCostly; case PhpTypeCode.String: return ConversionCost.Pass; case PhpTypeCode.PhpArray: return ConversionCost.Warning; default: return ConversionCost.NoConversion; } }
/// <summary> /// Output GD2 image to browser or file /// </summary> public static bool imagegd2(Context ctx, PhpResource im, [Optional] PhpValue to, int chunk_size = 128, int type = IMG_GD2_RAW) { throw new NotImplementedException(); }
public static ConversionCost ToPhpArray(PhpValue value) { switch (value.TypeCode) { case PhpTypeCode.Int32: case PhpTypeCode.Long: case PhpTypeCode.Double: case PhpTypeCode.Boolean: case PhpTypeCode.WritableString: case PhpTypeCode.String: return ConversionCost.Warning; case PhpTypeCode.PhpArray: return ConversionCost.Pass; default: return ConversionCost.NoConversion; } }
protected abstract PhpString CommonSerialize(Context ctx, PhpValue variable, RuntimeTypeHandle caller);