Search in sources :

Example 26 with ObjectMemory

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

the class ReflectionClass method getProperty.

@Signature(@Arg("name"))
public Memory getProperty(Environment env, Memory... args) {
    String name = args[0].toString();
    PropertyEntity e = entity.findProperty(name);
    if (e == null)
        e = entity.findStaticProperty(name);
    if (e == null)
        return Memory.NULL;
    ClassEntity classEntity = env.fetchClass("ReflectionProperty");
    ReflectionProperty prop = new ReflectionProperty(env, classEntity);
    prop.setEntity(e);
    return new ObjectMemory(prop);
}
Also used : ClassEntity(php.runtime.reflection.ClassEntity) PropertyEntity(php.runtime.reflection.PropertyEntity) ObjectMemory(php.runtime.memory.ObjectMemory)

Example 27 with ObjectMemory

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

the class ReflectionClass method getStaticProperties.

@Signature
public Memory getStaticProperties(Environment env, Memory... args) {
    ArrayMemory result = new ArrayMemory();
    ClassEntity classEntity = env.fetchClass("ReflectionProperty");
    for (PropertyEntity e : entity.getStaticProperties()) {
        ReflectionProperty prop = new ReflectionProperty(env, classEntity);
        prop.setEntity(e);
        result.add(new ObjectMemory(prop));
    }
    return result.toConstant();
}
Also used : ArrayMemory(php.runtime.memory.ArrayMemory) ClassEntity(php.runtime.reflection.ClassEntity) PropertyEntity(php.runtime.reflection.PropertyEntity) ObjectMemory(php.runtime.memory.ObjectMemory)

Example 28 with ObjectMemory

use of php.runtime.memory.ObjectMemory 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();
}
Also used : ArrayMemory(php.runtime.memory.ArrayMemory) ClassEntity(php.runtime.reflection.ClassEntity) ObjectMemory(php.runtime.memory.ObjectMemory)

Example 29 with ObjectMemory

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

the class WrapTime method of.

@Signature({ @Arg(value = "args", type = HintType.ARRAY), @Arg(value = "timeZone", nativeType = WrapTimeZone.class, optional = @Optional("null")), @Arg(value = "locale", nativeType = WrapLocale.class, optional = @Optional("null")) })
public static Memory of(Environment env, Memory... args) {
    Locale aLocale = args[2].isNull() ? Locale.ENGLISH : args[2].toObject(WrapLocale.class).getLocale();
    Calendar calendar = Calendar.getInstance(WrapTimeZone.getTimeZone(env, args[1]), aLocale);
    Memory arg = args[0];
    int year = arg.valueOfIndex("year").toInteger();
    Memory m = arg.toValue(ArrayMemory.class).getByScalar("month");
    int month = 1;
    if (m != null)
        month = m.toInteger();
    int day = arg.valueOfIndex("day").toInteger();
    if (day < 1)
        day = 1;
    int hour = arg.valueOfIndex("hour").toInteger();
    int min = arg.valueOfIndex("min").toInteger();
    int sec = arg.valueOfIndex("sec").toInteger();
    calendar.set(year, month - 1, day, hour, min, sec);
    calendar.set(Calendar.MILLISECOND, arg.valueOfIndex("millis").toInteger());
    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) 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 30 with ObjectMemory

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

the class WrapTime method add.

@Signature(@Arg(value = "args", type = HintType.ARRAY))
public Memory add(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.add(Calendar.YEAR, year.toInteger());
    if (month != null)
        calendar1.add(Calendar.MONTH, month.toInteger());
    if (day != null)
        calendar1.add(Calendar.DAY_OF_MONTH, day.toInteger());
    if (hour != null)
        calendar1.add(Calendar.HOUR_OF_DAY, hour.toInteger());
    if (min != null)
        calendar1.add(Calendar.MINUTE, min.toInteger());
    if (sec != null)
        calendar1.add(Calendar.SECOND, sec.toInteger());
    if (millis != null)
        calendar1.add(Calendar.MILLISECOND, millis.toInteger());
    return new ObjectMemory(new WrapTime(env, calendar1.getTime(), timeZone));
}
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)

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