Skip to content

RocketPHP-org/RocketUI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Quality Gate Status Bugs Code Smells Coverage Lines of Code Maintainability Rating Reliability Rating Security Rating Vulnerabilities

RocketUI

RocketUI turns XML view definitions into ready-to-render JSON responses. It powers dynamic forms and grids by hydrating layouts with values sourced from PHP domain objects and can also export React JSON Schema Form (RJSF) compatible structures.

Features

  • Parse XML layouts (validated with the bundled XSDs) into structured form and grid definitions.
  • Hydrate field values from PHP objects via public properties or getters, including nested dot-notation lookups.
  • Generate RJSF schema, uiSchema, and formData payloads from the native layout JSON.
  • Support UI primitives such as containers, tabs, inputs, selects, status chips, file uploads, toasts, and actions.
  • Provide a small utility layer for conditional rendering, value parsing, and reusable layout components.

Requirements

  • PHP 8.2 or higher (required by PHPUnit 11).
  • The ext-dom and ext-libxml extensions.
  • Composer for dependency management.

Installation

composer require rocket-php/rocket-ui

If you are working within this repository, install the dev dependencies first:

composer install

Defining a Form

Layouts are described in XML and validated against src/Views/Form/XSD/schema.xsd. A minimal example looks like:

<RocketForm xmlns="http://rocket.com/rf-schema">
  <metadata>
    <title>Customer Profile</title>
    <description>Primary contact information</description>
    <version>1.0</version>
  </metadata>
  <layout type="modal">
    <container id="main" label="Details" direction="column">
      <input name="name" type="text" label="Name" required="true" />
      <input name="email" type="email" label="Email" />
      <status name="status" label="Status" />
    </container>
  </layout>
  <actions>
    <button type="primary" name="submit" label="Save" />
  </actions>
</RocketForm>

See tests/data/form.xml and tests/data/grid.xml for more complete samples and schema coverage.

Usage

use RocketPhp\RocketUI\UIEngine;
use RocketPhp\RocketUI\Views\Form\Form;

$form = new Form(__DIR__ . '/form.xml');
$data = new class () {
    public string $name = 'Ada Lovelace';
    public function getEmail(): string { return 'ada@example.com'; }
    public function getStatus(): string { return 'active'; }
};

$engine = new UIEngine();

// Native form layout (metadata, layout blocks, actions)
$jsonLayout = $engine->buildForm($form, $data);

// React JSON Schema Form payloads
$rjsfPayload = $engine->buildRJSFSchema($form, $data);

The buildForm method walks the layout, resolves values (including nested properties like address.street), and returns a JSON string. buildRJSFSchema adapts that response for RJSF consumers, producing the familiar schema, uiSchema, and formData arrays.

Grids follow the same pattern via RocketPhp\RocketUI\Views\Grid\Grid definitions and UIEngine::buildGrid().

Running Tests

Execute the full suite with:

./vendor/bin/phpunit

To continuously run tests while developing, the project ships with spatie/phpunit-watcher:

./vendor/bin/phpunit-watcher watch

The provided tests (tests/formTest.php) also demonstrate real-world usage, including XML validation, value hydration, and RJSF conversion.

Project Structure

  • src/UIEngine.php – entry point for converting form and grid definitions into JSON payloads.
  • src/Views/Form – XML parsing, layout components, actions, and helper services for forms.
  • src/Views/Grid – grid layout parsing and rendering helpers.
  • src/Adapter/RjsfSchemaBuilder.php – converts native form layouts into RJSF structures.
  • tests/ – PHPUnit suites plus fixture XML/JSON data.

License

RocketUI is open-sourced software licensed under the MIT license.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •  

Languages