use of php.runtime.reflection.ClassEntity in project jphp by jphp-compiler.
the class ReflectionProperty method __construct.
@Signature({ @Arg("class"), @Arg("name") })
public Memory __construct(Environment env, Memory... args) {
ClassEntity classEntity;
Memory arg = args[0];
if (arg.isObject()) {
classEntity = arg.toValue(ObjectMemory.class).getReflection();
} else
classEntity = env.fetchClass(arg.toString());
if (classEntity == null) {
exception(env, Messages.ERR_CLASS_NOT_FOUND.fetch(arg));
return Memory.NULL;
}
String prop = args[1].toString();
PropertyEntity entity = classEntity.findProperty(prop);
if (entity == null)
entity = classEntity.findStaticProperty(prop);
if (entity == null) {
exception(env, Messages.ERR_UNDEFINED_PROPERTY.fetch(classEntity.getName(), prop));
return Memory.NULL;
}
setEntity(entity);
return Memory.NULL;
}
use of php.runtime.reflection.ClassEntity 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.reflection.ClassEntity 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.reflection.ClassEntity 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()));
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.setSystem(true);
classStmtCompiler.setInterfaceCheck(false);
classStmtCompiler.setClassContext(statement.getOwnerClass());
classStmtCompiler.setFunctionName(null);
ClassEntity clazzEntity = classStmtCompiler.compile();
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.ClassEntity in project jphp by jphp-compiler.
the class GeneratorStmtCompiler method compile.
@Override
public GeneratorEntity compile() {
GeneratorEntity entity = new GeneratorEntity(getCompiler().getContext());
entity.setReturnReference(statement.isReturnReference());
entity.setInternalName(compiler.getModule().getInternalName() + "_generator" + statement.getId());
entity.setId(statement.getGeneratorId());
entity.setTrace(statement.toTraceInfo(compiler.getContext()));
ClassStmtToken classStmtToken = new ClassStmtToken(statement.getMeta());
classStmtToken.setNamespace(NamespaceStmtToken.getDefault());
classStmtToken.setName(NameToken.valueOf(entity.getInternalName()));
classStmtToken.setExtend(ExtendsStmtToken.valueOf(Generator.class.getSimpleName()));
MethodStmtToken methodToken = new MethodStmtToken(statement);
methodToken.setClazz(classStmtToken);
methodToken.setGenerator(false);
methodToken.setReturnReference(false);
methodToken.setModifier(Modifier.PROTECTED);
methodToken.setName(NameToken.valueOf("_run"));
methodToken.setUses(statement.getArguments());
methodToken.setArguments(Collections.<ArgumentStmtToken>emptyList());
classStmtToken.setMethods(Arrays.asList(methodToken));
ClassStmtCompiler classStmtCompiler = new ClassStmtCompiler(this.compiler, classStmtToken);
classStmtCompiler.setSystem(true);
classStmtCompiler.setInterfaceCheck(false);
classStmtCompiler.setGeneratorEntity(entity);
classStmtCompiler.setFunctionName(statement.getFulledName());
ClassEntity clazzEntity = classStmtCompiler.compile();
entity.getMethods().putAll(clazzEntity.getMethods());
if (clazzEntity.getParent() != null)
entity.setParent(clazzEntity.getParent());
entity.setData(clazzEntity.getData());
entity.doneDeclare();
return entity;
}
Aggregations