use of php.runtime.reflection.MethodEntity in project jphp by jphp-compiler.
the class RootObject method __set.
@Reflection.Signature({ @Reflection.Arg("name"), @Reflection.Arg("value") })
public Memory __set(Environment env, Memory... args) throws Throwable {
String name = args[0].toString();
MethodEntity methodEntity = __class__.findMethod("__set" + name.toLowerCase());
if (methodEntity != null) {
Memory value = args[1];
if (value.instanceOf(WrapScopeValue.class)) {
value.toObject(WrapScopeValue.class).bind(env, this, name);
value = value.toObject(WrapScopeValue.class).getValue(env);
}
ObjectInvokeHelper.invokeMethod(this, methodEntity, env, env.trace(), new Memory[] { value });
} else
env.exception(env.trace(), "setting: Unknown property - " + args[0].toString());
return Memory.NULL;
}
use of php.runtime.reflection.MethodEntity in project jphp by jphp-compiler.
the class RootObject method __isset.
@Reflection.Signature({ @Reflection.Arg("name") })
public Memory __isset(Environment env, Memory... args) {
String name = args[0].toString();
MethodEntity methodEntity = __class__.findMethod("__get" + name.toLowerCase());
return methodEntity == null ? Memory.FALSE : Memory.TRUE;
}
use of php.runtime.reflection.MethodEntity in project jphp by jphp-compiler.
the class ClosureStmtCompiler method compile.
@Override
public ClosureEntity compile() {
ClosureEntity entity = new ClosureEntity(getCompiler().getContext());
entity.setReturnReference(statement.getFunction().isReturnReference());
entity.setInternalName(compiler.getModule().getInternalName() + "_closure" + statement.getId());
entity.setId(statement.getId());
entity.setTrace(statement.toTraceInfo(compiler.getContext()));
entity.setStatic(statement.isStatic());
ClassStmtToken classStmtToken = new ClassStmtToken(statement.getMeta());
classStmtToken.setNamespace(NamespaceStmtToken.getDefault());
classStmtToken.setName(NameToken.valueOf(entity.getInternalName()));
classStmtToken.setExtend(ExtendsStmtToken.valueOf(Closure.class.getSimpleName()));
MethodStmtToken methodToken = new MethodStmtToken(statement.getFunction());
methodToken.setClazz(classStmtToken);
methodToken.setReturnReference(entity.isReturnReference());
methodToken.setModifier(Modifier.PUBLIC);
methodToken.setName(NameToken.valueOf("__invoke"));
classStmtToken.setMethods(Arrays.asList(methodToken));
ClassStmtCompiler classStmtCompiler = new ClassStmtCompiler(this.compiler, classStmtToken);
classStmtCompiler.setClosureEntity(entity);
classStmtCompiler.setSystem(true);
classStmtCompiler.setInterfaceCheck(false);
classStmtCompiler.setClassContext(statement.getOwnerClass());
classStmtCompiler.setFunctionName(null);
ClassEntity clazzEntity = classStmtCompiler.compile();
clazzEntity.setType(ClassEntity.Type.CLOSURE);
MethodEntity __invoke = clazzEntity.findMethod("__invoke");
entity.getMethods().putAll(clazzEntity.getMethods());
if (clazzEntity.getParent() != null)
entity.setParent(clazzEntity.getParent());
entity.setData(clazzEntity.getData());
entity.setParameters(__invoke.getParameters());
entity.doneDeclare();
entity.setGeneratorEntity(__invoke.getGeneratorEntity());
return entity;
}
use of php.runtime.reflection.MethodEntity in project jphp by jphp-compiler.
the class MethodDumperTest method testBasic.
@Test
public void testBasic() throws IOException {
ByteArrayOutputStream output = new ByteArrayOutputStream();
MethodEntity entity = new MethodEntity(context);
entity.setName("foobar");
entity.setAbstract(true);
entity.setFinal(true);
entity.setModifier(Modifier.PROTECTED);
entity.setAbstractable(true);
entity.setImmutable(true);
entity.setReturnReference(true);
dumper.save(entity, output);
MethodEntity copyEntity = dumper.load(new ByteArrayInputStream(output.toByteArray()));
Assert.assertEquals("foobar", copyEntity.getName());
Assert.assertEquals(Modifier.PROTECTED, copyEntity.getModifier());
Assert.assertTrue(copyEntity.isAbstract());
Assert.assertTrue(copyEntity.isFinal());
Assert.assertTrue(copyEntity.isAbstractable());
Assert.assertTrue(copyEntity.isImmutable());
Assert.assertTrue(copyEntity.isReturnReference());
}
use of php.runtime.reflection.MethodEntity in project jphp by jphp-compiler.
the class DynamicMethodInvoker method valueOf.
public static DynamicMethodInvoker valueOf(Environment env, TraceInfo trace, IObject object, String methodName) {
String methodNameL = methodName.toLowerCase();
int pos;
MethodEntity methodEntity;
if ((pos = methodName.indexOf("::")) > -1) {
String className = methodNameL.substring(0, pos);
methodNameL = methodNameL.substring(pos + 2);
ClassEntity classEntity = object.getReflection();
ClassEntity clazz = env.fetchClass(methodName.substring(0, pos), className, false);
if (!classEntity.isInstanceOf(clazz)) {
return null;
}
methodEntity = clazz.findMethod(methodNameL);
} else
methodEntity = object.getReflection().findMethod(methodNameL);
if (methodEntity == null) {
if (object.getReflection().methodMagicCall != null) {
return new MagicDynamicMethodInvoker(env, trace, object, object.getReflection().methodMagicCall, methodName);
}
if (trace == null) {
return null;
}
env.error(trace, Messages.ERR_CALL_TO_UNDEFINED_METHOD.fetch(object.getReflection().getName() + "::" + methodName));
}
return new DynamicMethodInvoker(env, trace, object, methodEntity);
}
Aggregations