Search in sources :

Example 6 with IObject

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;
    }
}
Also used : ArrayMemory(php.runtime.memory.ArrayMemory) IObject(php.runtime.lang.IObject) ObjectMemory(php.runtime.memory.ObjectMemory)

Example 7 with IObject

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());
}
Also used : IObject(php.runtime.lang.IObject) ObjectMemory(php.runtime.memory.ObjectMemory) Memory(php.runtime.Memory) ObjectMemory(php.runtime.memory.ObjectMemory) Test(org.junit.Test)

Example 8 with IObject

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);
    }
}
Also used : ArrayMemory(php.runtime.memory.ArrayMemory) IObject(php.runtime.lang.IObject)

Example 9 with IObject

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;
}
Also used : NativeObject(org.develnext.jphp.ext.pna.classes.NativeObject) NativeObject(org.develnext.jphp.ext.pna.classes.NativeObject) IObject(php.runtime.lang.IObject) MemoryOperation(php.runtime.memory.support.MemoryOperation)

Example 10 with IObject

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);
}
Also used : IObject(php.runtime.lang.IObject) ObjectMemory(php.runtime.memory.ObjectMemory)

Aggregations

IObject (php.runtime.lang.IObject)23 ObjectMemory (php.runtime.memory.ObjectMemory)13 Memory (php.runtime.Memory)9 ArrayMemory (php.runtime.memory.ArrayMemory)8 ReferenceMemory (php.runtime.memory.ReferenceMemory)4 StringMemory (php.runtime.memory.StringMemory)4 ClassEntity (php.runtime.reflection.ClassEntity)4 CriticalException (php.runtime.exceptions.CriticalException)3 ForeachIterator (php.runtime.lang.ForeachIterator)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Test (org.junit.Test)2 Serializable (php.runtime.lang.spl.Serializable)2 MethodEntity (php.runtime.reflection.MethodEntity)2 Constructor (java.lang.reflect.Constructor)1 ParameterizedType (java.lang.reflect.ParameterizedType)1 LinkedHashSet (java.util.LinkedHashSet)1 NativeObject (org.develnext.jphp.ext.pna.classes.NativeObject)1 Environment (php.runtime.env.Environment)1 TraceInfo (php.runtime.env.TraceInfo)1 BaseWrapper (php.runtime.lang.BaseWrapper)1