Example #1
0
        public virtual void __construct(Traversable iterator, string classname = null)
        {
            if (classname != null)
            {
                //var downcast = ctx.ResolveType(PhpVariable.AsString(classname), null, this.iterator.TypeDesc, null, ResolveTypeFlags.ThrowErrors);

                PhpException.ArgumentValueNotSupported(nameof(classname), classname);
                throw new NotImplementedException();
            }

            _iterator   = iterator;
            _valid      = false;
            _enumerator = null;

            if (iterator is Iterator)
            {
                // ok
            }
            else
            {
                PhpException.InvalidArgument(nameof(iterator));
            }

            //rewind(context);  // not in PHP, performance reasons (foreach causes rewind() itself)
        }
Example #2
0
        internal protected void rewindImpl()
        {
            if (_iterator != null)
            {
                // we can make use of standard foreach enumerator
                _enumerator = Operators.GetForeachEnumerator(_iterator, true, default(RuntimeTypeHandle));

                //
                _valid = _enumerator.MoveNext();
            }
        }
Example #3
0
        public virtual void rewind()
        {
            if (_iterator != null)
            {
                // we can make use of standard foreach enumerator
                _enumerator = Operators.GetForeachEnumerator(_iterator, true, default(RuntimeTypeHandle));

                //
                _valid = _enumerator.MoveNext();
            }
        }
Example #4
0
        /// <summary>
        /// Creates array from PHP enumerator.
        /// </summary>
        internal static PhpArray Create(IPhpEnumerator phpenumerator)
        {
            Debug.Assert(phpenumerator != null);

            var arr = new PhpArray();

            while (phpenumerator.MoveNext())
            {
                var current = phpenumerator.Current;
                arr.Add(current.Key.ToIntStringKey(), current.Value);
            }

            //
            return(arr);
        }