Пример #1
0
 /// <summary>
 /// Calls by the Class Library methods which need variables but get a <b>null</b> reference.
 /// </summary>
 public static void NeedsVariables()
 {
     Throw(PhpError.Warning, CoreResources.GetString("function_needs_variables"));
 }
Пример #2
0
 /// <summary>
 /// Invalid argument error.
 /// </summary>
 /// <param name="argument">The name of the argument being invalid.</param>
 public static void InvalidArgument(string argument)
 {
     Throw(PhpError.Warning, CoreResources.GetString("invalid_argument", argument));
 }
Пример #3
0
 /// <summary>
 /// Argument null error. Thrown when argument can't be null but it is.
 /// </summary>
 /// <param name="argument">The name of the argument.</param>
 public static void ArgumentNull(string argument)
 {
     Throw(PhpError.Warning, CoreResources.GetString("argument_null", argument));
 }
Пример #4
0
        /// <summary>
        /// Returns names and values of properties whose names have been returned by <c>__sleep</c>.
        /// </summary>
        /// <param name="instance">The instance being serialized.</param>
        /// <param name="sleepResult">The array returned by <c>__sleep</c>.</param>
        /// <param name="context">Current <see cref="ScriptContext"/>.</param>
        /// <returns>Name-value pairs. Names are properly formatted for serialization.</returns>
        /// <exception cref="PhpException">Property of the name returned from <c>__sleep</c> does not exist.</exception>
        /// <remarks>
        /// This method returns exactly <paramref name="sleepResult"/>'s <see cref="PhpHashtable.Count"/> items.
        /// </remarks>
        public static IEnumerable <KeyValuePair <string, object> > EnumerateSerializableProperties(
            DObject /*!*/ instance,
            PhpArray /*!*/ sleepResult,
            ScriptContext /*!*/ context)
        {
            foreach (object item in sleepResult.Values)
            {
                PhpMemberAttributes visibility;
                string name = PHP.Core.Convert.ObjectToString(item);
                string declaring_type_name;
                string property_name = ParsePropertyName(name, out declaring_type_name, out visibility);

                DTypeDesc declarer;
                if (declaring_type_name == null)
                {
                    declarer = instance.TypeDesc;
                }
                else
                {
                    declarer = context.ResolveType(declaring_type_name);
                    if (declarer == null)
                    {
                        // property name refers to an unknown class -> value will be null
                        yield return(new KeyValuePair <string, object>(name, null));

                        continue;
                    }
                }

                // obtain the property desc and decorate the prop name according to its visibility and declaring class
                DPropertyDesc property;
                if (instance.TypeDesc.GetProperty(new VariableName(property_name), declarer, out property) ==
                    GetMemberResult.OK && !property.IsStatic)
                {
                    if ((Enums.VisibilityEquals(visibility, property.MemberAttributes) &&
                         visibility != PhpMemberAttributes.Public)
                        ||
                        (visibility == PhpMemberAttributes.Private &&
                         declarer != property.DeclaringType))
                    {
                        // if certain conditions are met, serialize the property as null
                        // (this is to precisely mimic the PHP behavior)
                        yield return(new KeyValuePair <string, object>(name, null));

                        continue;
                    }
                    name = FormatPropertyName(property, property_name);
                }
                else
                {
                    property = null;
                }

                // obtain the property value
                object val = null;

                if (property != null)
                {
                    val = property.Get(instance);
                }
                else if (instance.RuntimeFields == null || !instance.RuntimeFields.TryGetValue(name, out val))
                {
                    // this is new in PHP 5.1
                    PhpException.Throw(PhpError.Notice, CoreResources.GetString("sleep_returned_bad_field", name));
                }

                yield return(new KeyValuePair <string, object>(name, val));
            }
        }
Пример #5
0
 internal InvalidCallContextDataException(string slot)
     : base(CoreResources.GetString("invalid_call_context_data", slot))
 {
 }
Пример #6
0
 public static void MethodNotAccessible(string className, string methodName, string context, bool isProtected)
 {
     PhpException.Throw(PhpError.Error, CoreResources.GetString(
                            isProtected ? "protected_method_called" : "private_method_called", className, methodName, context));
 }
Пример #7
0
 public static void NoSuitableOverload(string className, string /*!*/ methodName)
 {
     PhpException.Throw(PhpError.Error, CoreResources.GetString(
                            (className != null) ? "no_suitable_method_overload" : "no_suitable_function_overload",
                            className, methodName));
 }
Пример #8
0
 public static void CannotReassignThis()
 {
     Throw(PhpError.Error, CoreResources.GetString("cannot_reassign_this"));
 }
Пример #9
0
 public static void InvalidArgumentType(string argName, string typeName)
 {
     Throw(PhpError.Error, CoreResources.GetString("invalid_argument_type", argName, typeName));
 }
Пример #10
0
 public static void InvalidBreakLevelCount(int levelCount)
 {
     Throw(PhpError.Error, CoreResources.GetString("invalid_break_level_count", levelCount));
 }
