use of php.runtime.memory.ObjectMemory in project jphp by jphp-compiler.
the class WrapTimeFormat method parse.
@Signature({ @Arg("string"), @Arg(value = "timeZone", nativeType = WrapTimeZone.class, optional = @Optional("null")) })
public Memory parse(Environment env, Memory... args) {
try {
TimeZone timeZone = WrapTimeZone.getTimeZone(env, args[1]);
Date date = getDateFormat(timeZone).parse(args[0].toString());
return new ObjectMemory(new WrapTime(env, date, timeZone));
} catch (ParseException e) {
return Memory.NULL;
}
}
use of php.runtime.memory.ObjectMemory in project jphp by jphp-compiler.
the class FileObject method findFiles.
@Signature(@Arg(value = "filter", optional = @Optional("NULL")))
public Memory findFiles(final Environment env, Memory... args) {
File[] result;
if (args[0].isNull()) {
result = file.listFiles();
} else {
final Invoker invoker = Invoker.valueOf(env, null, args[0]);
if (invoker == null) {
exception(env, "Invalid filter value, must be callable");
return Memory.NULL;
}
final TraceInfo trace = env.trace();
invoker.setTrace(trace);
result = file.listFiles(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
FileObject o = new FileObject(env, __class__, dir);
Memory[] args = new Memory[] { new ObjectMemory(o), new StringMemory(name) };
return invoker.callNoThrow(args).toBoolean();
}
});
}
ArrayMemory arr = new ArrayMemory();
if (result != null) {
for (File e : result) {
arr.add(new ObjectMemory(new FileObject(env, __class__, e)));
}
}
return arr.toConstant();
}
use of php.runtime.memory.ObjectMemory in project jphp by jphp-compiler.
the class ObjectInvokeHelper method issetProperty.
public static Memory issetProperty(Memory object, String property, Environment env, TraceInfo trace, PropertyCallCache callCache, int cacheIndex) throws Throwable {
object = object.toValue();
if (!object.isObject()) {
return Memory.NULL;
//env.error(trace, Messages.ERR_CANNOT_GET_PROPERTY_OF_NON_OBJECT.fetch(property));
}
IObject iObject = ((ObjectMemory) object).value;
return iObject.getReflection().issetProperty(env, trace, iObject, property, callCache, cacheIndex);
}
use of php.runtime.memory.ObjectMemory 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.memory.ObjectMemory in project jphp by jphp-compiler.
the class ObjectInvokeHelper method getRefProperty.
public static Memory getRefProperty(Memory object, String property, Environment env, TraceInfo trace, PropertyCallCache callCache, int cacheIndex) throws Throwable {
object = object.toValue();
if (!object.isObject()) {
env.error(trace, Messages.ERR_CANNOT_GET_PROPERTY_OF_NON_OBJECT.fetch(property));
return Memory.NULL;
}
IObject iObject = ((ObjectMemory) object).value;
return iObject.getReflection().getRefProperty(env, trace, iObject, property, callCache, cacheIndex);
}
Aggregations