Search in sources :

Example 66 with ArrayMemory

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

the class PropertyGetCommand method run.

@Override
public void run(Debugger context, CommandArguments args, Document result) {
    DebugTick tick = context.getRegisteredTick();
    Element response = createResponse(args, result);
    response.setAttribute("encoding", "base64");
    String varName = args.get("n");
    if (varName.startsWith("$")) {
        varName = varName.substring(1);
    }
    ArrayMemory locals = tick.getLocals();
    if (!locals.containsKey(varName)) {
        return;
    }
    ContextValueProvider provider = getContextValueProvider(context, result);
    if (provider.getMaxData() != 0 && args.containsKey("m")) {
        try {
            provider.setMaxData(Integer.parseInt(args.get("m")));
        } catch (NumberFormatException e) {
            return;
        }
    }
    Element property = provider.getProperty(null, locals.valueOfIndex(varName));
    response.setAttribute("size", property.getAttribute("size"));
    response.appendChild(property.getFirstChild());
}
Also used : ArrayMemory(php.runtime.memory.ArrayMemory) DebugTick(org.develnext.jphp.debug.impl.DebugTick) ContextValueProvider(org.develnext.jphp.debug.impl.command.support.ContextValueProvider) Element(org.w3c.dom.Element)

Example 67 with ArrayMemory

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

the class ContextValueProvider method processObject.

protected void processObject(Element property, ObjectMemory objectMemory, Set<Integer> used) {
    IObject value = objectMemory.value;
    ArrayMemory properties = value.getProperties();
    property.setAttribute("classname", value.getReflection().getName());
    if (properties != null) {
        processArray(property, properties, used, true);
    }
}
Also used : ArrayMemory(php.runtime.memory.ArrayMemory) IObject(php.runtime.lang.IObject)

Example 68 with ArrayMemory

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

the class UserFunctionTest method testWithGlobals.

@Test
public void testWithGlobals() {
    ArrayMemory globals = new ArrayMemory();
    globals.refOfIndex("y").assign("bar");
    Memory memory = includeResource("user_function/with_globals.php", globals);
    Assert.assertEquals("foobar", memory.toString());
}
Also used : ArrayMemory(php.runtime.memory.ArrayMemory) Memory(php.runtime.Memory) ArrayMemory(php.runtime.memory.ArrayMemory) Test(org.junit.Test)

Example 69 with ArrayMemory

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

the class HttpClientExtension method arrayToCookie.

public static HttpCookie arrayToCookie(ArrayMemory array) {
    Memory name = array.valueOfIndex("name");
    if (!name.toBoolean()) {
        throw new IllegalArgumentException("Cookie name is empty");
    }
    HttpCookie cookie = new HttpCookie(name.toString(), array.valueOfIndex("value").toString());
    if (array.containsKey("domain")) {
        cookie.setDomain(array.valueOfIndex("domain").toString());
    }
    if (array.containsKey("path")) {
        cookie.setPath(array.valueOfIndex("path").toString());
    }
    if (array.containsKey("secure")) {
        cookie.setSecure(array.valueOfIndex("secure").toBoolean());
    }
    if (array.containsKey("maxAge")) {
        cookie.setMaxAge(array.valueOfIndex("maxAge").toLong());
    }
    if (array.containsKey("comment")) {
        cookie.setComment(array.valueOfIndex("comment").toString());
    }
    if (array.containsKey("discard")) {
        cookie.setDiscard(array.valueOfIndex("discard").toBoolean());
    }
    if (array.containsKey("ports")) {
        cookie.setPortlist(array.valueOfIndex("ports").toString());
    }
    if (array.containsKey("version")) {
        cookie.setVersion(array.valueOfIndex("version").toInteger());
    }
    if (array.containsKey("httpOnly")) {
        cookie.setHttpOnly(array.valueOfIndex("httpOnly").toBoolean());
    }
    return cookie;
}
Also used : Memory(php.runtime.Memory) ArrayMemory(php.runtime.memory.ArrayMemory) HttpCookie(java.net.HttpCookie)

Example 70 with ArrayMemory

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

the class PHttpClient method makeConnection.

@Signature
protected URLConnection makeConnection(PHttpRequest request, Environment env) throws Throwable {
    URL url = new URL(request.getUrl());
    URLConnection connection = proxy == null ? url.openConnection() : url.openConnection(proxy);
    if (connection instanceof HttpURLConnection) {
        HttpURLConnection httpURLConnection = (HttpURLConnection) connection;
        httpURLConnection.setReadTimeout(timeout);
        httpURLConnection.setConnectTimeout(timeout);
        httpURLConnection.setRequestMethod(request.getMethod());
        httpURLConnection.setDoInput(true);
        httpURLConnection.setDoOutput(true);
        // cookies.
        ArrayMemory cookies = request.getCookies();
        ForeachIterator iterator = cookies.foreachIterator(false, false);
        StringBuilder cookieHeader = new StringBuilder();
        while (iterator.next()) {
            String name = iterator.getStringKey();
            String value = iterator.getValue().toString();
            cookieHeader.append(URLEncoder.encode(name, "UTF-8")).append('=').append(URLEncoder.encode(value, "UTF-8")).append(';');
        }
        httpURLConnection.setRequestProperty("Cookie", cookieHeader.toString());
        ArrayMemory headers = request.getHeaders();
        iterator = headers.foreachIterator(false, false);
        while (iterator.next()) {
            String name = iterator.getStringKey();
            Memory value = iterator.getValue();
            if (value.isTraversable()) {
                ForeachIterator subIterator = value.getNewIterator(env);
                while (subIterator.next()) {
                    httpURLConnection.addRequestProperty(name, subIterator.getValue().toString());
                }
            } else {
                httpURLConnection.addRequestProperty(name, value.toString());
            }
        }
        Memory body = request.getBody(env);
        if (body.instanceOf(PHttpBody.class)) {
            body.toObject(PHttpBody.class).apply(env, ObjectMemory.valueOf(new WrapURLConnection(env, connection)));
        } else {
            OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream());
            writer.write(request.getBody(env).toBinaryString());
            writer.close();
        }
        return httpURLConnection;
    } else {
        throw new IllegalStateException("HttpClient::makeConnection() method must return instance of HttpURLConnection");
    }
}
Also used : ArrayMemory(php.runtime.memory.ArrayMemory) ForeachIterator(php.runtime.lang.ForeachIterator) Memory(php.runtime.Memory) ArrayMemory(php.runtime.memory.ArrayMemory) ObjectMemory(php.runtime.memory.ObjectMemory) StringMemory(php.runtime.memory.StringMemory) WrapURLConnection(php.runtime.ext.net.WrapURLConnection) WrapURLConnection(php.runtime.ext.net.WrapURLConnection)

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