starfederation/datastar-php 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

starfederation/datastar-php

最新稳定版本:1.0.0-RC.5

Composer 安装命令:

composer require starfederation/datastar-php

包简介

A PHP SDK for working with Datastar.

README 文档

README

Stable Version Total Downloads

Datastar PHP SDK

This package provides a PHP SDK for working with Datastar.

License

This package is licensed for free under the MIT License.

Requirements

This package requires PHP 8.1 or later.

Installation

Install using composer.

composer require starfederation/datastar-php

Usage

use starfederation\datastar\ServerSentEventGenerator;

// Reads signals from the request.
$signals = ServerSentEventGenerator::readSignals();
use starfederation\datastar\enums\EventType;
use starfederation\datastar\enums\ElementPatchMode;
use starfederation\datastar\ServerSentEventGenerator;

// Creates a new `ServerSentEventGenerator` instance.
$sse = new ServerSentEventGenerator();

// Sends the response headers. 
// If your framework has its own way of sending response headers, manually send the headers returned by `ServerSentEventGenerator::headers()` instead.
$sse->sendHeaders();

// Patches elements into the DOM.
$sse->patchElements('<div></div>', [
    'selector' => '#my-div',
    'mode' => ElementPatchMode::Append,
    'useViewTransition' => true,
]);

// Patches elements into the DOM.
$sse->removeElements('#my-div', [
    'useViewTransition' => true,
]);

// Patches signals.
$sse->patchSignals('{foo: 123}', [
    'onlyIfMissing' => true,
]);

// Executes JavaScript in the browser.
$sse->executeScript('console.log("Hello, world!")', [
    'autoRemove' => true,
    'attributes' => [
        'type' => 'application/javascript',
    ],
]);

// Redirects the browser by setting the location to the provided URI.
$sse->location('/guide');

统计信息

  • 总下载量: 12.64k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 37
  • 点击次数: 1
  • 依赖项目数: 7
  • 推荐数: 0

GitHub 信息

  • Stars: 36
  • Watchers: 3
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: mit
  • 更新时间: 2024-11-15