use of php.runtime.lang.IObject 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.lang.IObject in project jphp by jphp-compiler.
the class ClassesTest method testDefine.
@Test
public void testDefine() {
Memory memory;
memory = runDynamic("class A { } return new A();", false);
Assert.assertTrue(memory.isObject());
IObject object = ((ObjectMemory) memory).value;
Assert.assertEquals("A", object.getReflection().getName());
}
use of php.runtime.lang.IObject in project jphp by jphp-compiler.
the class ContextValueProvider method processObject.
protected void processObject(Element property, ObjectMemory objectMemory, Set<Integer> used) {
IObject value = objectMemory.value;
ArrayMemory properties = value.getProperties();
property.setAttribute("classname", value.getReflection().getName());
if (properties != null) {
processArray(property, properties, used, true);
}
}
use of php.runtime.lang.IObject in project jphp by jphp-compiler.
the class NativeClassEntity method newObject.
@Override
public <T extends IObject> T newObject(Environment env, TraceInfo trace, boolean doConstruct, Memory... args) throws Throwable {
Object instance = null;
for (Constructor<?> construct : rawClass.getConstructors()) {
Class<?>[] parameterTypes = construct.getParameterTypes();
if ((args == null && parameterTypes.length == 0) || (parameterTypes.length == args.length)) {
Object[] passed = new Object[args == null ? 0 : args.length];
boolean next = false;
for (int i = 0; i < passed.length; i++) {
MemoryOperation op = MemoryOperation.get(parameterTypes[i], construct.getGenericParameterTypes()[i]);
if (op == null) {
next = true;
break;
}
passed[i] = op.convert(env, trace, args[i]);
}
if (next)
continue;
try {
instance = construct.newInstance(passed);
} catch (InvocationTargetException e) {
throw e.getCause();
}
}
}
NativeObject object = (NativeObject) super.newObject(env, trace, doConstruct, args);
object.__setNativeObject(instance);
return (T) object;
}
use of php.runtime.lang.IObject in project jphp by jphp-compiler.
the class ObjectInvokeHelper method issetProperty.
public static Memory issetProperty(Memory object, String property, Environment env, TraceInfo trace, PropertyCallCache callCache, int cacheIndex) throws Throwable {
object = object.toValue();
if (!object.isObject()) {
return Memory.NULL;
//env.error(trace, Messages.ERR_CANNOT_GET_PROPERTY_OF_NON_OBJECT.fetch(property));
}
IObject iObject = ((ObjectMemory) object).value;
return iObject.getReflection().issetProperty(env, trace, iObject, property, callCache, cacheIndex);
}
Aggregations