Search in sources :

Example 31 with ArrayMemory

use of php.runtime.memory.ArrayMemory in project jphp by jphp-compiler.

the class Environment method __import.

/*public Memory __getConstant(String name, String lowerName, TraceInfo trace){
        Memory constant = findConstant(name, lowerName);

        if (constant == null){
            error(trace, E_NOTICE, Messages.ERR_USE_UNDEFINED_CONSTANT, name, name);
            int p = name.lastIndexOf(Information.NAMESPACE_SEP_CHAR);

            if (p > -1) // for global scope
                return StringMemory.valueOf(name.substring(p + 1));
            else
                return StringMemory.valueOf(name);
        }

        return constant;
    }*/
private Memory __import(String path, ArrayMemory locals, TraceInfo trace, String funcName, boolean once, Callback<Void, Void> callback) throws Throwable {
    synchronized (moduleManager) {
        if (once && moduleManager.hasModule(path)) {
            return Memory.TRUE;
        }
        ModuleEntity module = moduleManager.fetchCachedModule(path, path.endsWith(".phb"));
        if (module == null) {
            callback.call(null);
            return Memory.FALSE;
        }
        pushCall(trace, null, new Memory[] { StringMemory.valueOf(path) }, funcName, null, null);
        try {
            if (locals == null) {
                locals = new ArrayMemory();
            }
            return module.include(this, locals);
        } finally {
            popCall();
        }
    }
}
Also used : ArrayMemory(php.runtime.memory.ArrayMemory)

Example 32 with ArrayMemory

use of php.runtime.memory.ArrayMemory in project jphp by jphp-compiler.

the class HttpClientExtension method cookieToArray.

public static ArrayMemory cookieToArray(HttpCookie cookie) {
    ArrayMemory memory = new ArrayMemory();
    memory.refOfIndex("value").assign(cookie.getValue());
    memory.refOfIndex("name").assign(cookie.getName());
    memory.refOfIndex("domain").assign(cookie.getDomain());
    memory.refOfIndex("path").assign(cookie.getPath());
    memory.refOfIndex("secure").assign(cookie.getSecure());
    memory.refOfIndex("maxAge").assign(cookie.getMaxAge());
    memory.refOfIndex("comment").assign(cookie.getComment());
    memory.refOfIndex("discard").assign(cookie.getDiscard());
    memory.refOfIndex("ports").assign(cookie.getPortlist());
    memory.refOfIndex("version").assign(cookie.getVersion());
    memory.refOfIndex("httpOnly").assign(cookie.isHttpOnly());
    return memory;
}
Also used : ArrayMemory(php.runtime.memory.ArrayMemory)

Example 33 with ArrayMemory

use of php.runtime.memory.ArrayMemory in project jphp by jphp-compiler.

the class PHttpResponse method setRawCookies.

@Signature
public void setRawCookies(ArrayMemory rawCookies) {
    this.rawCookies = rawCookies;
    ArrayMemory cookies = new ArrayMemory();
    ForeachIterator iterator = rawCookies.foreachIterator(false, false);
    while (iterator.next()) {
        cookies.putAsKeyString(iterator.getStringKey(), iterator.getValue().valueOfIndex("value").toImmutable());
    }
    this.cookies = cookies;
}
Also used : ArrayMemory(php.runtime.memory.ArrayMemory) ForeachIterator(php.runtime.lang.ForeachIterator) Signature(php.runtime.annotation.Reflection.Signature)

Example 34 with ArrayMemory

use of php.runtime.memory.ArrayMemory in project jphp by jphp-compiler.

the class Environment method __tick.

/***** UTILS *****/
public void __tick(TraceInfo trace, ArrayMemory locals) {
    TickHandler tickHandler = scope.getTickHandler();
    if (tickHandler != null) {
        IObject $this = this.getLateObject();
        if ($this != null) {
            Memory value = ObjectMemory.valueOf($this);
            if ($this instanceof Closure) {
                value = ((Closure) $this).getSelf();
            }
            if (value.isObject()) {
                locals.putAsKeyString("this", value);
            }
        }
        tickHandler.onTick(this, trace, locals);
    }
}
Also used : ArrayMemory(php.runtime.memory.ArrayMemory) Memory(php.runtime.Memory) ReferenceMemory(php.runtime.memory.ReferenceMemory) ObjectMemory(php.runtime.memory.ObjectMemory) StringMemory(php.runtime.memory.StringMemory)

Example 35 with ArrayMemory

use of php.runtime.memory.ArrayMemory in project jphp by jphp-compiler.

the class ArrayFunctions method recursive_count.

private static int recursive_count(Environment env, TraceInfo trace, ArrayMemory array, Set<Integer> used) {
    ForeachIterator iterator = array.foreachIterator(false, false);
    int size = array.size();
    while (iterator.next()) {
        Memory el = iterator.getValue();
        if (el.isArray()) {
            if (used == null)
                used = new HashSet<>();
            int pointer = el.getPointer();
            if (!used.add(pointer)) {
                env.warning(trace, "recursion detected");
            } else {
                size += recursive_count(env, trace, array, used);
            }
            used.remove(pointer);
        }
    }
    return size;
}
Also used : ForeachIterator(php.runtime.lang.ForeachIterator) Memory(php.runtime.Memory) ArrayMemory(php.runtime.memory.ArrayMemory) LongMemory(php.runtime.memory.LongMemory) ObjectMemory(php.runtime.memory.ObjectMemory) HashSet(java.util.HashSet)

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