use of php.runtime.invoke.Invoker in project jphp by jphp-compiler.
the class ItemsUtils method map.
@Signature({ @Arg(value = "collection", type = HintType.TRAVERSABLE), @Arg(value = "callback", type = HintType.CALLABLE) })
public static Memory map(Environment env, Memory... args) throws Throwable {
ForeachIterator iterator = args[0].getNewIterator(env);
if (iterator == null) {
return Memory.NULL;
}
Invoker callback = Invoker.valueOf(env, null, args[1]);
if (callback == null) {
return Memory.NULL;
}
ArrayMemory r = new ArrayMemory();
while (iterator.next()) {
r.refOfIndex(iterator.getMemoryKey()).assign(callback.call(iterator.getValue()));
}
return r.toConstant();
}
use of php.runtime.invoke.Invoker in project jphp by jphp-compiler.
the class PHttpServer method filters.
@Signature
public Memory filters() {
ArrayMemory result = ArrayMemory.createListed(filters.getHandlers().length);
for (Handler handler : filters.getHandlers()) {
if (handler instanceof InvokeHandler) {
Invoker invoker = ((InvokeHandler) handler).getInvoker();
result.add(invoker.getMemory().toImmutable());
}
}
return result.toImmutable();
}
use of php.runtime.invoke.Invoker in project jphp by jphp-compiler.
the class JsonProcessor method onSerialize.
@Signature({ @Arg("type"), @Arg(value = "callback", type = HintType.CALLABLE, optional = @Optional("null")) })
public Memory onSerialize(Environment env, Memory... args) {
Memory.Type type = Memory.Type.of(args[0].toString());
if (type == null)
throw new IllegalArgumentException("Invalid type - " + 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.setTypeHandler(type, handler);
return null;
}
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 WrapFlow method each.
@Signature(@Arg(value = "callback", type = HintType.CALLABLE))
public Memory each(Environment env, Memory... args) {
ForeachIterator iterator = getSelfIterator(env);
Invoker invoker = Invoker.valueOf(env, null, args[0]);
int cnt = 0;
while (iterator.next()) {
cnt++;
if (call(iterator, invoker).toValue() == Memory.FALSE)
break;
}
return LongMemory.valueOf(cnt);
}
Aggregations