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;
}
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);
}
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();
}
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();
}
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();
}
Aggregations