亚洲乱色熟女一区二区三区丝袜,天堂√中文最新版在线,亚洲精品乱码久久久久久蜜桃图片,香蕉久久久久久av成人,欧美丰满熟妇bbb久久久

LOGO OA教程 ERP教程 模切知識交流 PMS教程 CRM教程 開發(fā)文檔 其他文檔  
 
網(wǎng)站管理員

使用 PHP 和 Web 技術(shù)(而不是 Electron)構(gòu)建桌面應(yīng)用程序

admin
2025年7月11日 16:52 本文熱度 1220

介紹

Boson 是一個創(chuàng)新的跨平臺桌面應(yīng)用程序開發(fā)平臺,它釋放了 Web 技術(shù)(PHP、JavaScript、HTML、CSS)的強(qiáng)大功能以及本機(jī)匯編的優(yōu)勢。它的主要功能是將基于 Chromium 的 WebView 引擎和 PHP 解釋器直接集成到可執(zhí)行文件應(yīng)用程序中。

該解決方案允許開發(fā)人員:

  • 使用熟悉的堆棧技術(shù) — 通過 HTML/CSS 創(chuàng)建接口并在 PHP(使用 JavaScript 元素)中實現(xiàn)邏輯,而無需學(xué)習(xí)特定于平臺的語言。
  • 通過 Chromium 引擎實現(xiàn)穩(wěn)定渲染,在 Windows、macOS 和 Linux 上提供可靠的用戶體驗 。
  • 減少單個代碼庫計數(shù)器的開發(fā)時間 — 更改在所有平臺之間自動同步。
  • 簡化分發(fā) — 自包含的二進(jìn)制文件不需要安裝額外的運行時。

Boson 的設(shè)計功能使其成為想要超越瀏覽器應(yīng)用程序的 Web 開發(fā)人員的正確選擇。該庫完全允許使用本機(jī) API,而不是通常的工作流程,即自動將 Web 組件轉(zhuǎn)換為桌面界面?,F(xiàn)成的應(yīng)用程序保留了本機(jī)程序的所有優(yōu)勢,包括對文件系統(tǒng)和系統(tǒng)資源的訪問,同時保持跨平臺“開箱即用”。

Boson 不是什么?

Boson 不是一個 GUI 框架。 我們不是在這里決定您的應(yīng)用程序的外觀或感覺。使用最適合您的工作流程的任何前端堆棧 — React、Angular、Vue、Svelte、jQuery,或者只是經(jīng)典的 HTML 和 CSS。更喜歡 Bootstrap、Bulma 還是 Tailwind?去做吧。您的 UI,您的規(guī)則。

Boson 不啟動 HTTP 服務(wù)器 (與 NativePHP 不同)也不依賴 Node.js。沒有不穩(wěn)定的解決方法,沒有額外的層,也沒有不必要的數(shù)據(jù)轉(zhuǎn)換。只需直接、簡化地訪問渲染器 - 所有這些都在一個統(tǒng)一的過程中完成。

Boson 不依賴繁重的依賴項 ,也不是 Electron 或 NativePHP 的分支。它利用了作系統(tǒng)上已有的工具,使您的應(yīng)用程序保持輕量級。Boson 不像典型的 Electron 或 NativePHP 應(yīng)用程序那樣消耗數(shù)百兆字節(jié),而是將其占用空間保持在幾千字節(jié)——通過設(shè)計高效。

Boson 也沒有像 JPHP (Devel Studio/Devel Next) 那樣重新發(fā)明 PHP。它使用您已經(jīng)熟悉和喜愛的現(xiàn)代 PHP——沒有分叉,沒有驚喜。

忘記復(fù)雜的設(shè)置或自定義 PHP 擴(kuò)展。只需運行一個命令即可開始: composer require boson-php/runtime — 然后您就可以開始工作了。

安裝

運行時  — 充當(dāng) PHP 代碼和底層作系統(tǒng)之間的橋梁。這是您可以在運行時和開發(fā)期間使用的主要 API編譯器  – 允許您將工作結(jié)果構(gòu)建到完成的項目中,以便分發(fā)。

運行時

Boson 運行時提供了庫的核心,并允許您運行出色的應(yīng)用程序。

Library 作為 Composer 存儲庫提供,可以使用以下命令安裝在項目的根目錄中:

composer require boson-php/runtime

不要忘記在您的應(yīng)用程序中包含自動加載文件。

<?php

require __DIR__ . '/vendor/autoload.php';

$app = new Boson\Application();

編譯器

Boson 編譯器使您能夠?qū)⒐ぷ鹘Y(jié)果組裝成最終產(chǎn)品。也就是說,導(dǎo)入到目標(biāo)平臺的可執(zhí)行文件中。

Library 作為 Composer 存儲庫提供,可以使用以下命令安裝在項目的根目錄中:

composer require boson-php/compiler --dev

編譯器只是開發(fā)時需要的,不是代碼執(zhí)行時需要的,因此建議將其作為 --dev 包包含在內(nèi)。

