Search in sources :

Example 91 with ArrayMemory

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();
}
Also used : ArrayMemory(php.runtime.memory.ArrayMemory)

Example 92 with ArrayMemory

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();
}
Also used : ArrayMemory(php.runtime.memory.ArrayMemory) Invoker(php.runtime.invoke.Invoker) ObjectMemory(php.runtime.memory.ObjectMemory) Memory(php.runtime.Memory) ArrayMemory(php.runtime.memory.ArrayMemory) LongMemory(php.runtime.memory.LongMemory) ObjectMemory(php.runtime.memory.ObjectMemory) StringMemory(php.runtime.memory.StringMemory) StringMemory(php.runtime.memory.StringMemory) TraceInfo(php.runtime.env.TraceInfo)

Example 93 with ArrayMemory

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());
            }
        }
    }
}
Also used : ForeachIterator(php.runtime.lang.ForeachIterator) Memory(php.runtime.Memory) ArrayMemory(php.runtime.memory.ArrayMemory) LongMemory(php.runtime.memory.LongMemory) KeyValueMemory(php.runtime.memory.KeyValueMemory) ObjectMemory(php.runtime.memory.ObjectMemory)

Example 94 with ArrayMemory

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();
}
Also used : ArrayMemory(php.runtime.memory.ArrayMemory) ForeachIterator(php.runtime.lang.ForeachIterator)

Example 95 with ArrayMemory

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());
            }
        }
    };
}
Also used : ArrayMemory(php.runtime.memory.ArrayMemory) PathResourceResolver(org.springframework.web.servlet.resource.PathResourceResolver) ResourceHandlerRegistration(org.springframework.web.servlet.config.annotation.ResourceHandlerRegistration) Memory(php.runtime.Memory) ArrayMemory(php.runtime.memory.ArrayMemory) GzipResourceResolver(org.springframework.web.servlet.resource.GzipResourceResolver) ResourceHandlerRegistry(org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry) ResourceChainRegistration(org.springframework.web.servlet.config.annotation.ResourceChainRegistration)

Aggregations

ArrayMemory (php.runtime.memory.ArrayMemory)148 Memory (php.runtime.Memory)60 ForeachIterator (php.runtime.lang.ForeachIterator)41 ObjectMemory (php.runtime.memory.ObjectMemory)35 LongMemory (php.runtime.memory.LongMemory)31 StringMemory (php.runtime.memory.StringMemory)29 ReferenceMemory (php.runtime.memory.ReferenceMemory)25 KeyValueMemory (php.runtime.memory.KeyValueMemory)17 Invoker (php.runtime.invoke.Invoker)9 ClassEntity (php.runtime.reflection.ClassEntity)9 Signature (php.runtime.annotation.Reflection.Signature)6 IObject (php.runtime.lang.IObject)6 Map (java.util.Map)4 Test (org.junit.Test)4 DoubleMemory (php.runtime.memory.DoubleMemory)4 ConcurrentEnvironment (php.runtime.env.ConcurrentEnvironment)3 TraceInfo (php.runtime.env.TraceInfo)3 ModuleEntity (php.runtime.reflection.ModuleEntity)3 ParameterEntity (php.runtime.reflection.ParameterEntity)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2