Lapis Docs

For contributors

Tempest workarounds

Lapis works around Tempest (3.21) behavior in a few places. Each has a test in tests/Feature/TempestWorkaroundsTest.php: when a Tempest update changes the behavior, that is where it fails first. After updating, run the tests, and when a workaround is no longer needed, remove both the code and its test.

Tempest behavior The problem Lapis's solution Where
Request::get() returns an ImmutableArray for arrays after an (array) cast the array is empty or wrong, and settings silently fail to save the JSON body is read directly ($request->body) EditorApi::input()
Database::withinTransaction() swallows the exception and only returns false the error disappears and the caller thinks it worked our own Db::transaction(): BEGIN IMMEDIATE / COMMIT / ROLLBACK, rethrows the exception, and joins the outer transaction when nested Database/Db.php
Every 4xx/5xx response becomes an exception and Tempest's own error page is shown Lapis's 404 template and JSON errors never reach the client PassThroughExceptionRenderer sends responses marked with mark() out unchanged, and QuietExceptionReporter stops logging 4xx Http/PassThroughExceptionRenderer.php, Support/QuietExceptionReporter.php
The variables of a nested :foreach do not reach a component's slot in a loop, the slot of <x-block> does not see $item the :default="$item['title']" attribute on <x-block> Components/x-block.view.php, View/BlockView.php
Variables at the top of a template are not visible in the slot of <x-layout> the setup block's variables disappear inside the layout Lapis runs the <?php … ?> setup block separately and hands its variables to the view as data View/PageTemplate.php
A use function import at the top of a template does not reach a component's slot translate(…) inside <x-block>…</x-block> is an undefined function call it fully qualified in slots: {{ \Tempest\Intl\translate('…') }} tests/Fixtures/plugin/pages/index.php
Compiled views run from the cache folder __DIR__ in a view points to the wrong place the Paths service (Paths::package(), Paths::pages(), …) Paths.php
{{ }} escapes with htmlentities accented letters end up as &eacute; in the HTML (browsers show them correctly) not fixed, the test helpers (assertSeeText) compare decoded text Testing/LapisTestCase.php
Discovery registers every HttpMiddleware as global middleware middleware meant for some pages only (e.g. BasicAuth) would run on every request, and every page would fail for lack of constructor arguments the Lapis\Middleware\* classes have #[SkipDiscovery]. A site's own page middleware needs it too when it implements HttpMiddleware (or use a closure) Middleware/*.php
Discovery loads the classes of non-vendor packages (e.g. a path repository) and does not swallow errors src/Testing/LapisTestCase builds on PHPUnit, so on a live site (without dev dependencies) every request failed the file declares the class only when PHPUnit is available, and CI also boots the fixture site without dev dependencies Testing/LapisTestCase.php, .github/workflows/tests.yml
With ENVIRONMENT=testing Tempest installs no error handler (it leaves it to PHPUnit) under a web server every 4xx stops with a 500, "Uncaught HttpRequestFailed" the generated .env has ENVIRONMENT=local, and phpunit.xml sets testing for Pest runs tests/Fixtures/site/boot.php, Testing/LapisTestCase.php
A component also receives every variable of the calling template (extract($scopedVariables)) a template's $title, $type, $global look like attributes: a page title became a loop variable, and a $type could have changed a block's type components read only from the $attributes array ($attributes['title'] instead of isset($title)). A site's own components need the same Components/*.view.php
The template parser reads a > in an attribute value (e.g. in an fn () => … closure) as the end of the tag "syntax error, unexpected token )" in the compiled view build the closure in the setup block and pass it as a variable (:item-attributes="$attrs") documentation (x-repeat)
The expression of an :if="…" in a component's slot can get lost (it compiles to if():) a compile error use a plain <?php if (…): ?> for conditions in a slot x-repeat examples
PreventCrossSiteRequestsMiddleware requires a Sec-Fetch-Site header on every POST over plain HTTP on non-localhost origins browsers do not send it, so every save is a 403 a secure origin is required (http://localhost or HTTPS) documentation
GenericHttpClient decodes every request body as JSON (and the PSR-18 driver encodes it again) a form-encoded POST (hCaptcha, reCAPTCHA) throws before it is sent postForm() sends through the PSR-18 client itself, the JSON calls stay on Tempest's Assets/TempestHttpFetcher.php
Tempest's migrate:fresh drops every table of the database it would delete Lapis's own content, which lives in the same database the command is removed from the console Kernel\Configuration

To change the session id, Lapis uses Tempest's SessionManager::regenerate() (on sign-in and sign-out). That is not a workaround, but the test covers it too, because the protection against session fixation depends on it.