Documentation menu

Testing and operations

Upgrading

This page explains how Taphra versions change, where the upgrade notes for each release live, and what to change in an app that was built on a pre-release copy of the framework before 1.0.0.

Versions

#

Taphra follows semantic versioning from 1.0.0:

Release What it may contain
Patch (1.0.x) Bug fixes and documentation. No change to public APIs.
Minor (1.x.0) New features, commands and config keys, backward compatible. Deprecations are announced here.
Major (x.0.0) Breaking changes: removed or changed APIs, a higher minimum PHP version, changed conventions. Deprecated APIs are removed here.

Two exceptions to the rule, stated where they apply:

  • Features marked as a preview may change in a minor release. In 1.0 that is the AI builder (ai:build, ai:fix, ai:rollback).
  • A security fix can change behaviour in a patch release when keeping the old behaviour would leave apps exposed. The release notes say so.

Require the framework with a caret constraint ("taphra/taphra": "^1.0", what the skeleton does) to receive minor and patch releases with composer update.

Shell
php taphra --version            # Taphra 1.1.0
composer show taphra/taphra     # the installed version and its dependencies

Upgrade notes

#

Each release that needs more than composer update comes with a note in docs/upgrade/, named <from>-<to>.md (for example 1.0.0-1.1.0.md). A note starts with front matter that says whether the release breaks anything and which PHP version it needs:

YAML
version: "1.1.0"
released: "2027-01-15"
breaking: false
php_min: "8.2"

and then has sections for breaking changes (each with before, after and what to do), new features, deprecations and dependency changes. docs/upgrade/TEMPLATE.md is the template. The changelog lists every release.

The notes so far:

  • 1.0.0 to 1.0.1: execute() counts the rows it changed, and DatabaseConnection::load() returns the DataStores' connection.
  • 1.0.1 to 1.0.2: elements print a view variable once, save($data) runs the save hooks on the array, a cancelled save returns false, and new apps lock their dependencies for PHP 8.2.
  • 1.0.2 to 1.1.0: packages ship routes, controllers and migrations; foreign keys in create(), SQLite included; seeOther() and header() for HTML controllers; readable field names in validation messages; raw bodies in tests; the PSR-15 entry boots the service providers.

To upgrade:

  1. Read the notes between your version and the target, and the changelog entries.
  2. Run composer update taphra/taphra (or edit the constraint for a new major version).
  3. Run your tests, then follow the deploy steps in Deployment, which include php taphra cache:clear and php taphra optimize.

upgrade:check and upgrade:prep belong to taphra/dev, the development tooling of the framework repository: maintainers use them to write the notes. They read the repository's own docs/upgrade/ folder, so they do not work inside an app.

From a pre-release copy to 1.0.0

#

Apps written against a copy of the framework from before the 1.0.0 release need the changes below. Most come from security defaults that are now on. Work through the list, then run your test suite with APP_ENV=dev and once more with production settings.

Environment and URLs

#
  • An unset or unknown APP_ENV means production. Set APP_ENV=dev on development machines and in CI jobs that expect development behaviour; php taphra serve sets it for its own server. The debug error page (Whoops) is only used in development. The command line follows the same rule, so php taphra migrate without APP_ENV uses the prod: database settings.
  • url() needs app.base_url in production. It used to fall back to the request's Host header, which a client controls. Add base_url: https://your-domain to the prod: section of app/Config/app.yml; without it url() throws Taphra\Exceptions\ConfigurationException.
  • Forwarded headers are trusted only from app.trusted_proxies. Request::clientIP() and the HTTPS check ignore X-Forwarded-For and X-Forwarded-Proto unless the connection comes from a listed proxy. Behind a load balancer, list its addresses: trusted_proxies: [10.0.0.0/8].

Controllers and routes

