# Guided equipment-loan request

Complete example for “Building a guided multi-step process” (ExecKernel documentation, 10.02). The UI supports English and Spanish.

## Run in an existing PHP project

The project must already load ExecKernel core and its PHP SDK through `vendor/autoload.php`. See the documentation’s Installation and requirements page. Extract this folder beside `vendor/`, then run from the project root:

```sh
php -S 127.0.0.1:8080 -t guided-loan/public
```

Open http://127.0.0.1:8080/?lang=en or http://127.0.0.1:8080/?lang=es. PHP must be able to create and write `guided-loan/var/`. Serve only `public/`; graph definitions, business records and engine sessions stay outside the document root.

## Try it

1. Enter a sample name and 2 days.
2. Select Laptop or Projector, reload the review page, then submit.
3. Reload the result: the same request reference and outcome remain.
4. Start a new request for 5 days. Projector is disabled; Laptop remains available.
5. Choose Laptop and cancel on review.

The server validates the form, constructs trusted context, loads choices from the SDK and confirms transitions. A deliberately crafted POST for blocked edge 102 is rejected and redisplays the current step. The controller does not accept a session ID or context object from the browser.

## Files and state

- `graphs/equipment-loan.json`: nodes, edges, condition, English/Spanish text and terminal content.
- `bootstrap.php`: Composer autoloading, local SDK and filesystem session store.
- `src/LoanApplication.php`: validates input, coordinates the SDK and projects accepted state to a business record.
- `public/index.php`: forms, CSRF check, browser ownership, redirects, rejection recovery and HTML.
- `public/style.css`: presentation.
- `var/engine/`: engine session files.
- `var/requests/`: separate JSON business records with applicant, duration, equipment and outcome.
- `var/http/`: PHP browser sessions, holding the current request ID and CSRF token.

No generated records are distributed. “New request” changes the browser’s current reference; it does not delete old records. Reloading recovers progress while both the browser session and engine state remain valid. There is no account login or cross-device recovery.

## Application boundary

The duration rule (projector up to 3 days) is an example policy. Submitting records a request; it does not reserve stock, authorize an applicant or arrange a handover. Adapt those responsibilities in your application.

The PHP session lock serializes requests from this browser. The filesystem engine store does not add conditional writes, and the engine state and business JSON file do not share a transaction. The application projects the accepted state again when reopening a request, so a failed business-file write after a successful transition can be retried by reloading. This is not a general transaction or exactly-once effect mechanism. A failure during initial creation can leave an engine session without an associated request.

For a service shared across devices or workers, use the persistence/concurrency and application authorization patterns described in the documentation. Do not retry unknown navigation failures automatically.
