使用任何web瀏覽器或WebView作為GUI,后端使用您喜歡的語(yǔ)言,前端使用現(xiàn)代web技術(shù),所有這些都在一個(gè)輕量級(jí)的便攜式庫(kù)中。
composer require kingbes/webui
要求 | 狀態(tài) |
---|---|
PHP | 8.1+ |
FFI | * |
Windows | true |
Linux | 待測(cè)試 |
MacOs | 待測(cè)試 |
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<!-- 必須加入webui.js,否則無(wú)法交互 -->
<script src="webui.js"></script>
</head>
<body>
<button onclick="btn()">asd</button>
<script>
function btn() {
hello('hello').then(function (res) {
console.log(res)
})
}
</script>
</body>
</html>
index.php
require "./vendor/autoload.php";
use Kingbes\Webui;
use Kingbes\JavaScript;
// 實(shí)例
$Webui = new Webui;
// html字符串
$html = file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . "index.html");
// 創(chuàng)建一個(gè)窗口
$window = $Webui->newWindow();
// 綁定js函數(shù)
$bind = $Webui->bind($window, "hello", function ($event, JavaScript $js) {
// 獲取第一個(gè)參數(shù)為字符串
$arg_one = $js->getString($event);
var_dump($arg_one);
// 返回字符串
$js->returnString($event, "nihao");
});
// 顯示窗口
$Webui->show($window, $html);
// 等待
$Webui->wait();
// 釋放所有
$Webui->clean();
Webui
窗口的方法類(lèi)JavaScript
用于與js綁定交互用Wrapper
包裝器,對(duì)整個(gè)交互進(jìn)行包裝等Cobj
C的對(duì)象類(lèi),部分功能可能需要
nice