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();
}
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);
}
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);
}
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);
}
}
}
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());
}
Aggregations