Search in sources :

Example 6 with ObjectMemory

use of php.runtime.memory.ObjectMemory in project jphp by jphp-compiler.

the class ReflectionClass method getMethods.

@Signature(@Arg(value = "filter", optional = @Optional("NULL")))
public Memory getMethods(Environment env, Memory... args) {
    int mod = args[0].isNull() ? -1 : args[0].toInteger();
    ArrayMemory result = new ArrayMemory();
    ClassEntity classEntity = env.fetchClass("ReflectionMethod");
    for (MethodEntity e : entity.getMethods().values()) {
        if (checkModifiers(e, mod)) {
            ReflectionMethod method = new ReflectionMethod(env, classEntity);
            method.setEntity(e);
            result.add(new ObjectMemory(method));
        }
    }
    return result.toConstant();
}
Also used : ArrayMemory(php.runtime.memory.ArrayMemory) ClassEntity(php.runtime.reflection.ClassEntity) ObjectMemory(php.runtime.memory.ObjectMemory) MethodEntity(php.runtime.reflection.MethodEntity)

Example 7 with ObjectMemory

use of php.runtime.memory.ObjectMemory in project jphp by jphp-compiler.

the class ReflectionClass method getMethod.

@Signature(@Arg("name"))
public Memory getMethod(Environment env, Memory... args) {
    MethodEntity m = entity.findMethod(args[0].toString().toLowerCase());
    if (m == null) {
        exception(env, Messages.ERR_METHOD_NOT_FOUND.fetch(entity.getName(), args[0]));
        return Memory.NULL;
    }
    ReflectionMethod r = new ReflectionMethod(env, m);
    return new ObjectMemory(r);
}
Also used : ObjectMemory(php.runtime.memory.ObjectMemory) MethodEntity(php.runtime.reflection.MethodEntity)

Example 8 with ObjectMemory

use of php.runtime.memory.ObjectMemory in project jphp by jphp-compiler.

the class ReflectionClass method getParentClass.

@Signature
public Memory getParentClass(Environment env, Memory... args) {
    if (entity.getParent() == null)
        return Memory.NULL;
    ClassEntity classEntity = env.fetchClass("ReflectionClass");
    ReflectionClass result = new ReflectionClass(env, classEntity);
    result.setEntity(entity.getParent());
    return new ObjectMemory(result);
}
Also used : ClassEntity(php.runtime.reflection.ClassEntity) ObjectMemory(php.runtime.memory.ObjectMemory)

Example 9 with ObjectMemory

use of php.runtime.memory.ObjectMemory in project jphp by jphp-compiler.

the class ClosureEntity method setNativeClazz.

@Override
public void setNativeClazz(Class<?> nativeClazz) {
    this.nativeClazz = nativeClazz;
    if (!nativeClazz.isInterface()) {
        try {
            this.nativeConstructor = nativeClazz.getConstructor(Environment.class, ClassEntity.class, Memory.class, String.class, Memory[].class);
            this.nativeConstructor.setAccessible(true);
            //if (uses == null || uses.length == 0)
            singleton = new ObjectMemory((Closure) this.nativeConstructor.newInstance(null, this, Memory.NULL, null, null));
        //else
        //  singleton = null;
        } catch (NoSuchMethodException e) {
            throw new RuntimeException(e);
        } catch (InvocationTargetException e) {
            throw new RuntimeException(e.getTargetException());
        } catch (InstantiationException e) {
            throw new RuntimeException(e);
        } catch (IllegalAccessException e) {
            throw new RuntimeException(e);
        }
    }
}
Also used : ClassEntity(php.runtime.reflection.ClassEntity) Closure(php.runtime.lang.Closure) ObjectMemory(php.runtime.memory.ObjectMemory) Memory(php.runtime.Memory) ObjectMemory(php.runtime.memory.ObjectMemory) Environment(php.runtime.env.Environment) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 10 with ObjectMemory

use of php.runtime.memory.ObjectMemory in project jphp by jphp-compiler.

the class DeserializerTest method testObjects.

@Test
public void testObjects() {
    Memory value = unserialize("O:8:\"stdClass\":0:{}");
    Assert.assertTrue(value instanceof ObjectMemory);
    Assert.assertTrue(value.toValue(ObjectMemory.class).value instanceof StdClass);
    Assert.assertEquals(0, value.toValue(ObjectMemory.class).getProperties().size());
    value = unserialize("O:8:\"stdClass\":2:{s:1:\"x\";s:3:\"foo\";s:1:\"y\";s:3:\"bar\";}");
    Assert.assertTrue(value instanceof ObjectMemory);
    Assert.assertTrue(value.toValue(ObjectMemory.class).value instanceof StdClass);
    Assert.assertEquals(2, value.toValue(ObjectMemory.class).getProperties().size());
    Assert.assertEquals("foo", value.toValue(ObjectMemory.class).getProperties().valueOfIndex("x").toString());
    Assert.assertEquals("bar", value.toValue(ObjectMemory.class).getProperties().valueOfIndex("y").toString());
}
Also used : ObjectMemory(php.runtime.memory.ObjectMemory) Memory(php.runtime.Memory) ArrayMemory(php.runtime.memory.ArrayMemory) ObjectMemory(php.runtime.memory.ObjectMemory) StdClass(php.runtime.lang.StdClass) Test(org.junit.Test)

Aggregations

ObjectMemory (php.runtime.memory.ObjectMemory)55 ArrayMemory (php.runtime.memory.ArrayMemory)24 Memory (php.runtime.Memory)19 ClassEntity (php.runtime.reflection.ClassEntity)17 StringMemory (php.runtime.memory.StringMemory)14 IObject (php.runtime.lang.IObject)11 Invoker (php.runtime.invoke.Invoker)6 LongMemory (php.runtime.memory.LongMemory)6 Environment (php.runtime.env.Environment)5 MethodEntity (php.runtime.reflection.MethodEntity)5 Calendar (java.util.Calendar)4 Closure (php.runtime.lang.Closure)4 Locale (java.util.Locale)3 Test (org.junit.Test)3 WrapLocale (php.runtime.ext.core.classes.util.WrapLocale)3 PropertyEntity (php.runtime.reflection.PropertyEntity)3 AbstractFunctionEntity (php.runtime.reflection.support.AbstractFunctionEntity)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Date (java.util.Date)2 TimeZone (java.util.TimeZone)2