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);
}
use of php.runtime.invoke.Invoker in project jphp by jphp-compiler.
the class OutputFunctions method ob_start.
public static Memory ob_start(Environment env, TraceInfo trace, Memory outputCallback, Memory _chunkSize, Memory erase) {
Invoker invoker;
if (!outputCallback.isNull()) {
invoker = expectingCallback(env, trace, 1, outputCallback);
if (invoker == null)
return Memory.FALSE;
invoker.check("ob_start", trace);
}
switch(_chunkSize.getRealType()) {
case ARRAY:
case STRING:
case OBJECT:
env.warning(trace, "ob_start() expects parameter 2 to be long, " + _chunkSize.getRealType().toString() + " given");
return Memory.NULL;
}
switch(erase.getRealType()) {
case ARRAY:
case STRING:
case OBJECT:
env.warning(trace, "ob_start() expects parameter 3 to be long, " + erase.getRealType().toString() + " given");
return Memory.NULL;
}
int chunkSize = _chunkSize.toInteger();
if (chunkSize < 0)
chunkSize = 0;
if (chunkSize < 0) {
env.warning(trace, "ob_start(): chunk_size must be grater or equal than zero");
return Memory.FALSE;
}
OutputBuffer buffer = env.peekOutputBuffer();
if (buffer != null && buffer.isLock())
env.error(trace, "ob_start(): Cannot use output buffering in output buffering display handlers");
env.pushOutputBuffer(outputCallback, chunkSize, erase.toBoolean());
return Memory.TRUE;
}
use of php.runtime.invoke.Invoker in project jphp by jphp-compiler.
the class WrapClassLoader method _getSplClassLoader.
protected synchronized SplClassLoader _getSplClassLoader(Environment env) {
if (splClassLoader == null) {
ArrayMemory callback = new ArrayMemory();
callback.add(this);
callback.add("loadClass");
Invoker invoker = Invoker.valueOf(env, null, callback);
splClassLoader = new SplClassLoader(invoker, callback);
}
return splClassLoader;
}
use of php.runtime.invoke.Invoker in project jphp by jphp-compiler.
the class WrapEnvironment method execute.
@Signature(@Arg(value = "runnable"))
public Memory execute(Environment env, Memory... args) throws Throwable {
Invoker invoker = Invoker.valueOf(this.environment, null, args[0]);
if (invoker == null) {
env.exception("Argument 1 must be callable in environment");
return Memory.NULL;
}
invoker.setTrace(env.trace());
return invoker.call();
}
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();
}
Aggregations