Search in sources :

Example 26 with ForeachIterator

use of php.runtime.lang.ForeachIterator in project jphp by jphp-compiler.

the class ContextValueProvider method processArray.

protected void processArray(Element property, ArrayMemory array, Set<Integer> used, boolean forObjects) {
    if (array.size() != 0) {
        property.setAttribute("children", "1");
    }
    property.setAttribute("numchildren", String.valueOf(array.size()));
    ForeachIterator iterator = array.foreachIterator(false, false);
    int count = 0;
    while (iterator.next()) {
        if (iterator.getValue().isUndefined()) {
            continue;
        }
        Element value = getProperty(null, iterator.getValue().toValue(), used);
        String key = iterator.getKey().toString();
        if (forObjects) {
            key = key.replace('\0', '*');
            if (key.startsWith("***")) {
                key = key.substring(3);
            }
        }
        value.setAttribute("name", key);
        property.appendChild(value);
        count++;
        if (maxChildren > 0 && count >= maxChildren) {
            break;
        }
    }
}
Also used : ForeachIterator(php.runtime.lang.ForeachIterator) Element(org.w3c.dom.Element)

Example 27 with ForeachIterator

use of php.runtime.lang.ForeachIterator in project jphp by jphp-compiler.

the class PHttpResponse method setRawCookies.

@Signature
public void setRawCookies(ArrayMemory rawCookies) {
    this.rawCookies = rawCookies;
    ArrayMemory cookies = new ArrayMemory();
    ForeachIterator iterator = rawCookies.foreachIterator(false, false);
    while (iterator.next()) {
        cookies.putAsKeyString(iterator.getStringKey(), iterator.getValue().valueOfIndex("value").toImmutable());
    }
    this.cookies = cookies;
}
Also used : ArrayMemory(php.runtime.memory.ArrayMemory) ForeachIterator(php.runtime.lang.ForeachIterator) Signature(php.runtime.annotation.Reflection.Signature)

Example 28 with ForeachIterator

use of php.runtime.lang.ForeachIterator in project jphp by jphp-compiler.

the class ArrayFunctions method recursive_count.

private static int recursive_count(Environment env, TraceInfo trace, ArrayMemory array, Set<Integer> used) {
    ForeachIterator iterator = array.foreachIterator(false, false);
    int size = array.size();
    while (iterator.next()) {
        Memory el = iterator.getValue();
        if (el.isArray()) {
            if (used == null)
                used = new HashSet<>();
            int pointer = el.getPointer();
            if (!used.add(pointer)) {
                env.warning(trace, "recursion detected");
            } else {
                size += recursive_count(env, trace, array, used);
            }
            used.remove(pointer);
        }
    }
    return size;
}
Also used : ForeachIterator(php.runtime.lang.ForeachIterator) Memory(php.runtime.Memory) ArrayMemory(php.runtime.memory.ArrayMemory) LongMemory(php.runtime.memory.LongMemory) ObjectMemory(php.runtime.memory.ObjectMemory) HashSet(java.util.HashSet)

Example 29 with ForeachIterator

use of php.runtime.lang.ForeachIterator in project jphp by jphp-compiler.

the class ContextGetCommand method run.

@Override
public void run(Debugger context, CommandArguments args, Document result) {
    Element response = createResponse(args, result);
    String contextId = args.get("c");
    response.setAttribute("context", contextId);
    ContextValueProvider contextValueProvider = new ContextValueProvider(context, result);
    switch(contextId) {
        case "0":
            DebugTick tick = context.getRegisteredTick();
            ForeachIterator iterator = tick.getLocals().foreachIterator(true, false);
            while (iterator.next()) {
                Memory value = iterator.getValue().toValue();
                if (value.isUndefined()) {
                    continue;
                }
                response.appendChild(contextValueProvider.getProperty(iterator.getKey().toString(), value));
            }
            break;
    }
}
Also used : DebugTick(org.develnext.jphp.debug.impl.DebugTick) ForeachIterator(php.runtime.lang.ForeachIterator) ContextValueProvider(org.develnext.jphp.debug.impl.command.support.ContextValueProvider) Memory(php.runtime.Memory) Element(org.w3c.dom.Element)

Example 30 with ForeachIterator

use of php.runtime.lang.ForeachIterator in project jphp by jphp-compiler.

the class ItemsUtils method has.

@Signature({ @Arg(value = "collection", type = HintType.TRAVERSABLE), @Arg(value = "value"), @Arg(value = "strict", optional = @Optional("false")) })
public static Memory has(Environment env, Memory... args) {
    ForeachIterator iterator = args[0].getNewIterator(env);
    if (iterator == null) {
        return Memory.NULL;
    }
    Memory needle = args[1];
    boolean strict = args[2].toBoolean();
    while (iterator.next()) {
        if (strict) {
            if (needle.identical(iterator.getValue()))
                return Memory.TRUE;
        } else {
            if (needle.equal(iterator.getValue()))
                return Memory.TRUE;
        }
    }
    return Memory.FALSE;
}
Also used : ForeachIterator(php.runtime.lang.ForeachIterator) Memory(php.runtime.Memory) ArrayMemory(php.runtime.memory.ArrayMemory) LongMemory(php.runtime.memory.LongMemory) KeyValueMemory(php.runtime.memory.KeyValueMemory) ObjectMemory(php.runtime.memory.ObjectMemory)

Aggregations

ForeachIterator (php.runtime.lang.ForeachIterator)100 ArrayMemory (php.runtime.memory.ArrayMemory)49 Memory (php.runtime.Memory)47 LongMemory (php.runtime.memory.LongMemory)22 KeyValueMemory (php.runtime.memory.KeyValueMemory)18 ReferenceMemory (php.runtime.memory.ReferenceMemory)16 Invoker (php.runtime.invoke.Invoker)12 ObjectMemory (php.runtime.memory.ObjectMemory)12 IObject (php.runtime.lang.IObject)9 ArrayKeyMemory (php.runtime.memory.helper.ArrayKeyMemory)6 ArrayValueMemory (php.runtime.memory.helper.ArrayValueMemory)6 ShortcutMemory (php.runtime.memory.helper.ShortcutMemory)5 Signature (php.runtime.annotation.Reflection.Signature)4 StringMemory (php.runtime.memory.StringMemory)4 File (java.io.File)3 HashSet (java.util.HashSet)3 Element (org.w3c.dom.Element)3 FastMethod (php.runtime.annotation.Runtime.FastMethod)3 ClassEntity (php.runtime.reflection.ClassEntity)3 PropertyEntity (php.runtime.reflection.PropertyEntity)3