Exemplo n.º 1
0
 public override PhpValue ToPhpValue() => PhpValue.FromClass(_lazyResolved);
 PhpArray IPhpConvertible.ToArray() => PhpArray.New(PhpValue.FromClass(this));
Exemplo n.º 3
0
 public static PhpCallback Create(object targetInstance, string methodName) => new ArrayCallback(PhpValue.FromClass(targetInstance), (PhpValue)methodName);
 object IPhpConvertible.ToClass() => new stdClass(PhpValue.FromClass(this));
Exemplo n.º 5
0
 public override object EnsureObject(ref PhpValue me) => PhpValue.FromClass(ToClass(ref me)); // me is not changed
Exemplo n.º 6
0
        public static PhpCallback Create(PhpValue item1, PhpValue item2, RuntimeTypeHandle callerCtx = default(RuntimeTypeHandle)) => new ArrayCallback(item1.GetValue(), item2.GetValue(), callerCtx);  // creates callback to an array, array entries must be dereferenced so they cannot be changed gainst

        public static PhpCallback Create(object targetInstance, string methodName, RuntimeTypeHandle callerCtx = default(RuntimeTypeHandle)) => new ArrayCallback(PhpValue.FromClass(targetInstance), (PhpValue)methodName, callerCtx);
Exemplo n.º 7
0
 public void Define(string name, Func <PhpValue> getter) => Define(name, PhpValue.FromClass(getter));
Exemplo n.º 8
0
        public static int Compare(object x, PhpValue y)
        {
            Debug.Assert(x != null);

            if (x.Equals(y.Object))
            {
                return(0);
            }
            if (x is IPhpComparable)
            {
                return(((IPhpComparable)x).Compare(y));
            }
            if (y.Object is IPhpComparable)
            {
                return(-((IPhpComparable)y.Object).Compare(PhpValue.FromClass(x)));
            }
            if (x is decimal xd)
            {
                return(Compare((double)xd, y));
            }

            switch (y.TypeCode)
            {
            case PhpTypeCode.Null:
                return(1);

            case PhpTypeCode.Boolean:
                return(y.Boolean ? 0 : 1);

            case PhpTypeCode.Long:
                // Notice: Object of class {0} could not be converted to int
                PhpException.Throw(PhpError.Notice, string.Format(Resources.ErrResources.object_could_not_be_converted, PhpVariable.GetDebugType(y), PhpVariable.TypeNameInt));
                return(Compare(1L, y.Long));

            case PhpTypeCode.Double:
                // Notice: Object of class {0} could not be converted to float
                PhpException.Throw(PhpError.Notice, string.Format(Resources.ErrResources.object_could_not_be_converted, PhpVariable.GetDebugType(y), PhpVariable.TypeNameFloat));
                return(Compare(1L, y.Long));

            case PhpTypeCode.String:
                return(-CompareStringToObject(y.String, x));

            case PhpTypeCode.Object:
                Debug.Assert(y.Object != null);
                var result = CompareObjects(x, y.Object, PhpComparer.Default, out var incomparable);
                if (incomparable)
                {
                    PhpException.Throw(PhpError.Warning,
                                       Resources.ErrResources.incomparable_objects_compared_exception,
                                       x.GetPhpTypeInfo().Name,
                                       y.Object.GetPhpTypeInfo().Name);
                    return(1);
                }
                return(result);

            case PhpTypeCode.Alias:
                return(Compare(x, y.Alias.Value));

            default:
                PhpException.Throw(PhpError.Notice,
                                   string.Format(Resources.ErrResources.incomparable_objects_compared_exception,
                                                 x.GetPhpTypeInfo().Name,
                                                 PhpVariable.GetDebugType(y)));

                return(0);
            }
        }