環(huán)境要求:PHP 8.4+ 開啟 ext-ffi 擴(kuò)展

案例

您可以在 Web Components 中使用 Twig。為此,您需要遵循幾個簡單的步驟。

1. 在您的項目中安裝 Twig 組件:

composer require twig/twig

2. 創(chuàng)建 Twig 組件

之后,您應(yīng)該創(chuàng)建一個支持 twig 渲染的組件。

use Boson\WebView\Api\WebComponents\ReactiveContext;
useBoson\WebView\Api\WebComponents\WebComponent;
useBoson\WebView\WebView;
useTwig\Environment;
useTwig\TemplateWrapper;

abstractclass TwigComponent extends WebComponent
{
    /**
     * In this case, the template will be initialized
     * once during the first render.
     */

    private TemplateWrapper $template {
        get => $this->template ??= $this->twig->createTemplate(
            template: $this->renderTwig(),
        );
    }

    publicfunction __construct(
        protected readonly Environment $twig,
        ReactiveContext $ctx,
        WebView $webview,
    )
 
{
        parent::__construct($ctx, $webview);
    }

    abstractprotectedfunction renderTwig()string;

    /**
     * Override the default render behavior by
     * redirecting it to a Twig template
     */

    #[\Override]
    finalpublicfunction render()string
    
{
        return$this->template->render(\get_object_vars($this));
    }
}

3. 創(chuàng)建 Instantiator

現(xiàn)在我們需要定義這些組件的確切創(chuàng)建方式,為此,我們應(yīng)該創(chuàng)建自己的實例化器,它將按需返回新組件。

use Boson\WebView\Api\WebComponents\Instantiator\WebComponentInstantiatorInterface;
useBoson\WebView\Api\WebComponents\ReactiveContext;
useBoson\WebView\WebView;
useTwig\Environment;
useTwig\Loader\ArrayLoader;

final readonly class TwigComponentInstantiator implements
    WebComponentInstantiatorInterface
{
    private Environment $twig;

    publicfunction __construct()
    
{
        $this->twig = new Environment(new ArrayLoader());
    }

    privatefunction isTwigComponent(string $component)bool
    
{
        return \is_subclass_of($component, TwigComponent::class);
    }

    publicfunction create(WebView $webview, ReactiveContext $context)object
    
{
        $component = $context->component;

        // Pass twig as a first argument in case of passed
        // component extends from TwigComponent class
        if ($this->isTwigComponent($component)) {
            returnnew $component($this->twig, $context, $webview);
        }

        returnnew $component($context, $webview);
    }
}

4. 注冊實例化器

要確定應(yīng)使用不同的實例化器,可以在 webview 配置中指定它。

$webComponentsConfig = new WebComponentsCreateInfo(
    instantiator: new TwigComponentInstantiator(),
);

$applicationConfig = new ApplicationCreateInfo(
    window: new WindowCreateInfo(
        webview: new WebViewCreateInfo(
            webComponents: $webComponentsConfig,
        ),
    ),
);

$app = new Boson\Application($applicationConfig);

5. Twig 組件

現(xiàn)在我們可以創(chuàng)建自定義 twig 組件了!

class MyTwigComponent extends TwigComponent
{
    protected array $items = [123];

    protected function renderTwig()string
    
{
        return <<<'twig'
            <ul>
                {% for item in items %}
                <li>{{ item }}</li>
                {% endfor %}
            </ul>
        twig;
    }
}

要注冊和檢查,只需寫幾行

$app->webview->defineComponent('my-list', MyTwigComponent::class);

$app->webview->html = '<my-list />';

?


該文章在 2025/7/11 16:52:11 編輯過
關(guān)鍵字查詢
相關(guān)文章
正在查詢...
點晴ERP是一款針對中小制造業(yè)的專業(yè)生產(chǎn)管理軟件系統(tǒng),系統(tǒng)成熟度和易用性得到了國內(nèi)大量中小企業(yè)的青睞。
點晴PMS碼頭管理系統(tǒng)主要針對港口碼頭集裝箱與散貨日常運作、調(diào)度、堆場、車隊、財務(wù)費用、相關(guān)報表等業(yè)務(wù)管理,結(jié)合碼頭的業(yè)務(wù)特點,圍繞調(diào)度、堆場作業(yè)而開發(fā)的。集技術(shù)的先進(jìn)性、管理的有效性于一體,是物流碼頭及其他港口類企業(yè)的高效ERP管理信息系統(tǒng)。
點晴WMS倉儲管理系統(tǒng)提供了貨物產(chǎn)品管理,銷售管理,采購管理,倉儲管理,倉庫管理,保質(zhì)期管理,貨位管理,庫位管理,生產(chǎn)管理,WMS管理系統(tǒng),標(biāo)簽打印,條形碼,二維碼管理,批號管理軟件。
點晴免費OA是一款軟件和通用服務(wù)都免費,不限功能、不限時間、不限用戶的免費OA協(xié)同辦公管理系統(tǒng)。
Copyright 2010-2025 ClickSun All Rights Reserved