Search in sources :

Example 46 with ArrayMemory

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

the class OutputFunctions method ob_list_handlers.

public static Memory ob_list_handlers(Environment env) {
    ArrayMemory result = new ArrayMemory();
    OutputBuffer peek = env.peekOutputBuffer();
    ArrayList<OutputBuffer> list = new ArrayList<OutputBuffer>();
    while (peek != null && !peek.isRoot()) {
        list.add(0, peek);
        peek = peek.getParentOutput();
    }
    for (OutputBuffer e : list) {
        result.refOfPush().assign(e.getName());
    }
    return result.toConstant();
}
Also used : ArrayMemory(php.runtime.memory.ArrayMemory) ArrayList(java.util.ArrayList) OutputBuffer(php.runtime.output.OutputBuffer)

Example 47 with ArrayMemory

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

the class WrapTimeFormat method __construct.

@Signature({ @Arg("format"), @Arg(value = "locale", nativeType = WrapLocale.class, optional = @Optional("null")), @Arg(value = "formatSymbols", type = HintType.ARRAY, optional = @Optional("null")) })
public Memory __construct(Environment env, Memory... args) {
    format = args[0].toString();
    if (args[2].isNull()) {
        if (args[1].isNull())
            dateFormat = new SimpleDateFormat(args[0].toString(), WrapLocale.getDefault(env));
        else
            dateFormat = new SimpleDateFormat(args[0].toString(), args[1].toObject(WrapLocale.class).getLocale());
    } else {
        final ArrayMemory symbols = args[2].toValue(ArrayMemory.class);
        dateFormat = new SimpleDateFormat(args[0].toString(), new DateFormatSymbols(WrapLocale.getDefault(env, args[1])) {

            {
                Memory months = symbols.getByScalar("months");
                if (months != null && months.isArray()) {
                    this.setMonths(months.toValue(ArrayMemory.class).toStringArray());
                }
                Memory shortMonths = symbols.getByScalar("short_months");
                if (shortMonths != null && shortMonths.isArray()) {
                    this.setShortMonths(shortMonths.toValue(ArrayMemory.class).toStringArray());
                }
                Memory eras = symbols.getByScalar("eras");
                if (eras != null && eras.isArray()) {
                    this.setEras(eras.toValue(ArrayMemory.class).toStringArray());
                }
                Memory weekdays = symbols.getByScalar("weekdays");
                if (weekdays != null && weekdays.isArray()) {
                    this.setWeekdays(weekdays.toValue(ArrayMemory.class).toStringArray());
                }
                Memory shortWeekdays = symbols.getByScalar("short_weekdays");
                if (shortWeekdays != null && shortWeekdays.isArray()) {
                    this.setShortWeekdays(shortWeekdays.toValue(ArrayMemory.class).toStringArray());
                }
                Memory amPm = symbols.getByScalar("am_pm");
                if (amPm != null && amPm.isArray()) {
                    this.setAmPmStrings(amPm.toValue(ArrayMemory.class).toStringArray());
                }
                Memory localPatternChars = symbols.getByScalar("local_pattern_chars");
                if (localPatternChars != null) {
                    this.setLocalPatternChars(localPatternChars.toString());
                }
            }
        });
    }
    return Memory.NULL;
}
Also used : ArrayMemory(php.runtime.memory.ArrayMemory) Memory(php.runtime.Memory) ArrayMemory(php.runtime.memory.ArrayMemory) ObjectMemory(php.runtime.memory.ObjectMemory) StringMemory(php.runtime.memory.StringMemory) DateFormatSymbols(java.text.DateFormatSymbols) SimpleDateFormat(java.text.SimpleDateFormat)

Example 48 with ArrayMemory

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

the class WrapTimeZone method __debugInfo.

@Signature
public Memory __debugInfo(Environment env, Memory... args) {
    ArrayMemory r = new ArrayMemory();
    r.refOfIndex("*id").assign(timeZone.getID());
    r.refOfIndex("*rawOffset").assign(timeZone.getRawOffset());
    r.refOfIndex("*name").assign(timeZone.getDisplayName());
    return r.toConstant();
}
Also used : ArrayMemory(php.runtime.memory.ArrayMemory)

Example 49 with ArrayMemory

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

the class ItemsUtils method reverse.

@Signature({ @Arg(value = "collection", type = HintType.ARRAY) })
public static Memory reverse(Environment env, Memory... args) {
    ForeachIterator iterator = args[0].getNewIterator(env);
    ArrayMemory result = new ArrayMemory();
    while (iterator.next()) {
        result.unshift(iterator.getValue().toImmutable());
    }
    return result.toConstant();
}
Also used : ArrayMemory(php.runtime.memory.ArrayMemory) ForeachIterator(php.runtime.lang.ForeachIterator)

Example 50 with ArrayMemory

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

the class ItemsUtils method toArray.

@Signature({ @Arg(value = "collection", type = HintType.TRAVERSABLE), @Arg(value = "withKeys", optional = @Optional("false")) })
public static Memory toArray(Environment env, Memory... args) {
    boolean withKeys = args[1].toBoolean();
    if (withKeys && args[0].isArray())
        return args[0].toImmutable();
    ForeachIterator iterator = args[0].getNewIterator(env);
    if (iterator == null) {
        return Memory.NULL;
    }
    ArrayMemory r = new ArrayMemory();
    while (iterator.next()) {
        if (withKeys)
            r.put(iterator.getMemoryKey(), iterator.getValue().toImmutable());
        else
            r.add(iterator.getValue().toImmutable());
    }
    return r.toConstant();
}
Also used : ArrayMemory(php.runtime.memory.ArrayMemory) ForeachIterator(php.runtime.lang.ForeachIterator)

Aggregations

ArrayMemory (php.runtime.memory.ArrayMemory)148 Memory (php.runtime.Memory)60 ForeachIterator (php.runtime.lang.ForeachIterator)41 ObjectMemory (php.runtime.memory.ObjectMemory)35 LongMemory (php.runtime.memory.LongMemory)31 StringMemory (php.runtime.memory.StringMemory)29 ReferenceMemory (php.runtime.memory.ReferenceMemory)25 KeyValueMemory (php.runtime.memory.KeyValueMemory)17 Invoker (php.runtime.invoke.Invoker)9 ClassEntity (php.runtime.reflection.ClassEntity)9 Signature (php.runtime.annotation.Reflection.Signature)6 IObject (php.runtime.lang.IObject)6 Map (java.util.Map)4 Test (org.junit.Test)4 DoubleMemory (php.runtime.memory.DoubleMemory)4 ConcurrentEnvironment (php.runtime.env.ConcurrentEnvironment)3 TraceInfo (php.runtime.env.TraceInfo)3 ModuleEntity (php.runtime.reflection.ModuleEntity)3 ParameterEntity (php.runtime.reflection.ParameterEntity)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2