Search in sources :

Example 51 with ObjectMemory

use of php.runtime.memory.ObjectMemory in project jphp by jphp-compiler.

the class WrapTime method today.

@Signature({ @Arg(value = "timeZone", nativeType = WrapTimeZone.class, optional = @Optional("NULL")), @Arg(value = "locale", nativeType = WrapLocale.class, optional = @Optional("NULL")) })
public static Memory today(Environment env, Memory... args) {
    Date date1 = new Date();
    Locale aLocale = args[1].isNull() ? Locale.ENGLISH : args[1].toObject(WrapLocale.class).getLocale();
    Calendar calendar = Calendar.getInstance(WrapTimeZone.getTimeZone(env, args[0]), aLocale);
    calendar.setTime(date1);
    calendar.set(Calendar.HOUR_OF_DAY, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.MILLISECOND, 0);
    return new ObjectMemory(new WrapTime(env, calendar.getTime(), calendar.getTimeZone(), aLocale));
}
Also used : WrapLocale(php.runtime.ext.core.classes.util.WrapLocale) Locale(java.util.Locale) ObjectMemory(php.runtime.memory.ObjectMemory) Calendar(java.util.Calendar) Date(java.util.Date)

Example 52 with ObjectMemory

use of php.runtime.memory.ObjectMemory in project jphp by jphp-compiler.

the class WrapTime method now.

@Signature({ @Arg(value = "timeZone", nativeType = WrapTimeZone.class, optional = @Optional("null")), @Arg(value = "locale", nativeType = WrapLocale.class, optional = @Optional("NULL")) })
public static Memory now(Environment env, Memory... args) {
    Locale aLocale = args[1].isNull() ? Locale.ENGLISH : args[1].toObject(WrapLocale.class).getLocale();
    TimeZone zone = WrapTimeZone.getTimeZone(env, args[0]);
    return new ObjectMemory(new WrapTime(env, Calendar.getInstance(zone, aLocale).getTime(), zone, aLocale));
}
Also used : WrapLocale(php.runtime.ext.core.classes.util.WrapLocale) Locale(java.util.Locale) TimeZone(java.util.TimeZone) ObjectMemory(php.runtime.memory.ObjectMemory)

Example 53 with ObjectMemory

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()));
}
Also used : ArrayMemory(php.runtime.memory.ArrayMemory) 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) Calendar(java.util.Calendar)

Example 54 with ObjectMemory

use of php.runtime.memory.ObjectMemory in project jphp by jphp-compiler.

the class FunctionEntity method getClosure.

@Override
public Closure getClosure(Environment env) {
    if (cachedClosure != null)
        return cachedClosure;
    final FunctionEntity bind = this;
    final ClosureEntity closureEntity1 = new ClosureEntity(this.getContext());
    closureEntity1.setParent(env.scope.fetchUserClass(Closure.class));
    closureEntity1.parameters = this.parameters;
    closureEntity1.setReturnReference(this.isReturnReference());
    MethodEntity m = new MethodEntity(this);
    m.setClazz(closureEntity1);
    m.setName("__invoke");
    closureEntity1.addMethod(m, null);
    closureEntity1.doneDeclare();
    Closure tmp = new Closure(env, closureEntity1, new ObjectMemory(env.getLateObject()), null, new Memory[0]) {

        @Override
        public Memory __invoke(Environment e, Memory... args) {
            try {
                return bind.invoke(e, e.peekCall(0).trace, args);
            } catch (RuntimeException e1) {
                throw e1;
            } catch (Throwable throwable) {
                throw new RuntimeException(throwable);
            }
        }

        @Override
        public Memory getOrCreateStatic(String name) {
            return Memory.NULL;
        }

        @Override
        public ClassEntity getReflection() {
            return closureEntity1;
        }
    };
    try {
        m.setNativeMethod(tmp.getClass().getDeclaredMethod("__invoke", Environment.class, Memory[].class));
    } catch (NoSuchMethodException e) {
        throw new RuntimeException(e);
    }
    return cachedClosure = tmp;
}
Also used : AbstractFunctionEntity(php.runtime.reflection.support.AbstractFunctionEntity) Closure(php.runtime.lang.Closure) ObjectMemory(php.runtime.memory.ObjectMemory) ClosureEntity(php.runtime.reflection.helper.ClosureEntity) Memory(php.runtime.Memory) ObjectMemory(php.runtime.memory.ObjectMemory) Environment(php.runtime.env.Environment)

Example 55 with ObjectMemory

use of php.runtime.memory.ObjectMemory in project jphp by jphp-compiler.

the class MethodEntity method getClosure.

/*
            ClassNode classNode = clazz.getClassNode();
            for(Object m : classNode.methods) {
                MethodNode method = (MethodNode) m;
                if (method.name.equals(getInternalName()) ){
                    return cachedMethodNode = method;
                }
            }

        throw new CriticalException("Cannot find MethodNode for method - " + name + "(" + getSignatureString(true) + ")");
    */
public Closure getClosure(Environment env, final IObject object) {
    if (cachedClosure != null)
        return cachedClosure;
    final MethodEntity bind = this;
    final ClosureEntity closureEntity1 = new ClosureEntity(this.getContext());
    closureEntity1.setParent(env.scope.fetchUserClass(Closure.class));
    closureEntity1.parameters = this.parameters;
    closureEntity1.setReturnReference(this.isReturnReference());
    MethodEntity m = new MethodEntity(this);
    m.setClazz(closureEntity1);
    m.setName("__invoke");
    closureEntity1.addMethod(m, null);
    closureEntity1.doneDeclare();
    Closure tmp = new Closure(env, closureEntity1, new ObjectMemory(env.getLateObject()), clazz.getName(), new Memory[0]) {

        @Override
        public Memory __invoke(Environment e, Memory... args) {
            try {
                if (object == null)
                    return bind.invokeStatic(e, args);
                else
                    return bind.invokeDynamic(object, e, args);
            } catch (RuntimeException e1) {
                throw e1;
            } catch (Throwable throwable) {
                throw new RuntimeException(throwable);
            }
        }

        @Override
        public Memory getOrCreateStatic(String name) {
            return Memory.NULL;
        }

        @Override
        public ClassEntity getReflection() {
            return closureEntity1;
        }
    };
    try {
        m.setNativeMethod(tmp.getClass().getDeclaredMethod("__invoke", Environment.class, Memory[].class));
    } catch (NoSuchMethodException e) {
        throw new RuntimeException(e);
    }
    return cachedClosure = tmp;
}
Also used : Closure(php.runtime.lang.Closure) ObjectMemory(php.runtime.memory.ObjectMemory) ClosureEntity(php.runtime.reflection.helper.ClosureEntity) Memory(php.runtime.Memory) ObjectMemory(php.runtime.memory.ObjectMemory) Environment(php.runtime.env.Environment)

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