#
  • Only methods your controllers declare are URL actions. The helpers and hooks of Taphra\Controller, Taphra\RestController and Taphra\TaphraObject (redirect(), csrf(), json(), render(), sse(), the htmx*() helpers, beforeAction() and the others) can no longer be reached by a URL, and neither can an app method with one of those names, a method whose name starts with _, or a method with an MCP attribute. If one of your actions has a name the base classes use, rename it and its route. php taphra route:list shows your routes.
  • sse() is protected and takes a Generator or a Closure: call $this->sse($generator) from your own action.
  • A declared route answers 405 to the wrong method, with an Allow header. A route bound to POST no longer runs for GET.
  • Route group middleware runs on both entries, the classic index.php front controller and the PSR-15 pipeline, and the /controller/action URL of an action that a group guards answers 404, so it cannot skip the middleware.
  • The launch and utils commands are gone. Use the make:* generators and your own commands in app/Console/ (see Command line).

CSRF

#

CSRF protection is on in the skeleton's AppController (protected $autoVerifyCsrf = true) and checks every request that is not GET, HEAD or OPTIONS, custom methods included. A request without a valid token gets 403. Add the token to each form:

PHP
<!-- app/Views/posts/edit.tpl.php -->
<form method="post" action="/posts/<?= e($post['id']) ?>/update">
    <?= $this->csrf() ?>
    <!-- fields -->
</form>

For fetch() or HTMX requests, send the token in an X-CSRF-Token header. Controllers that extend RestController directly (JSON APIs that authenticate with tokens) do not check it. See Security.

Sessions, logging and worker mode

#
  • Session cookies are HttpOnly, SameSite=Lax and Secure on HTTPS, and sessions use strict mode (an ID the server never issued is refused). Override the cookie settings under app.session.cookie only if you need to.
  • New names for the logging helpers, session keys and remember-me cookie. The global helpers are tphr_log(), tphr_dbg(), tphr_warning(), tphr_notice() and tphr_err(); rename your calls (the old names still work as deprecated wrappers and are removed in 2.0). The framework's session keys are _tphr_errors, _tphr_old and _tphr_user, and the remember-me cookie is _tphr_remember. Users who were signed in before the upgrade sign in again once.
  • Production logs notices and above. Set app.logging.level (debug, message, notice, warning, error) to change it. logging.method: null discards every log line.
  • Worker mode resets per-request state. frankenphp-worker.php calls Taphra\RequestState::reset() before each request. If you wrote your own worker script, call it too. See Deployment.
  • The request log is app/tmp/Log/requests.log.

Database

#
  • Values are always bound as parameters, and identifiers and operators are checked. Condition keys, orderBy(), groupBy() and JSON paths accept column names only, operators come from a fixed list, and LIMIT and OFFSET are integers. Raw SQL is limited to string conditions and the *Raw() methods (whereRaw(), selectRaw(), orderByRaw(), with ? bindings for values): write those in code, never from request data.
  • $fillable and $guarded are respected. They filter fill() and create(), and, when the DataStore declares either, the data passed to save(), insert(), update() and upsert(). Fields a form sends that are not fillable are dropped; set them from trusted code.
  • findOrFail() throws Taphra\Db\RecordNotFoundException, which the framework answers with 404. Update catch blocks that caught the old exception.

The details are in DataStores and SqlQuery.

Views, email and validation

#
  • HTML helpers escape attribute values, option labels and anchor text. Pass new Taphra\SafeString($html) where you meant to insert markup.
  • e() does not escape a view variable a second time. Top-level strings are escaped once before the view runs; e() and the HTML helpers leave such a value as it is, so <?= e($title) ?> no longer prints &amp;amp;.
  • Email bodies set with html() or text() are never run as PHP. Replace <?= $name ?> in those bodies with {{ name }} placeholders and pass the values; in HTML bodies they are escaped (a SafeString value is inserted as is). Nested values use dots: {{ user.name }}. Template files in app/Views/Emails/ are unchanged.
PHP
use Taphra\Email;

