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());
}
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);
}
}
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());
}
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;
}
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");
}
}
Aggregations