Search in sources :

Example 6 with OutputBuffer

use of php.runtime.output.OutputBuffer in project jphp by jphp-compiler.

the class OutputFunctions method ob_list_handlers.

public static Memory ob_list_handlers(Environment env) {
    ArrayMemory result = new ArrayMemory();
    OutputBuffer peek = env.peekOutputBuffer();
    ArrayList<OutputBuffer> list = new ArrayList<OutputBuffer>();
    while (peek != null && !peek.isRoot()) {
        list.add(0, peek);
        peek = peek.getParentOutput();
    }
    for (OutputBuffer e : list) {
        result.refOfPush().assign(e.getName());
    }
    return result.toConstant();
}
Also used : ArrayMemory(php.runtime.memory.ArrayMemory) ArrayList(java.util.ArrayList) OutputBuffer(php.runtime.output.OutputBuffer)

Example 7 with OutputBuffer

use of php.runtime.output.OutputBuffer in project jphp by jphp-compiler.

the class OutputFunctions method ob_clean.

public static boolean ob_clean(Environment env, TraceInfo trace) throws Throwable {
    OutputBuffer buffer = env.peekOutputBuffer();
    if (buffer != null && !buffer.isRoot()) {
        buffer.setTrace(trace);
        buffer.clean();
        return true;
    } else {
        env.error(trace, ErrorType.E_NOTICE, "ob_clean(): failed to delete buffer. No buffer to delete");
        return false;
    }
}
Also used : OutputBuffer(php.runtime.output.OutputBuffer)

Example 8 with OutputBuffer

use of php.runtime.output.OutputBuffer in project jphp by jphp-compiler.

the class OutputFunctions method ob_end_clean.

public static boolean ob_end_clean(Environment env, TraceInfo trace) throws Throwable {
    OutputBuffer buffer = env.peekOutputBuffer();
    if (buffer != null && !buffer.isRoot()) {
        buffer.setTrace(trace);
        buffer.setStatus(OutputBuffer.HANDLER_FINAL);
        buffer.clean();
        env.popOutputBuffer();
        return true;
    } else {
        env.error(trace, ErrorType.E_NOTICE, "ob_end_clean(): failed to delete buffer. No buffer to delete");
        return false;
    }
}
Also used : OutputBuffer(php.runtime.output.OutputBuffer)

Example 9 with OutputBuffer

use of php.runtime.output.OutputBuffer in project jphp by jphp-compiler.

the class OutputFunctions method ob_get_clean.

public static Memory ob_get_clean(Environment env, TraceInfo trace) throws Throwable {
    OutputBuffer buffer = env.peekOutputBuffer();
    if (buffer != null && !buffer.isRoot()) {
        Memory result = buffer.getContents();
        buffer.setTrace(trace);
        buffer.clean();
        return result;
    } else {
        //env.error(trace, ErrorType.E_NOTICE, "ob_get_clean(): failed to delete and clean buffer. No buffer to delete or clean");
        return Memory.FALSE;
    }
}
Also used : Memory(php.runtime.Memory) ArrayMemory(php.runtime.memory.ArrayMemory) LongMemory(php.runtime.memory.LongMemory) OutputBuffer(php.runtime.output.OutputBuffer)

Example 10 with OutputBuffer

use of php.runtime.output.OutputBuffer 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)

Aggregations

OutputBuffer (php.runtime.output.OutputBuffer)12 ArrayMemory (php.runtime.memory.ArrayMemory)4 ArrayList (java.util.ArrayList)2 Memory (php.runtime.Memory)2 LongMemory (php.runtime.memory.LongMemory)2 Invoker (php.runtime.invoke.Invoker)1