use of php.runtime.memory.ObjectMemory in project jphp by jphp-compiler.
the class Environment method __throwCatch.
public Memory __throwCatch(BaseBaseException e, String className, String lowerClassName) {
ClassEntity origin = e.getReflection();
ClassEntity cause = fetchClass(className, lowerClassName, false);
if (cause != null && origin.isInstanceOf(cause))
return new ObjectMemory(e);
if (origin.isInstanceOfLower(lowerClassName))
return new ObjectMemory(e);
else
return Memory.NULL;
}
use of php.runtime.memory.ObjectMemory in project jphp by jphp-compiler.
the class LangFunctions method property_exists.
public static Memory property_exists(Environment env, Memory clazz, String property) throws Throwable {
ClassEntity classEntity;
IObject object = null;
boolean isMagic = false;
if (clazz.isObject()) {
ObjectMemory tmp = clazz.toValue(ObjectMemory.class);
classEntity = tmp.getReflection();
object = tmp.value;
} else {
String name = clazz.toString();
String nameL = name.toLowerCase();
classEntity = env.fetchClass(name, nameL, true);
if (classEntity == null) {
classEntity = env.fetchMagicClass(name, nameL);
isMagic = true;
}
}
if (classEntity == null) {
return Memory.FALSE;
}
if (object != null) {
ArrayMemory props = object.getProperties();
ClassEntity context = env.getLastClassOnStack();
PropertyEntity entity = classEntity.isInstanceOf(context) ? context.properties.get(property) : classEntity.properties.get(property);
int accessFlags = entity == null ? 0 : entity.canAccess(env);
if (accessFlags != 0)
return Memory.FALSE;
return (props != null && props.getByScalar(entity == null ? property : entity.getSpecificName()) != null) ? Memory.TRUE : Memory.FALSE;
} else {
PropertyEntity entity = classEntity.properties.get(property);
if (isMagic) {
int accessFlags = entity == null ? 0 : entity.canAccess(env);
if (accessFlags != 0)
return Memory.FALSE;
}
return entity != null ? Memory.TRUE : Memory.FALSE;
}
}
use of php.runtime.memory.ObjectMemory in project jphp by jphp-compiler.
the class CallStackItem method toArray.
public ArrayMemory toArray(boolean provideObject, boolean ignoreArgs) {
ArrayMemory el = new ArrayMemory();
if (trace != null) {
if (trace.getFile() != null)
el.refOfIndex("file").assign(trace.getFileName());
el.refOfIndex("line").assign(trace.getStartLine() + 1);
}
el.refOfIndex("function").assign(function);
if (clazz != null) {
el.refOfIndex("class").assign(clazz);
el.refOfIndex("type").assign("::");
}
if (object != null) {
if (provideObject) {
el.refOfIndex("object").assign(new ObjectMemory(object));
}
el.refOfIndex("type").assign("->");
}
if (!ignoreArgs) {
el.refOfIndex("args").assign(ArrayMemory.of(args));
}
if (trace != null)
el.refOfIndex("position").assign(trace.getStartPosition() + 1);
return el;
}
use of php.runtime.memory.ObjectMemory 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);
}
}
use of php.runtime.memory.ObjectMemory in project jphp by jphp-compiler.
the class Stream method of.
@Signature({ @Arg("path"), @Arg(value = "mode", optional = @Optional("r")) })
public static Memory of(Environment env, Memory... args) throws Throwable {
String path = args[0].toString();
String protocol = "file";
int pos = path.indexOf("://");
if (pos > -1) {
protocol = path.substring(0, pos);
path = path.substring(pos + 3);
}
String className = env.getUserValue(Stream.class.getName() + "#" + protocol, String.class);
if (className == null) {
throw new IOException("Unregistered protocol - " + protocol + "://");
}
ClassEntity classEntity = env.fetchClass(className);
if (classEntity.getNativeClass().getAnnotation(UsePathWithProtocols.class) != null) {
path = protocol + "://" + path;
}
return new ObjectMemory(classEntity.newObject(env, env.trace(), true, new StringMemory(path), args[1]));
}
Aggregations