Search in sources :

Example 26 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)

Example 27 with Invoker

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

the class OutputFunctions method ob_start.

public static Memory ob_start(Environment env, TraceInfo trace, Memory outputCallback, Memory _chunkSize, Memory erase) {
    Invoker invoker;
    if (!outputCallback.isNull()) {
        invoker = expectingCallback(env, trace, 1, outputCallback);
        if (invoker == null)
            return Memory.FALSE;
        invoker.check("ob_start", trace);
    }
    switch(_chunkSize.getRealType()) {
        case ARRAY:
        case STRING:
        case OBJECT:
            env.warning(trace, "ob_start() expects parameter 2 to be long, " + _chunkSize.getRealType().toString() + " given");
            return Memory.NULL;
    }
    switch(erase.getRealType()) {
        case ARRAY:
        case STRING:
        case OBJECT:
            env.warning(trace, "ob_start() expects parameter 3 to be long, " + erase.getRealType().toString() + " given");
            return Memory.NULL;
    }
    int chunkSize = _chunkSize.toInteger();
    if (chunkSize < 0)
        chunkSize = 0;
    if (chunkSize < 0) {
        env.warning(trace, "ob_start(): chunk_size must be grater or equal than zero");
        return Memory.FALSE;
    }
    OutputBuffer buffer = env.peekOutputBuffer();
    if (buffer != null && buffer.isLock())
        env.error(trace, "ob_start(): Cannot use output buffering in output buffering display handlers");
    env.pushOutputBuffer(outputCallback, chunkSize, erase.toBoolean());
    return Memory.TRUE;
}
Also used : Invoker(php.runtime.invoke.Invoker) OutputBuffer(php.runtime.output.OutputBuffer)

Example 28 with Invoker

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

the class WrapClassLoader method _getSplClassLoader.

protected synchronized SplClassLoader _getSplClassLoader(Environment env) {
    if (splClassLoader == null) {
        ArrayMemory callback = new ArrayMemory();
        callback.add(this);
        callback.add("loadClass");
        Invoker invoker = Invoker.valueOf(env, null, callback);
        splClassLoader = new SplClassLoader(invoker, callback);
    }
    return splClassLoader;
}
Also used : ArrayMemory(php.runtime.memory.ArrayMemory) SplClassLoader(php.runtime.env.SplClassLoader) Invoker(php.runtime.invoke.Invoker)

Example 29 with Invoker

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

the class WrapEnvironment method execute.

@Signature(@Arg(value = "runnable"))
public Memory execute(Environment env, Memory... args) throws Throwable {
    Invoker invoker = Invoker.valueOf(this.environment, null, args[0]);
    if (invoker == null) {
        env.exception("Argument 1 must be callable in environment");
        return Memory.NULL;
    }
    invoker.setTrace(env.trace());
    return invoker.call();
}
Also used : Invoker(php.runtime.invoke.Invoker)

Example 30 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 : ArrayMemory(php.runtime.memory.ArrayMemory) ForeachIterator(php.runtime.lang.ForeachIterator) Invoker(php.runtime.invoke.Invoker)

Aggregations

Invoker (php.runtime.invoke.Invoker)50 Memory (php.runtime.Memory)21 ArrayMemory (php.runtime.memory.ArrayMemory)13 ForeachIterator (php.runtime.lang.ForeachIterator)12 LongMemory (php.runtime.memory.LongMemory)9 ObjectMemory (php.runtime.memory.ObjectMemory)9 KeyValueMemory (php.runtime.memory.KeyValueMemory)7 StringMemory (php.runtime.memory.StringMemory)7 Environment (php.runtime.env.Environment)6 ReferenceMemory (php.runtime.memory.ReferenceMemory)5 SplClassLoader (php.runtime.env.SplClassLoader)4 File (java.io.File)2 MemorySerializer (org.develnext.jphp.json.gson.MemorySerializer)2 UIReader (org.develnext.jphp.swing.loader.UIReader)2 TraceInfo (php.runtime.env.TraceInfo)2 FileObject (php.runtime.ext.core.classes.stream.FileObject)2 ActionEvent (java.awt.event.ActionEvent)1 MessageDigest (java.security.MessageDigest)1 Scanner (java.util.Scanner)1 FileFilter (javax.swing.filechooser.FileFilter)1