Search in sources :

Example 51 with Invoker

use of php.runtime.invoke.Invoker in project jphp by jphp-compiler.

the class ItemsUtils method map.

@Signature({ @Arg(value = "collection", type = HintType.TRAVERSABLE), @Arg(value = "callback", type = HintType.CALLABLE) })
public static Memory map(Environment env, Memory... args) throws Throwable {
    ForeachIterator iterator = args[0].getNewIterator(env);
    if (iterator == null) {
        return Memory.NULL;
    }
    Invoker callback = Invoker.valueOf(env, null, args[1]);
    if (callback == null) {
        return Memory.NULL;
    }
    ArrayMemory r = new ArrayMemory();
    while (iterator.next()) {
        r.refOfIndex(iterator.getMemoryKey()).assign(callback.call(iterator.getValue()));
    }
    return r.toConstant();
}
Also used : ForeachIterator(php.runtime.lang.ForeachIterator) Invoker(php.runtime.invoke.Invoker)

Example 52 with Invoker

use of php.runtime.invoke.Invoker in project jphp by jphp-compiler.

the class PHttpServer method filters.

@Signature
public Memory filters() {
    ArrayMemory result = ArrayMemory.createListed(filters.getHandlers().length);
    for (Handler handler : filters.getHandlers()) {
        if (handler instanceof InvokeHandler) {
            Invoker invoker = ((InvokeHandler) handler).getInvoker();
            result.add(invoker.getMemory().toImmutable());
        }
    }
    return result.toImmutable();
}
Also used : Invoker(php.runtime.invoke.Invoker) SessionHandler(org.eclipse.jetty.server.session.SessionHandler) WebSocketHandler(org.eclipse.jetty.websocket.server.WebSocketHandler) Signature(php.runtime.annotation.Reflection.Signature)

Example 53 with Invoker

use of php.runtime.invoke.Invoker in project jphp by jphp-compiler.

the class JsonProcessor method onSerialize.

@Signature({ @Arg("type"), @Arg(value = "callback", type = HintType.CALLABLE, optional = @Optional("null")) })
public Memory onSerialize(Environment env, Memory... args) {
    Memory.Type type = Memory.Type.of(args[0].toString());
    if (type == null)
        throw new IllegalArgumentException("Invalid type - " + args[0]);
    MemorySerializer.Handler handler = null;
    if (!args[1].isNull()) {
        final Invoker invoker = Invoker.valueOf(env, env.trace(), args[1]);
        handler = new MemorySerializer.Handler() {

            @Override
            public Memory call(Environment env, Memory value) {
                return invoker.callNoThrow(value);
            }
        };
    }
    memorySerializer.setTypeHandler(type, handler);
    return null;
}
Also used : MemorySerializer(org.develnext.jphp.json.gson.MemorySerializer) Invoker(php.runtime.invoke.Invoker) ArrayMapEntryMemory(php.runtime.memory.support.ArrayMapEntryMemory) Memory(php.runtime.Memory) Environment(php.runtime.env.Environment)

Example 54 with Invoker

use of php.runtime.invoke.Invoker in project jphp by jphp-compiler.

the class JsonProcessor method onClassSerialize.

@Signature({ @Arg("className"), @Arg(value = "callback", type = HintType.CALLABLE, optional = @Optional("null")) })
public Memory onClassSerialize(Environment env, Memory... args) {
    ClassEntity entity = env.fetchClass(args[0].toString(), true);
    if (entity == null)
        throw new IllegalArgumentException("Class not found - " + args[0]);
    MemorySerializer.Handler handler = null;
    if (!args[1].isNull()) {
        final Invoker invoker = Invoker.valueOf(env, env.trace(), args[1]);
        handler = new MemorySerializer.Handler() {

            @Override
            public Memory call(Environment env, Memory value) {
                return invoker.callNoThrow(value);
            }
        };
    }
    memorySerializer.setClassHandler(entity.getName(), handler);
    return Memory.NULL;
}
Also used : ClassEntity(php.runtime.reflection.ClassEntity) MemorySerializer(org.develnext.jphp.json.gson.MemorySerializer) Invoker(php.runtime.invoke.Invoker) ArrayMapEntryMemory(php.runtime.memory.support.ArrayMapEntryMemory) Memory(php.runtime.Memory) Environment(php.runtime.env.Environment)

Example 55 with Invoker

use of php.runtime.invoke.Invoker in project jphp by jphp-compiler.

the class WrapFlow method each.

@Signature(@Arg(value = "callback", type = HintType.CALLABLE))
public Memory each(Environment env, Memory... args) {
    ForeachIterator iterator = getSelfIterator(env);
    Invoker invoker = Invoker.valueOf(env, null, args[0]);
    int cnt = 0;
    while (iterator.next()) {
        cnt++;
        if (call(iterator, invoker).toValue() == Memory.FALSE)
            break;
    }
    return LongMemory.valueOf(cnt);
}
Also used : ForeachIterator(php.runtime.lang.ForeachIterator) Invoker(php.runtime.invoke.Invoker)

Aggregations

Invoker (php.runtime.invoke.Invoker)61 Memory (php.runtime.Memory)29 ArrayMemory (php.runtime.memory.ArrayMemory)13 ForeachIterator (php.runtime.lang.ForeachIterator)12 LongMemory (php.runtime.memory.LongMemory)12 ObjectMemory (php.runtime.memory.ObjectMemory)12 StringMemory (php.runtime.memory.StringMemory)10 Environment (php.runtime.env.Environment)7 Signature (php.runtime.annotation.Reflection.Signature)5 KeyValueMemory (php.runtime.memory.KeyValueMemory)5 ReferenceMemory (php.runtime.memory.ReferenceMemory)5 SplClassLoader (php.runtime.env.SplClassLoader)4 FileObject (php.runtime.ext.core.classes.stream.FileObject)4 DynamicMethodInvoker (php.runtime.invoke.DynamicMethodInvoker)4 RunnableInvoker (php.runtime.invoke.RunnableInvoker)3 File (java.io.File)2 MemorySerializer (org.develnext.jphp.json.gson.MemorySerializer)2 UIReader (org.develnext.jphp.swing.loader.UIReader)2 SessionHandler (org.eclipse.jetty.server.session.SessionHandler)2 WebSocketHandler (org.eclipse.jetty.websocket.server.WebSocketHandler)2