starfederation/datastar-php
A PHP SDK for working with Datastar.
Maintainers
1.0.1
2026-06-02 18:56 UTC
Requires
- php: >=8.1
Requires (Dev)
- craftcms/ecs: dev-main
- craftcms/phpstan: dev-main
- pestphp/pest: ^3.5
Suggests
None
Provides
None
Conflicts
None
Replaces
None
mit a02c72956c9ee80fe7ae2ce28d1112cf92c6ffbf
This package is auto-updated.
Last update: 2026-06-02 18:56:21 UTC
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, ]); // Removes elements from 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');
