Skip to content

A set of PHP helper classes for working with Datastar.

License

Notifications You must be signed in to change notification settings

putyourlightson/datastar-php

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Datastar PHP

A dependency-free set of PHP helper classes for working with Datastar.

License

This plugin is licensed for free under the MIT License.

Requirements

This plugin requires Datastar 0.19.3 or later and PHP 8.0.0 or later.

Installation

Install using composer or download and require the classes manually.

composer require putyourlightson/datastar-php

Usage

Datastar Event Class

use putyourlightson\datastar\events\FragmentEvent;
use putyourlightson\datastar\events\SignalEvent;
use putyourlightson\datastar\events\DeleteEvent;
use putyourlightson\datastar\events\RedirectEvent;
use putyourlightson\datastar\events\ConsoleEvent;

$event = new FragmentEvent();
$event->content = '<div id="primary">New content</div>';
// Optional
$event->id = 1;
$event->selector = '#secondary';
$event->merge = 'morph';
$event->settle = 100;
$event->vt = 'false';

$event = new SignalEvent();
$event->store = '{foo: "bar"}';
// Optional
$event->id = 1;
$event->onlyIfMissing = 'true';

$event = new DeleteEvent();
$event->selector = '#primary';
// Optional
$event->id = 1;

$event = new RedirectEvent();
$event->content = '/new-url';
// Optional
$event->id = 1;

$event = new ConsoleEvent();
$event->content = 'Hello world';
// Optional
$event->id = 1;
$event->mode = 'error';

// Returns the output of a Datastar event.
$output = $event->getOutput();

Datastar Response Class

use putyourlightson\datastar\DatastarResponse;

$response = new DatastarResponse();

// Sends Datastar events to the browser.
$response->sendEvent($event1);
$response->sendEvent($event2);
$response->sendEvent($event3);

// Ends the response and closes the connection.
$response->end();

Created by PutYourLightsOn.

About

A set of PHP helper classes for working with Datastar.

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published

Languages