use of php.runtime.memory.ArrayMemory in project jphp by jphp-compiler.
the class ArrayFunctions method array_column.
public static Memory array_column(Environment env, TraceInfo trace, Memory input, Memory columnKey, Memory indexKey) {
if (expecting(env, trace, 1, input, ARRAY)) {
if (columnKey.isNull() && indexKey.isNull())
return array_values(env, trace, input);
ArrayMemory result = new ArrayMemory();
ForeachIterator iterator = input.getNewIterator(env, false, false);
while (iterator.next()) {
Memory value = iterator.getValue();
if (indexKey.isNull()) {
result.add(value.valueOfIndex(columnKey).toImmutable());
} else {
if (columnKey.isNull())
result.refOfIndex(value.valueOfIndex(indexKey)).assign(value.toImmutable());
else
result.refOfIndex(value.valueOfIndex(indexKey)).assign(value.valueOfIndex(columnKey));
}
}
return result.toConstant();
} else
return Memory.NULL;
}
use of php.runtime.memory.ArrayMemory in project jphp by jphp-compiler.
the class ArrayFunctions method array_change_key_case.
public static Memory array_change_key_case(Environment env, TraceInfo trace, Memory input, int _case) {
if (expecting(env, trace, 1, input, ARRAY)) {
ArrayMemory result = new ArrayMemory();
ForeachIterator iterator = input.getNewIterator(env, false, false);
while (iterator.next()) {
Object key = iterator.getKey();
if (key instanceof String) {
String str = (String) key;
str = _case == 0 ? str.toLowerCase() : str.toUpperCase();
result.put(str, iterator.getValue().toImmutable());
} else
result.put(key, iterator.getValue().toImmutable());
}
return result.toConstant();
}
return Memory.NULL;
}
use of php.runtime.memory.ArrayMemory in project jphp by jphp-compiler.
the class ReflectionFunction method getParameters.
@Override
@Signature
public Memory getParameters(Environment env, Memory... args) {
if (cachedParameters != null)
return cachedParameters;
if (functionEntity instanceof CompileFunctionEntity)
exception(env, "Cannot get parameters for internal function %s()", functionEntity.getName());
ParameterEntity[] parameters = closureEntity == null ? functionEntity.getParameters() : closureEntity.parameters;
ClassEntity entity = env.fetchClass("ReflectionParameter");
ArrayMemory result = new ArrayMemory();
int i = 0;
for (ParameterEntity param : parameters) {
ReflectionParameter e = new ReflectionParameter(env, entity);
e.setEntity(param);
e.setFunctionEntity(functionEntity);
e.setPosition(i);
i++;
result.add(new ObjectMemory(e));
}
return cachedParameters = result;
}
use of php.runtime.memory.ArrayMemory in project jphp by jphp-compiler.
the class ReflectionMethod method getParameters.
@Override
@Signature
public Memory getParameters(Environment env, Memory... args) {
if (cachedParameters != null)
return cachedParameters;
ParameterEntity[] parameters = methodEntity.getParameters(Integer.MAX_VALUE);
ClassEntity entity = env.fetchClass("ReflectionParameter");
ArrayMemory result = new ArrayMemory();
int i = 0;
for (ParameterEntity param : parameters) {
ReflectionParameter e = new ReflectionParameter(env, entity);
e.setEntity(param);
e.setFunctionEntity(methodEntity);
e.setPosition(i);
i++;
result.add(new ObjectMemory(e));
}
return cachedParameters = result;
}
use of php.runtime.memory.ArrayMemory in project jphp by jphp-compiler.
the class WrapTimeZone method __construct.
@Signature({ @Arg("rawOffset"), @Arg("ID"), @Arg(value = "properties", type = HintType.ARRAY, optional = @Optional("null")) })
public Memory __construct(Environment env, Memory... args) {
if (args[2].isNull()) {
timeZone = new SimpleTimeZone(args[0].toInteger(), args[1].toString());
} else {
ArrayMemory props = args[2].toValue(ArrayMemory.class);
int startMonth = props.valueOfIndex("start_month").toInteger();
int startDay = props.valueOfIndex("start_day").toInteger();
int startDayOfWeek = props.valueOfIndex("start_day_of_week").toInteger();
int startTime = props.valueOfIndex("start_time").toInteger();
int endMonth = props.valueOfIndex("end_month").toInteger();
int endDay = props.valueOfIndex("end_day").toInteger();
int endDayOfWeek = props.valueOfIndex("end_day_of_week").toInteger();
int endTime = props.valueOfIndex("end_time").toInteger();
timeZone = new SimpleTimeZone(args[0].toInteger(), args[1].toString(), startMonth, startDay, startDayOfWeek, startTime, endMonth, endDay, endDayOfWeek, endTime);
}
return Memory.NULL;
}
Aggregations