myphp-runtime
类型化访问MyPHP应用程序的运行时; 为他们的网络前端服务。
MyPHP将其运行时注入到应用程序的每个页面中 window.myphp。这
包为它提供了类型和导入。客户端 myphp generate 写
为你绑定的PHP服务是建立在它上面的,所以你主要使用它:
import { Greeter, events } from "./myphp"; // generated
const greeting = await Greeter.greet("Ada");
events.tick.on((time) => console.log(time));
从npm安装它, npm install myphp-runtime,或者依赖于它
应用程序运行在MyPHP上, "myphp-runtime": "file:<MyPHP>/packages/runtime",
作为 myphp init -template web 写它。它的模块是TypeScript,其中
维特和布恩安于现状。
将包直接用于窗口和平台:
import { currentWindow, isCallError, isMyPHP, runtime } from "myphp-runtime";
if (isMyPHP() && runtime().platform === "darwin") {
document.body.classList.add("mac");
}
await currentWindow.toggleMaximize();
一个PHP方法,通过 MyPHP\Channel 参数需要
一个 Channel 取而代之的是:
import { Channel } from "myphp-runtime";
const lines = new Channel<string>();
const done = Shell.tail("ls -R", lines);
for await (const line of lines) console.log(line);
await done;
抛出拒绝的PHP方法 CallError (见
isCallError). 在MyPHP窗口外,例如,当开发服务器在
浏览器,呼叫拒绝和 isMyPHP() 是假的。
myphp-runtime/i18n 在其页面中格式化应用程序目录的信息,
作为 MyPHP\Message 在PHP: ICU MessageFormat的消息,与复数
的规则、号码和日期 Intl。 myphp generate 的类型化模块
客户端旁边的目录(locales.ts)之上;
import { messages } from "./locales"; // generated
status.textContent = messages.filesSelected(3); // "3 files selected"
formatMessage(locale, message, args) 格式化您自己的消息。