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