Example #1
0
 /// <summary>
 /// Retrieves name of a variable type.
 /// </summary>
 /// <param name="variable">The variable.</param>
 /// <returns>The string type identifier. See PHP manual for details.</returns>
 public static string gettype(PhpValue variable)
 {
     // works well on references:
     return(PhpVariable.GetTypeName(variable));
 }
Example #2
0
        public virtual object __toString(ScriptContext /*!*/ context)
        {
            if (this.typedesc == null)
            {
                return(false);
            }

            StringBuilder result = new StringBuilder();

            // Interface|Class
            result.Append(this.typedesc.IsInterface ? "Interface [ interface " : "Class [ class ");
            result.Append(this.name);
            result.Append(' ');
            if (this.typedesc.Base != null)
            {
                result.Append("extends ");
                result.Append(this.typedesc.Base.MakeFullName());
                result.Append(' ');
            }
            if (this.typedesc.Interfaces.Length > 0)
            {
                result.Append("implements ");
                result.Append(string.Join(", ", this.typedesc.Interfaces.Select(x => x.MakeFullName())));
                result.Append(' ');
            }
            result.AppendLine("] {");

            // @@ filename
            var fname = this.getFileName(context);

            if (fname is string)
            {
                result.AppendFormat("  @@ {0}\n", (string)fname);
            }

            // Constants
            result.AppendLine();
            result.AppendFormat("  - Constants [{0}] {{\n", this.typedesc.Constants.Count);
            foreach (var cnst in this.typedesc.Constants)
            {
                var cnst_value = cnst.Value.GetValue(context);
                result.AppendFormat("    Constant [ {0} {1} ] {{ {2} }}\n",
                                    PhpVariable.GetTypeName(cnst_value),
                                    cnst.Key.Value,
                                    Core.Convert.ObjectToString(cnst_value));
            }
            result.AppendLine("  }");

            // Static properties
            var static_properties = this.typedesc.Properties.Where(x => x.Value.IsStatic).ToList();

            result.AppendLine();
            result.AppendFormat("  - Static properties [{0}] {{\n", static_properties.Count);
            foreach (var prop in static_properties)
            {
                result.AppendFormat("    Property [ {0} static ${1} ]\n",
                                    VisibilityString(prop.Value.MemberAttributes),
                                    prop.Key.Value);
            }
            result.AppendLine("  }");

            // Static methods
            var static_methods = this.typedesc.Methods.Where(x => x.Value.IsStatic).ToList();

            result.AppendLine();
            result.AppendFormat("  - Static methods [{0}] {{\n", static_methods.Count);
            foreach (var mtd in static_methods)
            {
                result.AppendFormat("    Method [ static {0} method {1} ] {{}}\n",
                                    VisibilityString(mtd.Value.MemberAttributes),
                                    mtd.Key.Value);
                // TODO: @@ fname position
            }
            result.AppendLine("  }");

            // Properties
            var properties = this.typedesc.Properties.Where(x => !x.Value.IsStatic).ToList();

            result.AppendLine();
            result.AppendFormat("  - Properties [{0}] {{\n", properties.Count);
            foreach (var prop in properties)
            {
                result.AppendFormat("    Property [ {0} ${1} ]\n",
                                    VisibilityString(prop.Value.MemberAttributes),
                                    prop.Key.Value);
            }
            result.AppendLine("  }");

            // Methods
            var methods = this.typedesc.Methods.Where(x => !x.Value.IsStatic).ToList();

            result.AppendLine();
            result.AppendFormat("  - Methods [{0}] {{\n", methods.Count);
            foreach (var mtd in static_methods)
            {
                result.AppendFormat("    Method [ {0} method {1} ] {{}}\n",
                                    VisibilityString(mtd.Value.MemberAttributes),
                                    mtd.Key.Value);
                // TODO: @@ fname position
            }
            result.AppendLine("  }");

            // }
            result.AppendLine("}");

            //
            return(result.ToString());
        }
Example #3
0
 public static string GetType(object variable)
 {
     // works well on references:
     return(PhpVariable.GetTypeName(variable));
 }
Example #4
0
        /// <summary>
        /// This function controls various runtime options for the specified FTP stream.
        /// </summary>
        /// <param name="ftp_stream">The link identifier of the FTP connection.</param>
        /// <param name="option">Currently, the following options are supported:FTP_TIMEOUT_SEC,
        /// FTP_AUTOSEEK, FTP_USEPASVADDRESS</param>
        /// <param name="value">This parameter depends on which option is chosen to be altered.</param>
        /// <returns>Returns TRUE if the option could be set; FALSE if not. A warning message will be thrown
        /// if the option is not supported or the passed value doesn't match the expected value for the given option.</returns>
        public static bool ftp_set_option(PhpResource ftp_stream, int option, PhpValue value)
        {
            var resource = ValidateFtpResource(ftp_stream);

            if (resource == null)
            {
                return(false);
            }

            switch (option)
            {
            case FTP_AUTOSEEK:
                if (value.IsBoolean(out var result))
                {
                    resource.Autoseek = result;
                    return(true);
                }
                else
                {
                    PhpException.Throw(PhpError.Warning, Resources.Resources.unexpected_arg_given,
                                       nameof(value), PhpVariable.TypeNameBoolean, PhpVariable.GetTypeName(value));
                    return(false);
                }

            case FTP_TIMEOUT_SEC:
                if (value.IsLong(out var time))
                {
                    if (time <= 0)
                    {
                        PhpException.Throw(PhpError.Warning, Resources.Resources.sleep_seconds_less_zero);
                        return(false);
                    }

                    resource.Client.ReadTimeout    = (int)time * 1000;
                    resource.Client.ConnectTimeout = resource.Client.ReadTimeout;
                    resource.Client.DataConnectionConnectTimeout = resource.Client.ReadTimeout;
                    resource.Client.DataConnectionReadTimeout    = resource.Client.ReadTimeout;
                    return(true);
                }
                else
                {
                    PhpException.Throw(PhpError.Warning, Resources.Resources.unexpected_arg_given,
                                       nameof(value), PhpVariable.TypeNameInteger, PhpVariable.GetTypeName(value));
                    return(false);
                }

            case FTP_USEPASVADDRESS:
                if (value.IsBoolean(out result))
                {
                    resource.UsePASVAddress = result;
                    return(true);
                }
                else
                {
                    PhpException.Throw(PhpError.Warning, Resources.Resources.unexpected_arg_given,
                                       nameof(value), PhpVariable.TypeNameBoolean, PhpVariable.GetTypeName(value));
                    return(false);
                }

            default:
                PhpException.Throw(PhpError.Warning, Resources.Resources.arg_invalid_value, option.ToString(), nameof(option));
                return(false);
            }
        }
Example #5
0
        public static string ObjectHash(object obj)
        {
            DObject dobj = obj as DObject;

            if (dobj == null)
            {
                PhpException.Throw(PhpError.Warning, LibResources.GetString("unexpected_arg_given", 1, DObject.PhpTypeName, PhpVariable.GetTypeName(obj).ToLower()));
                return(null);
            }

            return(dobj.GetHashCode().ToString("x32"));
        }