use of php.runtime.reflection.ClassEntity in project jphp by jphp-compiler.
the class ReflectionClass method getInterfaces.
@Signature
public Memory getInterfaces(Environment env, Memory... args) {
ArrayMemory result = new ArrayMemory();
ClassEntity classEntity = env.fetchClass("ReflectionClass");
for (ClassEntity e : entity.getInterfaces().values()) {
ReflectionClass cls = new ReflectionClass(env, classEntity);
cls.setEntity(e);
result.add(new ObjectMemory(cls));
}
return result.toConstant();
}
use of php.runtime.reflection.ClassEntity in project jphp by jphp-compiler.
the class ObjectInvokeHelper method invokeMethod.
public static Memory invokeMethod(Memory object, String methodName, String methodLowerName, Environment env, TraceInfo trace, Memory[] args) throws Throwable {
object = object.toValue();
Memory[] passed = null;
boolean doublePop = false;
if (object.type != Memory.Type.OBJECT) {
env.error(trace, ErrorType.E_RECOVERABLE_ERROR, Messages.ERR_CANNOT_CALL_OF_NON_OBJECT.fetch(methodName));
return Memory.NULL;
}
IObject iObject = ((ObjectMemory) object).value;
ClassEntity clazz = iObject.getReflection();
MethodEntity method;
if (methodName == null) {
method = clazz.methodMagicInvoke;
} else {
method = clazz.findMethod(methodLowerName);
if (method != null && method.isContextDepends()) {
ClassEntity context = env.getLastClassOnStack();
if (context != null) {
MethodEntity contextMethod = context.findMethod(methodLowerName);
if (contextMethod != null) {
method = contextMethod;
}
}
}
if (method == null && ((method = clazz.methodMagicCall) != null)) {
clazz.methodMagicCall.setModifier(Modifier.PUBLIC);
passed = new Memory[] { new StringMemory(methodName), ArrayMemory.of(args) };
doublePop = true;
}
}
String className = clazz.getName();
if (method == null) {
if (methodName == null)
methodName = "__invoke";
env.error(trace, ErrorType.E_ERROR, Messages.ERR_CALL_TO_UNDEFINED_METHOD.fetch(className + "::" + methodName));
return Memory.NULL;
}
InvokeHelper.checkAccess(env, trace, method);
if (passed == null) {
passed = InvokeHelper.makeArguments(env, args, method.getParameters(args == null ? 0 : args.length), className, methodName, trace);
}
Memory result = method.getImmutableResult();
if (result != null) {
return result;
}
try {
if (trace != null) {
String staticClass = className;
if (iObject instanceof Closure) {
staticClass = ((Closure) iObject).getScope();
}
String stackClass = clazz.isHiddenInCallStack() ? staticClass : method.getClazz().getName();
env.pushCall(trace, iObject, args, methodName, stackClass, staticClass);
if (doublePop) {
env.pushCall(trace, iObject, passed, method.getName(), stackClass, staticClass);
}
}
return method.invokeDynamic(iObject, env, passed);
} catch (NoClassDefFoundError e) {
throw new CriticalException("Unable to call method " + className + "::" + methodName + "(), " + e.getMessage());
} finally {
if (trace != null) {
env.popCall();
if (doublePop)
env.popCall();
}
}
}
use of php.runtime.reflection.ClassEntity in project jphp by jphp-compiler.
the class ObjectInvokeHelper method getConstant.
public static Memory getConstant(String className, String lowerClassName, String constant, Environment env, TraceInfo trace, ConstantCallCache callCache, int cacheIndex) {
ConstantEntity constantEntity = null;
if (callCache != null) {
constantEntity = callCache.get(env, cacheIndex);
}
if (constantEntity == null) {
ClassEntity entity = env.fetchClass(className, lowerClassName, true);
if (entity == null) {
env.error(trace, Messages.ERR_CLASS_NOT_FOUND.fetch(className));
return Memory.NULL;
}
constantEntity = entity.findConstant(constant);
if (constantEntity == null) {
env.error(trace, Messages.ERR_UNDEFINED_CLASS_CONSTANT.fetch(constant));
return Memory.NULL;
}
if (callCache != null) {
callCache.put(env, cacheIndex, constantEntity);
}
}
Memory value = constantEntity.getValue(env);
if (value == null) {
return Memory.NULL;
}
return value;
}
use of php.runtime.reflection.ClassEntity in project jphp by jphp-compiler.
the class SPLFunctions method class_parents.
public static Memory class_parents(Environment env, TraceInfo trace, Memory object, boolean autoLoad) {
ClassEntity entity;
if (object.isObject()) {
entity = object.toValue(ObjectMemory.class).getReflection();
} else {
entity = env.fetchClass(object.toString(), autoLoad);
}
if (entity == null) {
env.warning(trace, "class_parents(): Class %s does not exist and could not be loaded", object.toString());
return Memory.FALSE;
}
ArrayMemory result = new ArrayMemory();
do {
entity = entity.getParent();
if (entity == null)
break;
result.refOfIndex(entity.getName()).assign(entity.getName());
} while (true);
return result.toConstant();
}
use of php.runtime.reflection.ClassEntity in project jphp by jphp-compiler.
the class ModuleDumper method load.
@Override
public ModuleEntity load(InputStream input) throws IOException {
DumpInputStream data = new DumpInputStream(input);
int STAMP = data.readInt();
if (STAMP != DUMP_STAMP)
throw new DumpException("Invalid file format");
int VERSION = data.readInt();
if (VERSION != DUMP_VERSION)
throw new DumpException("Invalid dump version - " + VERSION + ", only " + DUMP_VERSION);
// legacy
data.readLangMode();
ModuleEntity entity = new ModuleEntity(context);
entity.setName(data.readName());
entity.setInternalName(data.readName());
entity.setTrace(data.readTrace(context));
// constants
int count = data.readInt();
for (int i = 0; i < count; i++) {
ConstantEntity el = constantDumper.load(input);
el.setModule(entity);
entity.addConstant(el);
}
// closures
count = data.readInt();
for (int i = 0; i < count; i++) {
ClosureEntity el = closureDumper.load(input);
el.setModule(entity);
entity.addClosure(el);
}
count = data.readInt();
for (int i = 0; i < count; i++) {
GeneratorEntity el = generatorDumper.load(input);
el.setModule(entity);
entity.addGenerator(el);
}
// functions
count = data.readInt();
for (int i = 0; i < count; i++) {
FunctionEntity el = functionDumper.load(input);
el.setModule(entity);
entity.addFunction(el);
}
// classes
count = data.readInt();
ClassDumper classDumper = new ClassDumper(context, entity, env, debugInformation);
for (int i = 0; i < count; i++) {
ClassEntity el = classDumper.load(input);
el.setModule(entity);
entity.addClass(el);
}
// byte code
entity.setData(data.readRawData(Integer.MAX_VALUE));
data.readRawData(1024 * 1024 * 5);
return entity;
}
Aggregations