use of php.runtime.memory.ArrayMemory in project jphp by jphp-compiler.
the class MultipleIterator method current.
@Override
@Signature
public Memory current(Environment env, Memory... args) {
if (iterators.size() == 0) {
return Memory.FALSE;
}
ArrayMemory result = new ArrayMemory();
ForeachIterator iterator = iterators.getNewIterator(env);
while (iterator.next()) {
Iterator el = iterator.getValue().toObject(Iterator.class);
if (env.invokeMethodNoThrow(el, "valid").toBoolean()) {
Memory current = env.invokeMethodNoThrow(el, "current");
if ((flags & MIT_KEYS_ASSOC) == MIT_KEYS_ASSOC) {
result.put(iterator.getKey(), current);
} else {
result.add(current);
}
} else {
if ((flags & MIT_NEED_ALL) == MIT_NEED_ALL) {
env.exception(InvalidArgumentException.class, "One of iterators is not valid");
}
}
}
return result.toConstant();
}
use of php.runtime.memory.ArrayMemory in project jphp by jphp-compiler.
the class ReflectionClass method getMethods.
@Signature(@Arg(value = "filter", optional = @Optional("NULL")))
public Memory getMethods(Environment env, Memory... args) {
int mod = args[0].isNull() ? -1 : args[0].toInteger();
ArrayMemory result = new ArrayMemory();
ClassEntity classEntity = env.fetchClass("ReflectionMethod");
for (MethodEntity e : entity.getMethods().values()) {
if (checkModifiers(e, mod)) {
ReflectionMethod method = new ReflectionMethod(env, classEntity);
method.setEntity(e);
result.add(new ObjectMemory(method));
}
}
return result.toConstant();
}
use of php.runtime.memory.ArrayMemory in project jphp by jphp-compiler.
the class CharArrayMemoryOperation method convert.
@Override
public char[] convert(Environment env, TraceInfo trace, Memory arg) throws Throwable {
char[] result = new char[((ArrayMemory) arg).size()];
int i = 0;
for (Memory el : (ArrayMemory) arg) {
result[i++] = el.toChar();
}
return result;
}
use of php.runtime.memory.ArrayMemory in project jphp by jphp-compiler.
the class ShortArrayMemoryOperation method convert.
@Override
public short[] convert(Environment env, TraceInfo trace, Memory arg) throws Throwable {
short[] result = new short[((ArrayMemory) arg).size()];
int i = 0;
for (Memory el : (ArrayMemory) arg) {
result[i++] = (short) el.toInteger();
}
return result;
}
use of php.runtime.memory.ArrayMemory in project jphp by jphp-compiler.
the class ClassEntity method issetProperty.
public Memory issetProperty(Environment env, TraceInfo trace, IObject object, String property, PropertyCallCache callCache, int cacheIndex) throws Throwable {
PropertyEntity entity = callCache == null || env instanceof ConcurrentEnvironment ? null : callCache.get(env, cacheIndex);
if (entity == null) {
ClassEntity contex = env.getLastClassOnStack();
entity = isInstanceOf(contex) ? contex.properties.get(property) : properties.get(property);
if (entity != null && callCache != null) {
callCache.put(env, cacheIndex, entity);
}
}
int accessFlag = entity == null ? 0 : entity.canAccess(env);
ArrayMemory props = object.getProperties();
Memory tmp = props == null || accessFlag != 0 ? null : props.getByScalar(entity == null ? property : entity.specificName);
if (tmp != null)
return tmp.isNull() ? tmp : Memory.TRUE;
if (methodMagicIsset != null) {
Memory result;
ClassEntity contex = env.getLastClassOnStack();
if (contex != null && contex.getId() == methodMagicIsset.getClazz().getId())
if (env.peekCall(0).flags == FLAG_ISSET) {
return object.getProperties().getByScalar(property) != null ? Memory.TRUE : Memory.NULL;
}
try {
Memory[] args = new Memory[] { new StringMemory(property) };
env.pushCall(trace, object, args, methodMagicIsset.getName(), methodMagicIsset.getClazz().getName(), name);
env.peekCall(0).flags = FLAG_ISSET;
InvokeArgumentHelper.checkType(env, trace, methodMagicIsset, new StringMemory(property));
result = methodMagicIsset.invokeDynamic(object, env, new StringMemory(property)).toBoolean() ? Memory.TRUE : Memory.NULL;
} finally {
env.popCall();
}
return result;
}
return Memory.NULL;
}
Aggregations