use of php.runtime.memory.ObjectMemory in project jphp by jphp-compiler.
the class WrapTime method replace.
@Signature({ @Arg(value = "args", type = HintType.ARRAY) })
public Memory replace(Environment env, Memory... args) {
ArrayMemory arg = args[0].toValue(ArrayMemory.class);
Memory year = arg.getByScalar("year");
Memory month = arg.getByScalar("month");
Memory day = arg.getByScalar("day");
Memory hour = arg.getByScalar("hour");
Memory min = arg.getByScalar("min");
Memory sec = arg.getByScalar("sec");
Memory millis = arg.getByScalar("millis");
Calendar calendar1 = (Calendar) calendar.clone();
if (year != null)
calendar1.set(Calendar.YEAR, year.toInteger());
if (month != null)
calendar1.set(Calendar.MONTH, month.toInteger() - 1);
if (day != null)
calendar1.set(Calendar.DATE, day.toInteger());
if (hour != null)
calendar1.set(Calendar.HOUR_OF_DAY, hour.toInteger());
if (min != null)
calendar1.set(Calendar.MINUTE, min.toInteger());
if (sec != null)
calendar1.set(Calendar.SECOND, sec.toInteger());
if (millis != null)
calendar1.set(Calendar.MILLISECOND, millis.toInteger());
return new ObjectMemory(new WrapTime(env, calendar1.getTime(), calendar1.getTimeZone()));
}
use of php.runtime.memory.ObjectMemory in project jphp by jphp-compiler.
the class InvokeHelper method callStatic.
public static Memory callStatic(Environment env, TraceInfo trace, String className, String methodName, String originClassName, String originMethodName, Memory[] args, MethodCallCache callCache, int cacheIndex) throws Throwable {
if (callCache != null) {
MethodEntity entity = callCache.get(env, cacheIndex);
if (entity != null) {
return callStatic(env, trace, entity, originClassName, args, false);
}
}
ClassEntity classEntity = env.fetchClass(originClassName, className, true);
MethodEntity method = classEntity == null ? null : classEntity.findMethod(methodName);
Memory[] passed = null;
boolean isMagic = false;
if (method == null) {
IObject maybeObject = env.getLateObject();
if (maybeObject != null && maybeObject.getReflection().isInstanceOf(classEntity))
return ObjectInvokeHelper.invokeMethod(new ObjectMemory(maybeObject), originMethodName, methodName, env, trace, args);
if (classEntity != null && classEntity.methodMagicCallStatic != null) {
method = classEntity.methodMagicCallStatic;
isMagic = true;
passed = new Memory[] { new StringMemory(originMethodName), ArrayMemory.of(args) };
} else {
if (classEntity == null) {
env.error(trace, Messages.ERR_CLASS_NOT_FOUND.fetch(originClassName));
return Memory.NULL;
}
}
}
if (method == null) {
env.error(trace, Messages.ERR_CALL_TO_UNDEFINED_METHOD.fetch(originClassName + "::" + originMethodName));
return Memory.NULL;
}
if (!method.isStatic()) {
IObject maybeObject = env.getLateObject();
if (maybeObject != null && maybeObject.getReflection().isInstanceOf(classEntity))
return ObjectInvokeHelper.invokeMethod(maybeObject, method, env, trace, args, true);
env.error(trace, ErrorType.E_STRICT, Messages.ERR_NON_STATIC_METHOD_CALLED_DYNAMICALLY, originClassName, originMethodName);
}
if (callCache != null && !isMagic) {
callCache.put(env, cacheIndex, method);
}
checkAccess(env, trace, method);
if (passed == null)
passed = makeArguments(env, args, method.getParameters(), originClassName, originMethodName, trace);
Memory result = method.getImmutableResult();
if (result != null)
return result;
try {
if (trace != null)
env.pushCall(trace, null, args, originMethodName, method.getClazz().getName(), originClassName);
return method.invokeStatic(env, trace, passed);
} finally {
if (trace != null)
env.popCall();
}
}
use of php.runtime.memory.ObjectMemory in project jphp by jphp-compiler.
the class WrapThreadPool method schedule.
@Signature({ @Arg(value = "runnable", type = HintType.CALLABLE), @Arg("delay"), @Arg(value = "env", typeClass = "php\\lang\\Environment", optional = @Optional("NULL")) })
public Memory schedule(final Environment env, Memory... args) {
final Environment _env = args[2].isNull() ? env : args[2].toObject(WrapEnvironment.class).getWrapEnvironment();
final Invoker invoker = Invoker.valueOf(_env, null, args[0]);
ScheduledFuture<Memory> future = getScheduledExecutorService(env).schedule(new Callable<Memory>() {
@Override
public Memory call() throws Exception {
Environment.addThreadSupport(_env);
return invoker.callNoThrow();
}
}, args[1].toLong(), TimeUnit.MILLISECONDS);
return new ObjectMemory(new WrapFuture(env, future));
}
use of php.runtime.memory.ObjectMemory in project jphp by jphp-compiler.
the class LangFunctions method method_exists.
public static boolean method_exists(Environment env, Memory clazz, String method) {
ClassEntity classEntity;
if (clazz.isObject()) {
ObjectMemory tmp = clazz.toValue(ObjectMemory.class);
classEntity = tmp.getReflection();
} else {
String name = clazz.toString();
String nameL = name.toLowerCase();
classEntity = env.fetchClass(name, nameL, true);
if (classEntity == null)
classEntity = env.fetchMagicClass(name, nameL);
}
return classEntity != null && classEntity.findMethod(method.toLowerCase()) != null;
}
use of php.runtime.memory.ObjectMemory in project jphp by jphp-compiler.
the class LangFunctions method get_object_vars.
public static Memory get_object_vars(Environment env, TraceInfo trace, Memory object) {
if (expecting(env, trace, 1, object, Memory.Type.OBJECT)) {
ObjectMemory o = object.toValue(ObjectMemory.class);
ArrayMemory props = o.value.getProperties();
ClassEntity entity = o.getReflection();
ClassEntity context = env.getLastClassOnStack();
ForeachIterator iterator = props.foreachIterator(false, false);
ArrayMemory result = new ArrayMemory();
while (iterator.next()) {
PropertyEntity prop = entity.findProperty(iterator.getKey().toString());
if (prop == null || prop.canAccess(env, context) == 0)
result.refOfIndex(prop == null ? iterator.getKey().toString() : prop.getName()).assign(iterator.getValue());
}
return result.toConstant();
} else
return Memory.NULL;
}
Aggregations