(new Email())
    ->to('[email protected]')
    ->subject('Welcome')
    ->html('<p>Hello {{ name }}, your plan is {{ plan }}.</p>', ['name' => $user['name'], 'plan' => $plan])
    ->send();
  • The validator is stricter. An unknown rule name throws InvalidArgumentException (register custom rules with Validator::extend()). min and max on a string measure its length; add integer or numeric to compare the value as a number. url accepts http, https and ftp URLs only.
PHP
use Taphra\Validator;

$v = Validator::make(
    ['name' => 'Al', 'age' => '25', 'site' => 'javascript:alert(1)'],
    ['name' => 'required|min:3', 'age' => 'integer|min:18', 'site' => 'url']
);
print_r(array_keys($v->errors()));      // name (too short) and site (not http, https or ftp)

try {
    Validator::make(['email' => '[email protected]'], ['email' => 'requird|email'])->fails();
} catch (InvalidArgumentException $e) {
    echo $e->getMessage(), "\n";        // Unknown validation rule 'requird' on field 'email'. ...
}

Secrets and tokens

#
  • Crypt::encrypt() and Crypt::decrypt() need a key of at least 32 bytes, such as the 64-character hex APP_SECRET_KEY that php taphra key:generate writes. A shorter key throws. For a passphrase a person types, use Crypt::encryptWithPassphrase() and Crypt::decryptWithPassphrase(). decrypt() still reads values encrypted by earlier versions, so you can re-encrypt stored data under the new key: Crypt::encrypt(Crypt::decrypt($stored, $oldKey), $newKey).
  • JWT secrets must be at least 32 bytes. Taphra\Auth\Jwt and the JWT middleware throw on a shorter secret. Generate one with bin2hex(random_bytes(32)).
PHP
use Taphra\Auth\Jwt;
use Taphra\Crypt;

$key    = bin2hex(random_bytes(32));                // 64 hex characters, like APP_SECRET_KEY
$stored = Crypt::encrypt('card ending 4242', $key);
echo Crypt::decrypt($stored, $key), "\n";           // card ending 4242

$secret = bin2hex(random_bytes(32));
$token  = Jwt::encode(['sub' => 42], $secret, 900);
echo Jwt::decode($token, $secret)['sub'], "\n";     // 42

foreach ([fn() => Crypt::encrypt('x', 'old-short-key'), fn() => Jwt::encode(['sub' => 42], 'secret')] as $tooShort) {
    try {
        $tooShort();
    } catch (InvalidArgumentException $e) {
        echo "refused: ", $e->getMessage(), "\n";
    }
}
  • TOTP verification fails closed. When the cache that records used codes cannot be read or written, Auth::verifyTotp() returns false instead of accepting a code it cannot check for replay. Make sure the cache backend is reachable where you verify codes.

Queues

#
  • Queue workers run only job classes that implement Taphra\Queue\JobInterface, calling a public static method of the class (plus the framework's own Email::processQueue). Payloads that name a plain function or another class are refused, so whoever can write to the queue cannot make a worker call arbitrary code. Add implements JobInterface to your job classes and make their entry points public static methods. See Queues.

AI providers

#
  • Structured answers are checked against the whole schema. Before 1.0 only the top-level required fields were checked; now nested objects, types and enums must match too. An answer that is declined, cut short, not JSON or off-schema throws Taphra\Ai\AiStructuredOutputException, whose response() and usage() still give you the provider's answer and token usage, so the call can be counted and logged.
  • Anthropic uses output_format for structured output on models from 4.1 on, and no longer sends the tools-2024-04-04 beta header. To keep the forced-tool way, set structured_output: tool for the provider in ai.yml.
  • OpenAI reasoning models use the Responses API. Set api: chat for the provider to keep Chat Completions.
  • HTTP calls go through a transport. Providers call Taphra\Ai\Http\CurlTransport; code that overrode a provider's cURL calls should pass its own transport with withTransport() instead (tests can use FakeTransport).