Search in sources :

Example 31 with ObjectMemory

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;
    }
}
Also used : TimeZone(java.util.TimeZone) ObjectMemory(php.runtime.memory.ObjectMemory) ParseException(java.text.ParseException) Date(java.util.Date)

Example 32 with ObjectMemory

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();
}
Also used : ArrayMemory(php.runtime.memory.ArrayMemory) Invoker(php.runtime.invoke.Invoker) ObjectMemory(php.runtime.memory.ObjectMemory) Memory(php.runtime.Memory) ArrayMemory(php.runtime.memory.ArrayMemory) LongMemory(php.runtime.memory.LongMemory) ObjectMemory(php.runtime.memory.ObjectMemory) StringMemory(php.runtime.memory.StringMemory) StringMemory(php.runtime.memory.StringMemory) TraceInfo(php.runtime.env.TraceInfo)

Example 33 with ObjectMemory

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);
}
Also used : IObject(php.runtime.lang.IObject) ObjectMemory(php.runtime.memory.ObjectMemory)

Example 34 with ObjectMemory

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();
        }
    }
}
Also used : ClassEntity(php.runtime.reflection.ClassEntity) IObject(php.runtime.lang.IObject) Closure(php.runtime.lang.Closure) ObjectMemory(php.runtime.memory.ObjectMemory) Memory(php.runtime.Memory) ArrayMemory(php.runtime.memory.ArrayMemory) ReferenceMemory(php.runtime.memory.ReferenceMemory) ObjectMemory(php.runtime.memory.ObjectMemory) StringMemory(php.runtime.memory.StringMemory) MethodEntity(php.runtime.reflection.MethodEntity) StringMemory(php.runtime.memory.StringMemory) CriticalException(php.runtime.exceptions.CriticalException)

Example 35 with ObjectMemory

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);
}
Also used : IObject(php.runtime.lang.IObject) ObjectMemory(php.runtime.memory.ObjectMemory)

Aggregations

ObjectMemory (php.runtime.memory.ObjectMemory)55 ArrayMemory (php.runtime.memory.ArrayMemory)24 Memory (php.runtime.Memory)19 ClassEntity (php.runtime.reflection.ClassEntity)17 StringMemory (php.runtime.memory.StringMemory)14 IObject (php.runtime.lang.IObject)11 Invoker (php.runtime.invoke.Invoker)6 LongMemory (php.runtime.memory.LongMemory)6 Environment (php.runtime.env.Environment)5 MethodEntity (php.runtime.reflection.MethodEntity)5 Calendar (java.util.Calendar)4 Closure (php.runtime.lang.Closure)4 Locale (java.util.Locale)3 Test (org.junit.Test)3 WrapLocale (php.runtime.ext.core.classes.util.WrapLocale)3 PropertyEntity (php.runtime.reflection.PropertyEntity)3 AbstractFunctionEntity (php.runtime.reflection.support.AbstractFunctionEntity)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Date (java.util.Date)2 TimeZone (java.util.TimeZone)2