Пример #11
0
 public static void UndefinedVariable(string name)
 {
     Throw(PhpError.Notice, CoreResources.GetString("undefined_variable", name));
 }
Пример #12
0
 public static void InvalidForeachArgument()
 {
     Throw(PhpError.Warning, CoreResources.GetString("invalid_foreach_argument"));
 }
Пример #13
0
 public static void UnsupportedOperandTypes()
 {
     PhpException.Throw(PhpError.Error, CoreResources.GetString("unsupported_operand_types"));
 }
Пример #14
0
 /// <summary>
 /// The value of an argument is not invalid but unsupported.
 /// </summary>
 /// <param name="argument">The argument which value is unsupported.</param>
 /// <param name="value">The value which is unsupported.</param>
 public static void ArgumentValueNotSupported(string argument, object value)
 {
     Throw(PhpError.Warning, CoreResources.GetString("argument_value_not_supported", value, argument));
 }
Пример #15
0
 public static void ConstantNotAccessible(string className, string constName, string context, bool isProtected)
 {
     PhpException.Throw(PhpError.Error, CoreResources.GetString(
                            isProtected ? "protected_constant_accessed" : "private_constant_accessed", className, constName, context));
 }
Пример #16
0
 /// <summary>
 /// Array operators reports this error if an value of illegal type is used for indexation.
 /// </summary>
 public static void IllegalOffsetType()
 {
     Throw(PhpError.Warning, CoreResources.GetString("illegal_offset_type"));
 }
Пример #17
0
 public static void PropertyNotAccessible(string className, string fieldName, string context, bool isProtected)
 {
     PhpException.Throw(PhpError.Error, CoreResources.GetString(
                            isProtected ? "protected_property_accessed" : "private_property_accessed", className, fieldName, context));
 }
Пример #18
0
 /// <summary>
 /// Array does not contain given <paramref name="key"/>.
 /// </summary>
 /// <param name="key">Key which was not found in the array.</param>
 public static void UndefinedOffset(object key)
 {
     Throw(PhpError.Notice, CoreResources.GetString("undefined_offset", key));
 }
Пример #19
0
 public static void CannotInstantiateType(string typeName, bool isInterface)
 {
     PhpException.Throw(PhpError.Error, CoreResources.GetString(
                            isInterface ? "interface_instantiated" : "abstract_class_instantiated", typeName));
 }
Пример #20
0
 public static void ThisUsedOutOfObjectContext()
 {
     PhpException.Throw(PhpError.Error, CoreResources.GetString("this_used_out_of_object"));
 }
Пример #21
0
 public static void PropertyTypeMismatch(string /*!*/ className, string /*!*/ propertyName)
 {
     PhpException.Throw(PhpError.Error, CoreResources.GetString("property_type_mismatch",
                                                                className, propertyName));
 }
Пример #22
0
 public static void UndeclaredStaticProperty(string className, string fieldName)
 {
     PhpException.Throw(PhpError.Error, CoreResources.GetString("undeclared_static_property_accessed", className, fieldName));
 }
