use of php.runtime.annotation.Reflection.Signature in project jphp by jphp-compiler.
the class PSqlStatement method bindTimestamp.
@Signature
public void bindTimestamp(Environment env, int index, Memory value) throws SQLException {
if (value.instanceOf(WrapTime.class)) {
WrapTime time = value.toObject(WrapTime.class);
statement.setTimestamp(index + 1, new Timestamp(time.getDate().getTime()), time.getCalendar());
} else {
statement.setTimestamp(index + 1, new Timestamp(value.toLong()));
}
}
use of php.runtime.annotation.Reflection.Signature in project jphp by jphp-compiler.
the class PSqlStatement method bind.
@Signature
public void bind(Environment env, int index, Memory value) throws SQLException {
if (value.instanceOf(WrapTime.class)) {
WrapTime time = value.toObject(WrapTime.class);
statement.setDate(index + 1, new Date(time.getDate().getTime()), time.getCalendar());
} else if (value.instanceOf(Stream.class)) {
statement.setBlob(index + 1, Stream.getInputStream(env, value));
} else if (value.toValue() instanceof BinaryMemory) {
statement.setBytes(index + 1, value.getBinaryBytes(env.getDefaultCharset()));
} else {
if (value.isNull()) {
statement.setNull(index + 1, Types.NULL);
} else {
switch(value.getRealType()) {
case INT:
statement.setLong(index + 1, value.toLong());
break;
case DOUBLE:
statement.setDouble(index + 1, value.toDouble());
break;
case BOOL:
statement.setBoolean(index + 1, value.toBoolean());
break;
default:
statement.setString(index + 1, value.toString());
}
}
}
}
use of php.runtime.annotation.Reflection.Signature in project jphp by jphp-compiler.
the class WrapAndroid method startActivity.
@Signature
public static void startActivity(Environment env, String clazz) throws ClassNotFoundException {
ClassEntity entity = env.fetchClass(clazz);
if (entity == null) {
env.exception(Messages.ERR_CLASS_NOT_FOUND.fetch(clazz));
return;
}
Intent intent = new Intent(AndroidStandaloneLoader.getContext(), entity.getNativeClass());
AndroidStandaloneLoader.getMainActivity().startActivity(intent);
}
use of php.runtime.annotation.Reflection.Signature in project jphp by jphp-compiler.
the class WrapLinearLayout method __construct.
@Signature
public void __construct(WrapActivity activity) {
__wrappedObject = new LinearLayout(activity);
getWrappedObject().setOrientation(LinearLayout.VERTICAL);
}
use of php.runtime.annotation.Reflection.Signature in project jphp by jphp-compiler.
the class PHttpMultipartFormBody method apply.
@Override
@Signature
public Memory apply(Environment env, Memory... args) throws IOException {
WrapURLConnection connection = args[0].toObject(WrapURLConnection.class);
URLConnection conn = connection.getWrappedObject();
OutputStream out = connection.getOutputStream();
conn.setRequestProperty("Cache-Control", "no-cache");
conn.setRequestProperty("Content-Type", "multipart/form-data;boundary=" + this.boundary);
ForeachIterator iterator = fields.foreachIterator(false, false);
while (iterator.next()) {
StringBuilder sb = new StringBuilder();
String name = iterator.getStringKey();
Memory value = iterator.getValue();
sb.append("--").append(boundary).append(CRLF);
sb.append("Content-Disposition: form-data; name=\"").append(name).append("\"").append(CRLF);
sb.append("Content-Type: text/plain; charset=").append(encoding).append(CRLF);
sb.append(CRLF).append(value).append(CRLF);
out.write(sb.toString().getBytes());
}
iterator = files.foreachIterator(false, false);
while (iterator.next()) {
StringBuilder sb = new StringBuilder();
String name = iterator.getStringKey();
String fileName = name;
Memory value = iterator.getValue();
InputStream inputStream = Stream.getInputStream(env, value);
if (inputStream == null) {
throw new IllegalStateException("File '" + name + "' is not valid file or stream");
}
if (value.instanceOf(Stream.class)) {
Stream stream = value.toObject(Stream.class);
fileName = new File(stream.getPath()).getName();
} else {
fileName = new File(value.toString()).getName();
}
sb.append("--").append(boundary).append(CRLF).append("Content-Disposition: form-data; name=\"").append(URLEncoder.encode(name, encoding)).append("\"; filename=\"").append(URLEncoder.encode(fileName, encoding)).append("\"").append(CRLF);
sb.append("Content-Type: ").append(URLConnection.guessContentTypeFromName(fileName)).append(CRLF);
sb.append("Content-Transfer-Encoding: binary").append(CRLF).append(CRLF);
out.write(sb.toString().getBytes());
byte[] buff = new byte[4096];
int len;
while ((len = inputStream.read(buff)) > 0) {
out.write(buff, 0, len);
}
Stream.closeStream(env, inputStream);
sb.append(CRLF);
}
out.write(("--" + boundary + "--").getBytes());
out.write(CRLF.getBytes());
return Memory.NULL;
}
Aggregations