Search in sources :

Example 16 with Signature

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()));
    }
}
Also used : WrapTime(php.runtime.ext.core.classes.time.WrapTime) Signature(php.runtime.annotation.Reflection.Signature)

Example 17 with Signature

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());
            }
        }
    }
}
Also used : WrapTime(php.runtime.ext.core.classes.time.WrapTime) BinaryMemory(php.runtime.memory.BinaryMemory) Stream(php.runtime.ext.core.classes.stream.Stream) InputStream(java.io.InputStream) Signature(php.runtime.annotation.Reflection.Signature)

Example 18 with Signature

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);
}
Also used : ClassEntity(php.runtime.reflection.ClassEntity) Intent(android.content.Intent) Signature(php.runtime.annotation.Reflection.Signature)

Example 19 with Signature

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);
}
Also used : LinearLayout(android.widget.LinearLayout) Signature(php.runtime.annotation.Reflection.Signature)

Example 20 with Signature

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;
}
Also used : Memory(php.runtime.Memory) ArrayMemory(php.runtime.memory.ArrayMemory) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) WrapURLConnection(php.runtime.ext.net.WrapURLConnection) URLConnection(java.net.URLConnection) ForeachIterator(php.runtime.lang.ForeachIterator) OutputStream(java.io.OutputStream) Stream(php.runtime.ext.core.classes.stream.Stream) InputStream(java.io.InputStream) WrapURLConnection(php.runtime.ext.net.WrapURLConnection) File(java.io.File) Signature(php.runtime.annotation.Reflection.Signature)

Aggregations

Signature (php.runtime.annotation.Reflection.Signature)30 ArrayMemory (php.runtime.memory.ArrayMemory)8 InputStream (java.io.InputStream)4 Memory (php.runtime.Memory)4 ForeachIterator (php.runtime.lang.ForeachIterator)4 StringMemory (php.runtime.memory.StringMemory)4 ZipEntry (java.util.zip.ZipEntry)2 DOMSource (javax.xml.transform.dom.DOMSource)2 StreamResult (javax.xml.transform.stream.StreamResult)2 Stream (php.runtime.ext.core.classes.stream.Stream)2 WrapTime (php.runtime.ext.core.classes.time.WrapTime)2 LongMemory (php.runtime.memory.LongMemory)2 Intent (android.content.Intent)1 Button (android.widget.Button)1 EditText (android.widget.EditText)1 ImageView (android.widget.ImageView)1 LinearLayout (android.widget.LinearLayout)1 TextView (android.widget.TextView)1 HikariConfig (com.zaxxer.hikari.HikariConfig)1 HikariDataSource (com.zaxxer.hikari.HikariDataSource)1