Search in sources :

Example 31 with ForeachIterator

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

the class PrintR method printArray.

@Override
protected void printArray(ArrayMemory value, int level, Set<Integer> used) {
    writeArrayHeader();
    if (used.contains(value.getPointer())) {
        printer.write(" *RECURSION*");
    } else {
        printer.write(StringUtils.repeat(' ', level * PRINT_INDENT));
        writeOpen();
        level += 1;
        used.add(value.getPointer());
        ForeachIterator iterator = value.foreachIterator(false, false);
        int i = 0;
        int size = value.size();
        while (iterator.next()) {
            Memory el = iterator.getValue();
            if (el == Memory.UNDEFINED)
                continue;
            printer.write(StringUtils.repeat(' ', level * PRINT_INDENT));
            Memory key = iterator.getMemoryKey();
            printer.write('[');
            printer.write(key.toString());
            printer.write("] => ");
            print(el, level + 1, used);
            writeSeparator(i == size - 1);
            i++;
        }
        level -= 1;
        printer.write(StringUtils.repeat(' ', level * PRINT_INDENT));
        writeClose();
        used.remove(value.getPointer());
    }
}
Also used : ForeachIterator(php.runtime.lang.ForeachIterator) Memory(php.runtime.Memory)

Example 32 with ForeachIterator

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

the class VarDump method printObject.

@Override
protected void printObject(ObjectMemory value, int level, Set<Integer> used) {
    ClassEntity classEntity = value.getReflection();
    if (used.contains(value.getPointer())) {
        printer.write("*RECURSION*\n");
    } else {
        ArrayMemory arr;
        if (classEntity.methodMagicDebugInfo != null) {
            try {
                Memory tmp = env.invokeMethod(value.value, classEntity.methodMagicDebugInfo.getName());
                if (tmp.isArray()) {
                    arr = tmp.toValue(ArrayMemory.class);
                } else {
                    arr = new ArrayMemory();
                }
            } catch (RuntimeException e) {
                throw e;
            } catch (Throwable throwable) {
                throw new RuntimeException(throwable);
            }
        } else
            arr = value.getProperties();
        printer.write("object(");
        printer.write(classEntity.getName());
        printer.write(")#" + value.getPointer());
        printer.write(" (" + arr.size() + ") {\n");
        level += 1;
        used.add(value.getPointer());
        if (classEntity.methodMagicDebugInfo == null) {
            for (PropertyEntity entity : classEntity.getProperties()) {
                if (entity.getGetter() != null && !entity.isHiddenInDebugInfo()) {
                    printer.write(StringUtils.repeat(' ', level * PRINT_INDENT));
                    printer.write("[\"");
                    printer.write(entity.getName());
                    printer.write('"');
                    printer.write(":getter]=>\n");
                    printer.write(StringUtils.repeat(' ', level * PRINT_INDENT));
                    try {
                        print(entity.getValue(env, TraceInfo.UNKNOWN, value.value), level, used);
                    } catch (RuntimeException e) {
                        throw e;
                    } catch (Throwable throwable) {
                        throw new RuntimeException(throwable);
                    }
                }
            }
        }
        ForeachIterator iterator = arr.foreachIterator(false, false);
        while (iterator.next()) {
            printer.write(StringUtils.repeat(' ', level * PRINT_INDENT));
            Memory key = iterator.getMemoryKey();
            printer.write('[');
            if (key.isString()) {
                String realKey = key.toString();
                int pos;
                Modifier modifier = Modifier.PUBLIC;
                String className = "";
                if ((pos = realKey.lastIndexOf("\0")) > -1) {
                    if (realKey.startsWith("\0*\0")) {
                        modifier = Modifier.PROTECTED;
                    } else {
                        modifier = Modifier.PRIVATE;
                        className = realKey.substring(1, pos);
                    }
                    realKey = realKey.substring(pos + 1);
                }
                printer.write('"');
                printer.write(realKey);
                printer.write('"');
                switch(modifier) {
                    case PRIVATE:
                        printer.write(":\"" + className + "\":private");
                        break;
                    case PROTECTED:
                        printer.write(":protected");
                }
            } else {
                printer.write(key.toString());
            }
            printer.write("]=>\n");
            printer.write(StringUtils.repeat(' ', level * PRINT_INDENT));
            print(iterator.getValue(), level, used);
        //printer.write('\n');
        }
        level -= 1;
        printer.write(StringUtils.repeat(' ', level * PRINT_INDENT));
        printer.write("}\n");
        used.remove(value.getPointer());
    }
}
Also used : ClassEntity(php.runtime.reflection.ClassEntity) ForeachIterator(php.runtime.lang.ForeachIterator) PropertyEntity(php.runtime.reflection.PropertyEntity) Memory(php.runtime.Memory) Modifier(php.runtime.common.Modifier)

Example 33 with ForeachIterator

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

the class VarExport method printArray.

protected void printArray(ArrayMemory value, int level, Set<Integer> used, boolean stripNulls) {
    if (!used.add(value.getPointer())) {
        recursionExists = true;
        printNull();
    } else {
        printer.write(StringUtils.repeat(' ', level * PRINT_INDENT));
        printer.write("array (\n");
        ForeachIterator iterator = value.foreachIterator(false, false);
        level += 1;
        while (iterator.next()) {
            Memory el = iterator.getValue();
            if (el == Memory.UNDEFINED)
                continue;
            printer.write(StringUtils.repeat(' ', level * PRINT_INDENT));
            Memory key = iterator.getMemoryKey();
            if (key.isString()) {
                String k = key.toString();
                if (stripNulls) {
                    int pos = k.lastIndexOf('\0');
                    if (pos > -1)
                        k = k.substring(pos + 1);
                }
                printString(new StringMemory(k));
            } else {
                printer.write(key.toString());
            }
            printer.write(" =>");
            if (el.isArray()) {
                if (!used.contains(el.getPointer()))
                    printer.write("\n");
                else
                    printer.write(" ");
                print(el, level, used);
            } else {
                printer.write(" ");
                print(el, level + 1, used);
            }
            printer.append(",\n");
        }
        level -= 1;
        printer.write(StringUtils.repeat(' ', level * PRINT_INDENT));
        printer.append(")");
        used.remove(value.getPointer());
    }
}
Also used : ForeachIterator(php.runtime.lang.ForeachIterator) Memory(php.runtime.Memory)

Example 34 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 35 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)

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