use of php.runtime.invoke.Invoker in project jphp by jphp-compiler.
the class JsonProcessor method onClassSerialize.
@Signature({ @Arg("className"), @Arg(value = "callback", type = HintType.CALLABLE, optional = @Optional("null")) })
public Memory onClassSerialize(Environment env, Memory... args) {
ClassEntity entity = env.fetchClass(args[0].toString(), true);
if (entity == null)
throw new IllegalArgumentException("Class not found - " + args[0]);
MemorySerializer.Handler handler = null;
if (!args[1].isNull()) {
final Invoker invoker = Invoker.valueOf(env, env.trace(), args[1]);
handler = new MemorySerializer.Handler() {
@Override
public Memory call(Environment env, Memory value) {
return invoker.callNoThrow(value);
}
};
}
memorySerializer.setClassHandler(entity.getName(), handler);
return Memory.NULL;
}
use of php.runtime.invoke.Invoker in project jphp by jphp-compiler.
the class RunnableMemoryOperation method convert.
@Override
public Runnable convert(final Environment env, final TraceInfo trace, final Memory arg) throws Throwable {
return new Runnable() {
@Override
public void run() {
Invoker invoker = Invoker.valueOf(env, trace, arg);
invoker.callAny();
}
};
}
use of php.runtime.invoke.Invoker in project jphp by jphp-compiler.
the class WrapFlow method eachSlice.
@Signature({ @Arg(value = "sliceSize"), @Arg(value = "callback", type = HintType.CALLABLE) })
public Memory eachSlice(Environment env, Memory... args) {
Invoker invoker = Invoker.valueOf(env, null, args[1]);
ArrayMemory tmp = new ArrayMemory();
int cnt = 0, r = 0, n = args[0].toInteger();
while (iterator.next()) {
cnt++;
if (withKeys)
tmp.refOfIndex(iterator.getMemoryKey()).assign(iterator.getValue());
else
tmp.add(iterator.getValue());
if (cnt >= n) {
r++;
Memory ret = invoker.callNoThrow(tmp);
tmp = new ArrayMemory();
if (ret.toValue() == Memory.FALSE)
break;
cnt = 0;
}
}
if (tmp.size() > 0) {
r++;
invoker.callNoThrow(tmp);
}
return LongMemory.valueOf(r);
}
use of php.runtime.invoke.Invoker in project jphp by jphp-compiler.
the class WrapFlow method group.
@Signature({ @Arg(value = "callback", type = HintType.CALLABLE) })
public Memory group(Environment env, Memory... args) {
final Invoker invoker = Invoker.valueOf(env, null, args[0]);
final ForeachIterator iterator = getSelfIterator(env);
return new ObjectMemory(new WrapFlow(env, new ForeachIterator(false, false, false) {
protected Memory key;
@Override
protected boolean init() {
key = Memory.CONST_INT_M1;
return true;
}
@Override
protected boolean nextValue() {
Memory r = new ArrayMemory();
boolean done = false;
while (iterator.next()) {
done = true;
if (withKeys)
r.refOfIndex(iterator.getMemoryKey()).assign(iterator.getValue());
else
r.refOfPush().assign(iterator.getValue());
if (call(iterator, invoker).toBoolean())
break;
}
if (done) {
currentKeyMemory = key.inc();
currentKey = currentKeyMemory;
currentValue = r;
}
return done;
}
@Override
protected boolean prevValue() {
return false;
}
@Override
public void reset() {
iterator.reset();
key = Memory.CONST_INT_M1;
}
}));
}
use of php.runtime.invoke.Invoker in project jphp by jphp-compiler.
the class WrapFlow method findOne.
@Signature(@Arg(value = "filter", type = HintType.CALLABLE, optional = @Optional("NULL")))
public Memory findOne(Environment env, Memory... args) {
final Invoker invoker = Invoker.valueOf(env, null, args[0]);
ForeachIterator iterator = getSelfIterator(env);
while (iterator.next()) {
if (call(iterator, invoker).toBoolean())
return iterator.getValue();
}
return Memory.NULL;
}
Aggregations