use of php.runtime.invoke.Invoker in project jphp by jphp-compiler.
the class SPLFunctions method iterator_apply.
public static long iterator_apply(Environment env, TraceInfo trace, Memory object, Memory callback, Memory args) throws Throwable {
if (expectingImplement(env, trace, 1, object, Traversable.class)) {
Invoker invoker = expectingCallback(env, trace, 2, callback);
if (invoker == null)
return 0;
if (args != null && !expecting(env, trace, 3, args, Memory.Type.ARRAY)) {
return 0;
}
ForeachIterator iterator = object.getNewIterator(env, false, false);
Memory[] values = args == null ? null : args.toValue(ArrayMemory.class).values(true);
int i = 0;
while (iterator.next()) {
if (!invoker.call(values).toBoolean())
break;
i++;
}
return i;
} else
return 0;
}
use of php.runtime.invoke.Invoker in project jphp by jphp-compiler.
the class ReflectionParameter method __construct.
@Signature({ @Arg("function"), @Arg("parameter") })
public Memory __construct(Environment env, Memory... args) {
ParameterEntity[] parameters = null;
if (args[0].isClosure()) {
ClosureEntity tmp = (ClosureEntity) args[0].toValue(ObjectMemory.class).getReflection();
parameters = tmp.parameters;
} else if (args[0].isArray()) {
Invoker invoker = Invoker.valueOf(env, null, args[0]);
if (invoker == null) {
exception(env, "%s does not exists", args[0].toString());
return Memory.NULL;
}
parameters = invoker.getParameters();
} else {
String name = args[0].toString();
if (name.contains("::")) {
Invoker invoker = Invoker.valueOf(env, null, args[0]);
if (invoker == null) {
exception(env, "%s does not exists", args[0].toString());
return Memory.NULL;
}
parameters = invoker.getParameters();
} else {
FunctionEntity tmp = env.fetchFunction(name);
functionEntity = tmp;
if (tmp == null) {
exception(env, "Function %s does not exist", args[0].toString());
return Memory.NULL;
}
if (tmp.isInternal()) {
exception(env, "%s(): ReflectionParameter does not support internal functions", tmp.getName());
return Memory.NULL;
}
parameters = tmp.getParameters();
}
}
entity = null;
String name = args[1].toString();
if (parameters != null) {
if (args[1].isNumber()) {
int index = args[1].toInteger();
if (index >= 0 && index < parameters.length) {
entity = parameters[index];
position = index;
}
} else {
int i = 0;
for (ParameterEntity e : parameters) {
if (e.getName().equals(name)) {
entity = e;
position = i;
break;
}
i++;
}
}
}
if (entity == null)
exception(env, "Parameter %s does not exist", name);
setEntity(entity);
return Memory.NULL;
}
use of php.runtime.invoke.Invoker in project jphp by jphp-compiler.
the class LangFunctions method set_exception_handler.
public static Memory set_exception_handler(Environment env, TraceInfo trace, @Runtime.Reference Memory handler) {
Invoker invoker = expectingCallback(env, trace, 1, handler);
if (invoker != null) {
ExceptionHandler eh = env.getExceptionHandler();
env.setExceptionHandler(new ExceptionHandler(invoker, handler.toImmutable()));
return eh == null || eh.invoker == null ? Memory.NULL : eh.invokerMemory;
} else
return Memory.FALSE;
}
use of php.runtime.invoke.Invoker in project jphp by jphp-compiler.
the class LangFunctions method _call_user_func.
private static Memory _call_user_func(Environment env, TraceInfo trace, Memory function, Memory... args) throws Throwable {
Invoker invoker = expectingCallback(env, trace, 1, function);
if (invoker == null) {
return Memory.FALSE;
}
invoker.setTrace(trace);
return invoker.call(args);
}
use of php.runtime.invoke.Invoker in project jphp by jphp-compiler.
the class FileObject method find.
@Signature(@Arg(value = "filter", optional = @Optional("NULL")))
public Memory find(final Environment env, Memory... args) {
if (args[0].isNull()) {
return ArrayMemory.ofStrings(file.list()).toConstant();
} else {
final Invoker invoker = Invoker.valueOf(env, null, args[0]);
if (invoker == null) {
exception(env, "Invalid filter value, must be callable");
return Memory.NULL;
}
final TraceInfo trace = env.trace();
invoker.setTrace(trace);
String[] result = file.list(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
FileObject o = new FileObject(env, __class__, dir);
Memory[] args = new Memory[] { new ObjectMemory(o), new StringMemory(name) };
return invoker.callNoThrow(args).toBoolean();
}
});
return ArrayMemory.ofStrings(result);
}
}
Aggregations