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.
php taphra --version # Taphra 1.1.0
composer show taphra/taphra # the installed version and its dependenciesUpgrade 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:
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, andDatabaseConnection::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 returnsfalse, 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()andheader()for HTML controllers; readable field names in validation messages; raw bodies in tests; the PSR-15 entry boots the service providers.
To upgrade:
- Read the notes between your version and the target, and the changelog entries.
- Run
composer update taphra/taphra(or edit the constraint for a new major version). - Run your tests, then follow the deploy steps in Deployment, which include
php taphra cache:clearandphp 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_ENVmeans production. SetAPP_ENV=devon development machines and in CI jobs that expect development behaviour;php taphra servesets it for its own server. The debug error page (Whoops) is only used in development. The command line follows the same rule, sophp taphra migratewithoutAPP_ENVuses theprod:database settings. url()needsapp.base_urlin production. It used to fall back to the request'sHostheader, which a client controls. Addbase_url: https://your-domainto theprod:section ofapp/Config/app.yml; without iturl()throwsTaphra\Exceptions\ConfigurationException.- Forwarded headers are trusted only from
app.trusted_proxies.Request::clientIP()and the HTTPS check ignoreX-Forwarded-ForandX-Forwarded-Protounless 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\RestControllerandTaphra\TaphraObject(redirect(),csrf(),json(),render(),sse(), thehtmx*()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:listshows 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
Allowheader. A route bound toPOSTno longer runs forGET. - Route group middleware runs on both entries, the classic
index.phpfront controller and the PSR-15 pipeline, and the/controller/actionURL of an action that a group guards answers 404, so it cannot skip the middleware. - The
launchandutilscommands are gone. Use themake:*generators and your own commands inapp/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:
<!-- 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=LaxandSecureon HTTPS, and sessions use strict mode (an ID the server never issued is refused). Override the cookie settings underapp.session.cookieonly 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()andtphr_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_oldand_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: nulldiscards every log line. - Worker mode resets per-request state.
frankenphp-worker.phpcallsTaphra\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. $fillableand$guardedare respected. They filterfill()andcreate(), and, when the DataStore declares either, the data passed tosave(),insert(),update()andupsert(). Fields a form sends that are not fillable are dropped; set them from trusted code.findOrFail()throwsTaphra\Db\RecordNotFoundException, which the framework answers with 404. Updatecatchblocks 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;.- Email bodies set with
html()ortext()are never run as PHP. Replace<?= $name ?>in those bodies with{{ name }}placeholders and pass the values; in HTML bodies they are escaped (aSafeStringvalue is inserted as is). Nested values use dots:{{ user.name }}. Template files inapp/Views/Emails/are unchanged.
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 withValidator::extend()).minandmaxon a string measure its length; addintegerornumericto compare the value as a number.urlacceptshttp,httpsandftpURLs only.
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()andCrypt::decrypt()need a key of at least 32 bytes, such as the 64-character hexAPP_SECRET_KEYthatphp taphra key:generatewrites. A shorter key throws. For a passphrase a person types, useCrypt::encryptWithPassphrase()andCrypt::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\Jwtand the JWT middleware throw on a shorter secret. Generate one withbin2hex(random_bytes(32)).
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 ownEmail::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. Addimplements JobInterfaceto 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, whoseresponse()andusage()still give you the provider's answer and token usage, so the call can be counted and logged. - Anthropic uses
output_formatfor structured output on models from 4.1 on, and no longer sends thetools-2024-04-04beta header. To keep the forced-tool way, setstructured_output: toolfor the provider inai.yml. - OpenAI reasoning models use the Responses API. Set
api: chatfor 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 withwithTransport()instead (tests can useFakeTransport).