Example #1
0
        /// <summary>
        /// Compares two PHP versions.
        /// </summary>
        /// <param name="ver1">The first version.</param>
        /// <param name="ver2">The second version.</param>
        /// <returns>The result of comparison (-1,0,+1).</returns>
        public static int Compare(string ver1, string ver2)
        {
            string[] v1 = VersionToArray(ver1);
            string[] v2 = VersionToArray(ver2);
            int      result;

            for (int i = 0; i < Math.Max(v1.Length, v2.Length); i++)
            {
                string item1 = (i < v1.Length) ? v1[i] : " ";
                string item2 = (i < v2.Length) ? v2[i] : " ";

                if (Char.IsDigit(item1[0]) && Char.IsDigit(item2[0]))
                {
                    result = PhpComparer.CompareInteger(Convert.StringToInteger(v1[i]), Convert.StringToInteger(item2));
                }
                else
                {
                    result = CompareParts(Char.IsDigit(item1[0]) ? "#" : item1, Char.IsDigit(item2[0]) ? "#" : item2);
                }

                if (result != 0)
                {
                    return(result);
                }
            }

            return(0);
        }
Example #2
0
        /// <summary>
        /// Finds the specified autoload function list element.
        /// </summary>
        /// <param name="context">Current script context.</param>
        /// <param name="autoloadFunction">The PHP representation of callback function to find in list of SPL autoload functions.</param>
        /// <returns>List node or null if such a functions does not exist in the list.</returns>
        private static LinkedListNode <PhpCallback> FindAutoloadFunction(ScriptContext /*!*/ context, object autoloadFunction)
        {
            Debug.Assert(context != null);

            if (context.IsSplAutoloadEnabled)
            {
                for (var node = context.SplAutoloadFunctions.First; node != null; node = node.Next)
                {
                    if (PhpComparer.CompareEq(node.Value.ToPhpRepresentation(), autoloadFunction))
                    {
                        return(node);
                    }
                }
            }

            return(null);
        }
Example #3
0
        public static bool CheckAssertion(
            object assertion,
            string code,
            ScriptContext context,
            string callerRelativeSourcePath,
            int line,
            int column,
            NamingContext namingContext)
        {
            // checks assertion:
            if (assertion != null && !PhpComparer./*Default.*/ CompareEq(assertion, false))
            {
                return(true);
            }

            // calls user callback:
            if (context.Config.Assertion.Callback != null)
            {
                ApplicationConfiguration app_config = Configuration.Application;
                FullPath full_path = new FullPath(callerRelativeSourcePath, app_config.Compiler.SourceRoot);
                context.Config.Assertion.Callback.Invoke(full_path.FullFileName, line, code);
            }

            // reports a warning if required:
            if (context.Config.Assertion.ReportWarning)
            {
                PhpException.Throw(PhpError.Warning, CoreResources.GetString("assertion_failed", code));
            }

            // terminates script execution if required:
            if (context.Config.Assertion.Terminate)
            {
                throw new ScriptDiedException(0);
            }

            // assertion failed:
            return(false);
        }
Example #4
0
        internal override object Evaluate(object leftValue, object rightValue)
        {
            switch (operation)
            {
            case Operations.Xor:
                return(Convert.ObjectToBoolean(leftValue) ^ Convert.ObjectToBoolean(rightValue));

            case Operations.Or:
                return(Convert.ObjectToBoolean(leftValue) || Convert.ObjectToBoolean(rightValue));

            case Operations.And:
                return(Convert.ObjectToBoolean(leftValue) && Convert.ObjectToBoolean(rightValue));

            case Operations.BitOr:
                return(Operators.BitOperation(leftValue, rightValue, Operators.BitOp.Or));

            case Operations.BitXor:
                return(Operators.BitOperation(leftValue, rightValue, Operators.BitOp.Xor));

            case Operations.BitAnd:
                return(Operators.BitOperation(leftValue, rightValue, Operators.BitOp.And));

            case Operations.Equal:
                return(PhpComparer./*Default.*/ CompareEq(leftValue, rightValue));

            case Operations.NotEqual:
                return(!PhpComparer./*Default.*/ CompareEq(leftValue, rightValue));

            case Operations.Identical:
                return(Operators.StrictEquality(leftValue, rightValue));

            case Operations.NotIdentical:
                return(!Operators.StrictEquality(leftValue, rightValue));

            case Operations.LessThan:
                return(PhpComparer.Default.Compare(leftValue, rightValue) < 0);

            case Operations.GreaterThan:
                return(PhpComparer.Default.Compare(leftValue, rightValue) > 0);

            case Operations.LessThanOrEqual:
                return(PhpComparer.Default.Compare(leftValue, rightValue) <= 0);

            case Operations.GreaterThanOrEqual:
                return(PhpComparer.Default.Compare(leftValue, rightValue) >= 0);

            case Operations.ShiftRight:
                return(Operators.ShiftRight(leftValue, rightValue));                        // int

            case Operations.ShiftLeft:
                return(Operators.ShiftLeft(leftValue, rightValue));                         // int

            case Operations.Add:
                return(Operators.Add(leftValue, rightValue));

            case Operations.Sub:
                return(Operators.Subtract(leftValue, rightValue));

            case Operations.Mul:
                return(Operators.Multiply(leftValue, rightValue));

            case Operations.Div:
                return(Operators.Divide(leftValue, rightValue));

            case Operations.Mod:
                return(Operators.Remainder(leftValue, rightValue));

            case Operations.Concat:
                return(Operators.Concat(leftValue, rightValue));

            default:
                throw null;
            }
        }