Пример #23
0
        /// <summary>
        /// Runs the compiler with specified options.
        /// </summary>
        /// <param name="args">Command line arguments.</param>
        /// <returns>Whether the compilation was successful.</returns>
        public bool Compile(List <string> /*!*/ args)
        {
            if (args == null)
            {
                throw new ArgumentNullException("args");
            }

            TextErrorSink errorSink = null;

            // processes arguments:
            try
            {
                try
                {
                    commandLineParser.Parse(args);
                }
                finally
                {
                    if (commandLineParser.Quiet)
                    {
                        output = errors = TextWriter.Null;
                    }
                    else if (commandLineParser.RedirectErrors)
                    {
                        output = errors = Console.Out;
                    }
                    else
                    {
                        output = Console.Out;
                        errors = Console.Error;
                    }

                    errorSink = new TextErrorSink(errors);

                    ShowLogo();

                    if (commandLineParser.ShowHelp)
                    {
                        ShowHelp();
                    }
                    else
                    {
                        DumpArguments(args);
                    }
                }
            }
            catch (InvalidCommandLineArgumentException e)
            {
                e.Report(errorSink);
                return(false);
            }

            if (commandLineParser.ShowHelp)
            {
                return(true);
            }

            // allow loading of all assemblies in /Bin directory by their FullName
            HandleAssemblies(Path.Combine(commandLineParser.Parameters.SourceRoot, "Bin"));

            //
            ApplicationContext.DefineDefaultContext(false, true, false);
            ApplicationContext app_context = ApplicationContext.Default;

            CompilerConfiguration compiler_config;

            // loads entire configuration:
            try
            {
                if (commandLineParser.Parameters.ConfigPaths.Count == 0)
                {
                    // Add config files for known targets
                    switch (commandLineParser.Parameters.Target)
                    {
                    case ApplicationCompiler.Targets.Web:
                        if (File.Exists("web.config"))
                        {
                            commandLineParser.Parameters.ConfigPaths.Add(new FullPath("web.config"));
                        }
                        break;

                    case ApplicationCompiler.Targets.WinApp:
                        if (File.Exists("app.config"))
                        {
                            commandLineParser.Parameters.ConfigPaths.Add(new FullPath("app.config"));
                        }
                        break;
                    }
                }
                compiler_config = ApplicationCompiler.LoadConfiguration(app_context,
                                                                        commandLineParser.Parameters.ConfigPaths, output);

                commandLineParser.Parameters.ApplyToConfiguration(compiler_config);
            }
            catch (ConfigurationErrorsException e)
            {
                if (commandLineParser.Verbose)
                {
                    output.WriteLine(CoreResources.GetString("reading_configuration") + ":");
                    output.WriteLine();

                    if (!String.IsNullOrEmpty(e.Filename))                     // Mono puts here null
                    {
                        output.WriteLine(FileSystemUtils.ReadFileLine(e.Filename, e.Line).Trim());
                        output.WriteLine();
                    }
                }

                errorSink.AddConfigurationError(e);
                return(false);
            }

            // load referenced assemblies:
            try
            {
                try
                {
                    app_context.AssemblyLoader.Load(commandLineParser.Parameters.References);
                }
                finally
                {
                    if (commandLineParser.Verbose)
                    {
                        DumpLoadedLibraries();
                    }
                }
            }
            catch (ConfigurationErrorsException e)
            {
                errorSink.AddConfigurationError(e);
                return(false);
            }

            output.WriteLine(CoreResources.GetString("performing_compilation") + " ...");

            try
            {
                CommandLineParser p = commandLineParser;
                Statistics.DrawGraph = p.DrawInclusionGraph;

                errorSink.DisabledGroups        = compiler_config.Compiler.DisabledWarnings;
                errorSink.DisabledWarnings      = compiler_config.Compiler.DisabledWarningNumbers;
                errorSink.TreatWarningsAsErrors = compiler_config.Compiler.TreatWarningsAsErrors;

                // initializes log:
                Debug.ConsoleInitialize(Path.GetDirectoryName(p.Parameters.OutPath));

                new ApplicationCompiler().Compile(app_context, compiler_config, errorSink, p.Parameters);
            }
            catch (InvalidSourceException e)
            {
                e.Report(errorSink);
                return(false);
            }
            catch (Exception e)
            {
                errorSink.AddInternalError(e);
                return(false);
            }

            var errorscount  = errorSink.ErrorCount + errorSink.FatalErrorCount;
            var warningcount = errorSink.WarningCount + errorSink.WarningAsErrorCount;

            output.WriteLine();
            output.WriteLine("Build complete -- {0} error{1}, {2} warning{3}.",
                             errorscount, (errorscount == 1) ? "" : "s",
                             warningcount, (warningcount == 1) ? "" : "s");

            return(!errorSink.AnyError);
        }
Пример #24
0
 public static void StaticPropertyUnset(string className, string fieldName)
 {
     PhpException.Throw(PhpError.Error, CoreResources.GetString("static_property_unset", className, fieldName));
 }
Пример #25
0
 public InvalidMethodImplementationException(string methodName)
     : base(CoreResources.GetString("invalid_method_implementation", methodName))
 {
 }
Пример #26
0
 public static void UndefinedMethodCalled(string className, string methodName)
 {
     PhpException.Throw(PhpError.Error, CoreResources.GetString("undefined_method_called", className, methodName));
 }
Пример #27
0
 /// <summary>
 /// Invalid argument error with a description of a reason.
 /// </summary>
 /// <param name="argument">The name of the argument being invalid.</param>
 /// <param name="message">The message - what is wrong with the argument. Must contain "{0}" which is replaced by argument's name.
 /// </param>
 public static void InvalidArgument(string argument, string message)
 {
     Throw(PhpError.Warning, String.Format(CoreResources.GetString("invalid_argument_with_message") + message, argument));
 }
Пример #28
0
 public static void AbstractMethodCalled(string className, string methodName)
 {
     PhpException.Throw(PhpError.Error, CoreResources.GetString("abstract_method_called", className, methodName));
 }
Пример #29
0
 /// <summary>
 /// Reference argument null error. Thrown when argument which is passed by reference is null.
 /// </summary>
 /// <param name="argument">The name of the argument.</param>
 public static void ReferenceNull(string argument)
 {
     Throw(PhpError.Error, CoreResources.GetString("reference_null", argument));
 }
Пример #30
0
        ///// <summary>
        ///// Called library function is deprecated.
        ///// </summary>
        //public static void FunctionDeprecated()
        //{
        //    ErrorStackInfo info = PhpStackTrace.TraceErrorFrame(ScriptContext.CurrentContext);
        //    FunctionDeprecated(info.LibraryCaller ? info.Caller : null);
        //}

        /// <summary>
        /// Called library function is deprecated.
        /// </summary>
        public static void FunctionDeprecated(string functionName)
        {
            Throw(PhpError.Deprecated, CoreResources.GetString("function_is_deprecated", functionName));
        }