use of php.runtime.memory.StringMemory in project jphp by jphp-compiler.
the class InfoFunctions method get_defined_functions.
public static Memory get_defined_functions(Environment env) {
ArrayMemory array = new ArrayMemory();
ArrayMemory item = (ArrayMemory) array.refOfIndex("internal").assign(new ArrayMemory());
for (FunctionEntity entity : env.getFunctions()) {
if (entity.isInternal())
item.add(new StringMemory(entity.getName()));
}
item = (ArrayMemory) array.refOfIndex("user").assign(new ArrayMemory());
for (FunctionEntity entity : env.getLoadedFunctions().values()) {
if (!entity.isInternal())
item.add(new StringMemory(entity.getName()));
}
return array.toConstant();
}
use of php.runtime.memory.StringMemory in project jphp by jphp-compiler.
the class InfoFunctions method var_export.
public static Memory var_export(Environment env, TraceInfo trace, @Runtime.Reference Memory value, boolean returned) {
StringWriter writer = new StringWriter();
VarExport printer = new VarExport(env, writer);
printer.print(value);
if (printer.isRecursionExists()) {
env.warning(trace, "var_export does not handle circular references");
}
if (returned) {
return new StringMemory(writer.toString());
} else {
env.echo(writer.toString());
return Memory.TRUE;
}
}
use of php.runtime.memory.StringMemory in project jphp by jphp-compiler.
the class LangFunctions method get_parent_class.
public static Memory get_parent_class(Environment env) {
CallStackItem item = env.peekCall(0);
if (item.clazz != null) {
if (item.classEntity == null)
item.classEntity = env.fetchClass(item.clazz, false);
if (item.classEntity == null)
return Memory.FALSE;
else {
MethodEntity method = item.classEntity.findMethod(item.function);
if (method == null)
return Memory.FALSE;
ClassEntity parent = method.getClazz().getParent();
return parent == null ? Memory.FALSE : new StringMemory(parent.getName());
}
}
return Memory.FALSE;
}
use of php.runtime.memory.StringMemory in project jphp by jphp-compiler.
the class FileObject method exception.
protected void exception(Environment env, String message, Object... args) {
WrapIOException exception = new WrapIOException(env, env.fetchClass("php\\io\\IOException"));
exception.__construct(env, new StringMemory(String.format(message, args)));
env.__throwException(exception);
}
use of php.runtime.memory.StringMemory 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