use of php.runtime.memory.ArrayMemory in project jphp by jphp-compiler.
the class FileObject method listRoots.
@Signature
public static Memory listRoots(Environment env, Memory... args) {
ArrayMemory r = new ArrayMemory();
File[] roots = File.listRoots();
if (roots == null)
return r.toConstant();
for (File e : roots) {
r.add(new FileObject(env, e));
}
return r.toConstant();
}
use of php.runtime.memory.ArrayMemory in project jphp by jphp-compiler.
the class FileObject method findFiles.
@Signature(@Arg(value = "filter", optional = @Optional("NULL")))
public Memory findFiles(final Environment env, Memory... args) {
File[] result;
if (args[0].isNull()) {
result = file.listFiles();
} else {
final Invoker invoker = Invoker.valueOf(env, null, args[0]);
if (invoker == null) {
exception(env, "Invalid filter value, must be callable");
return Memory.NULL;
}
final TraceInfo trace = env.trace();
invoker.setTrace(trace);
result = file.listFiles(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
FileObject o = new FileObject(env, __class__, dir);
Memory[] args = new Memory[] { new ObjectMemory(o), new StringMemory(name) };
return invoker.callNoThrow(args).toBoolean();
}
});
}
ArrayMemory arr = new ArrayMemory();
if (result != null) {
for (File e : result) {
arr.add(new ObjectMemory(new FileObject(env, __class__, e)));
}
}
return arr.toConstant();
}
use of php.runtime.memory.ArrayMemory in project jphp by jphp-compiler.
the class ItemsUtils method flatten.
protected static void flatten(Environment env, ForeachIterator iterator, Set<Integer> used, ArrayMemory array, int level, int maxLevel) {
while (iterator.next()) {
Memory el = iterator.getValue();
ForeachIterator innerIterator = el.getNewIterator(env);
if (innerIterator == null || (level >= maxLevel && maxLevel > -1)) {
array.add(el.toImmutable());
} else {
if (used.add(el.getPointer())) {
flatten(env, innerIterator, used, array, level + 1, maxLevel);
used.remove(el.getPointer());
}
}
}
}
use of php.runtime.memory.ArrayMemory in project jphp by jphp-compiler.
the class ItemsUtils method keys.
@Signature({ @Arg(value = "collection", type = HintType.TRAVERSABLE) })
public static Memory keys(Environment env, Memory... args) {
ForeachIterator iterator = args[0].getNewIterator(env);
if (iterator == null) {
return Memory.NULL;
}
ArrayMemory r = new ArrayMemory();
while (iterator.next()) r.add(iterator.getMemoryKey());
return r.toConstant();
}
use of php.runtime.memory.ArrayMemory in project jphp by jphp-compiler.
the class PWebServer method _makeHandlers.
protected WebServerConfig.Handlers _makeHandlers() {
return new WebServerConfig.Handlers() {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
for (ArrayMemory handler : staticHandlers) {
Memory path = handler.valueOfIndex("path");
ResourceHandlerRegistration registration;
if (path.isArray()) {
registration = registry.addResourceHandler(path.toValue(ArrayMemory.class).toStringArray());
} else {
registration = registry.addResourceHandler(path.toString());
}
Memory cachePeriod = handler.valueOfIndex("cachePeriod");
registration.setCachePeriod(cachePeriod.isNull() ? null : cachePeriod.toInteger());
Memory location = handler.valueOfIndex("location");
if (location.isArray()) {
registration.addResourceLocations(location.toValue(ArrayMemory.class).toStringArray());
} else {
registration.addResourceLocations(location.toString());
}
ResourceChainRegistration chain = registration.resourceChain(handler.valueOfIndex("cache").toBoolean());
if (handler.valueOfIndex("gzip").toBoolean()) {
chain.addResolver(new GzipResourceResolver());
}
chain.addResolver(new PathResourceResolver());
}
}
};
}
Aggregations