Search in sources :

Example 41 with ForeachIterator

use of php.runtime.lang.ForeachIterator in project jphp by jphp-compiler.

the class WrapFlow method toString.

@Signature(@Arg(value = "separator"))
public Memory toString(Environment env, Memory... args) {
    String sep = args[0].toString();
    ForeachIterator iterator = getSelfIterator(env);
    StringBuilderMemory sb = new StringBuilderMemory();
    int i = 0;
    while (iterator.next()) {
        if (i != 0)
            sb.append(sep);
        sb.append(iterator.getValue());
        i++;
    }
    return sb;
}
Also used : ForeachIterator(php.runtime.lang.ForeachIterator)

Example 42 with ForeachIterator

use of php.runtime.lang.ForeachIterator in project jphp by jphp-compiler.

the class WrapFlow method count.

@Signature
public Memory count(Environment env, Memory... args) {
    int cnt = 0;
    ForeachIterator iterator = getSelfIterator(env);
    while (iterator.next()) cnt++;
    return LongMemory.valueOf(cnt);
}
Also used : ForeachIterator(php.runtime.lang.ForeachIterator)

Example 43 with ForeachIterator

use of php.runtime.lang.ForeachIterator in project jphp by jphp-compiler.

the class WrapFlow method toArray.

@Signature
public Memory toArray(Environment env, Memory... args) {
    ForeachIterator iterator = getSelfIterator(env);
    ArrayMemory r = new ArrayMemory();
    while (iterator.next()) {
        if (withKeys)
            r.put(iterator.getKey(), iterator.getValue());
        else
            r.add(iterator.getValue());
    }
    return r.toConstant();
}
Also used : ForeachIterator(php.runtime.lang.ForeachIterator)

Example 44 with ForeachIterator

use of php.runtime.lang.ForeachIterator 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 45 with ForeachIterator

use of php.runtime.lang.ForeachIterator 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

ForeachIterator (php.runtime.lang.ForeachIterator)100 ArrayMemory (php.runtime.memory.ArrayMemory)49 Memory (php.runtime.Memory)47 LongMemory (php.runtime.memory.LongMemory)22 KeyValueMemory (php.runtime.memory.KeyValueMemory)18 ReferenceMemory (php.runtime.memory.ReferenceMemory)16 Invoker (php.runtime.invoke.Invoker)12 ObjectMemory (php.runtime.memory.ObjectMemory)12 IObject (php.runtime.lang.IObject)9 ArrayKeyMemory (php.runtime.memory.helper.ArrayKeyMemory)6 ArrayValueMemory (php.runtime.memory.helper.ArrayValueMemory)6 ShortcutMemory (php.runtime.memory.helper.ShortcutMemory)5 Signature (php.runtime.annotation.Reflection.Signature)4 StringMemory (php.runtime.memory.StringMemory)4 File (java.io.File)3 HashSet (java.util.HashSet)3 Element (org.w3c.dom.Element)3 FastMethod (php.runtime.annotation.Runtime.FastMethod)3 ClassEntity (php.runtime.reflection.ClassEntity)3 PropertyEntity (php.runtime.reflection.PropertyEntity)3