use of php.runtime.lang.ForeachIterator in project jphp by jphp-compiler.
the class PrintR method printObject.
@Override
protected void printObject(ObjectMemory value, int level, Set<Integer> used) {
ClassEntity classEntity = value.getReflection();
writeObjectHeader(classEntity.getName());
if (used.contains(value.getPointer())) {
printer.write(" *RECURSION*");
} else {
printer.write(StringUtils.repeat(' ', level * PRINT_INDENT));
writeOpen();
level += 1;
used.add(value.getPointer());
ArrayMemory props;
if (env != null && classEntity.methodMagicDebugInfo != null) {
try {
Memory tmp = env.invokeMethod(value.value, classEntity.methodMagicDebugInfo.getName());
if (tmp.isArray()) {
props = tmp.toValue(ArrayMemory.class);
} else {
props = new ArrayMemory();
}
} catch (RuntimeException e) {
throw e;
} catch (Throwable throwable) {
throw new RuntimeException(throwable);
}
} else {
props = value.getProperties();
}
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(":getter] => ");
try {
print(entity.getValue(env, TraceInfo.UNKNOWN, value.value));
} catch (RuntimeException e) {
throw e;
} catch (Throwable throwable) {
throw new RuntimeException(throwable);
}
writeSeparator(false);
}
}
}
if (props != null) {
ForeachIterator iterator = props.foreachIterator(false, false);
int i = 0;
int size = classEntity.properties.size();
while (iterator.next()) {
printer.write(StringUtils.repeat(' ', level * PRINT_INDENT));
Object key = iterator.getKey();
printer.write('[');
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(realKey);
switch(modifier) {
case PRIVATE:
printer.write(":" + className + ":private");
break;
case PROTECTED:
printer.write(":protected");
}
printer.write("] => ");
print(iterator.getValue(), 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 printArray.
@Override
protected void printArray(ArrayMemory value, int level, Set<Integer> used) {
if (used.contains(value.getPointer())) {
printer.write("*RECURSION*\n");
} else {
printer.write("array(");
printer.write(value.size() + "");
printer.write(") {\n");
level += 1;
used.add(value.getPointer());
ForeachIterator iterator = value.foreachIterator(false, false);
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('[');
if (key.isString()) {
printer.write('"');
printer.write(key.toString());
printer.write('"');
} else {
printer.write(key.toString());
}
printer.write("]=>\n");
printer.write(StringUtils.repeat(' ', level * PRINT_INDENT));
print(el, 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 ArrayMemory method resetCurrentIterator.
public Memory resetCurrentIterator() {
reset();
ForeachIterator iterator = getCurrentIterator();
if (size == 0)
return FALSE;
else {
iterator.next();
Memory tmp = iterator.getValue();
iterator.prev();
return tmp;
}
}
use of php.runtime.lang.ForeachIterator in project jphp by jphp-compiler.
the class ClassEntity method cloneObject.
public <T extends IObject> T cloneObject(T value, Environment env, TraceInfo trace) throws Throwable {
IObject copy = this.newObjectWithoutConstruct(env);
ForeachIterator iterator = value.getProperties().foreachIterator(false, false);
ArrayMemory props = copy.getProperties();
while (iterator.next()) {
Object key = iterator.getKey();
if (key instanceof String) {
String name = (String) key;
if (name.indexOf('\0') > -1)
name = name.substring(name.lastIndexOf('\0') + 1);
PropertyEntity entity = properties.get(name);
if (entity != null) {
if (props.getByScalar(entity.getSpecificName()) == null)
props.put(entity.getSpecificName(), iterator.getValue().toImmutable());
} else
props.put(key, iterator.getValue().toImmutable());
} else
props.put(key, iterator.getValue().toImmutable());
}
if (methodMagicClone != null) {
ObjectInvokeHelper.invokeMethod(copy, methodMagicClone, env, trace, null, true);
}
return (T) copy;
}
use of php.runtime.lang.ForeachIterator in project jphp by jphp-compiler.
the class ArrayMemory method slice.
public ArrayMemory slice(int offset, boolean saveKeys) {
ArrayMemory result = new ArrayMemory();
if (offset < 0) {
offset = size() + offset;
}
if (isList()) {
int i = 0;
try {
for (ReferenceMemory referenceMemory : list.subList(offset, list.size())) {
if (saveKeys) {
result.refOfIndex(i + offset).assign(referenceMemory.toImmutable());
} else {
result.add(referenceMemory.toImmutable());
}
i++;
}
} catch (IllegalArgumentException e) {
throw new IndexOutOfBoundsException(e.getMessage());
}
} else {
int i = 0;
ForeachIterator iterator = foreachIterator(false, false);
while (iterator.next()) {
if (i >= offset) {
if (saveKeys || !iterator.isLongKey()) {
result.put(iterator.getKey(), iterator.getValue().toImmutable());
} else {
result.add(iterator.getValue().toImmutable());
}
}
i++;
}
}
return result;
}
Aggregations