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());
}
}
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());
}
}
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());
}
}
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;
}
}
}
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;
}
Aggregations