Beispiel #1
0
        public PhpAlias GetAlias(ref PhpValue value, Context ctx, Type classContext)
        {
            var      arr = PhpValue.EnsureArray(ref value);
            PhpValue tmp;

            switch (Next.Operation)
            {
            case RuntimeChainOperation.ArrayItem:
                tmp = PhpValue.Create(arr.EnsureItemArray(Key));
                break;

            case RuntimeChainOperation.Property:
                tmp = PhpValue.FromClass(arr.EnsureItemObject(Key));
                break;

            case RuntimeChainOperation.End:
                return(arr.EnsureItemAlias(Key));

            default:
                throw new InvalidOperationException();
            }

            //
            return(Next.GetAlias(ref tmp, ctx, classContext));
        }
Beispiel #2
0
        public PhpAlias GetAlias(ref PhpValue value, Context ctx, Type classContext)
        {
            var result = PhpValue.Null;
            var alias  = Next.GetAlias(ref result, ctx, classContext);

            PhpValue.EnsureArray(ref value).AddValue(result);

            return(alias);
        }
Beispiel #3
0
        public PhpAlias GetAlias(ref PhpValue value, Context ctx, Type classContext)
        {
            PhpValue tmp;

            if (value.AsObject() is ArrayAccess arrayaccess)
            {
                // special case for ArrayAccess avoids conversion to IntStringKey

                tmp = arrayaccess.offsetGet(Key);

                switch (Next.Operation)
                {
                case RuntimeChainOperation.ArrayItem:
                    tmp = PhpValue.EnsureAlias(ref tmp);
                    break;

                case RuntimeChainOperation.Property:
                    tmp = PhpValue.FromClass(PhpValue.EnsureObject(ref tmp));
                    break;

                case RuntimeChainOperation.End:
                    return(PhpValue.EnsureAlias(ref tmp));

                default:
                    throw new InvalidOperationException();
                }
            }
            else
            {
                var arr = PhpValue.EnsureArray(ref value);

                switch (Next.Operation)
                {
                case RuntimeChainOperation.ArrayItem:
                    tmp = PhpValue.Create(arr.EnsureItemArray(Key));
                    break;

                case RuntimeChainOperation.Property:
                    tmp = PhpValue.FromClass(arr.EnsureItemObject(Key));
                    break;

                case RuntimeChainOperation.End:
                    return(arr.EnsureItemAlias(Key));

                default:
                    throw new InvalidOperationException();
                }
            }

            //
            return(Next.GetAlias(ref tmp, ctx, classContext));
        }
Beispiel #4
0
        ref PhpValue Ensure(ref PhpValue value)
        {
            Debug.Assert(Next.Operation != RuntimeChainOperation.End);

            switch (Next.Operation)
            {
            case RuntimeChainOperation.Value:
                break;

            case RuntimeChainOperation.Property:
                value = PhpValue.FromClass(PhpValue.EnsureObject(ref value));
                break;

            case RuntimeChainOperation.ArrayItem:
                value = PhpValue.Create(PhpValue.EnsureArray(ref value));
                break;

            default:
                throw new InvalidOperationException();
            }

            //
            return(ref value);
        }
Beispiel #5
0
        public virtual IPhpArray EnsureArray(Context ctx, object instance)
        {
            var value = GetValue(ctx, instance);

            return(PhpValue.EnsureArray(ref value));
        }