Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ This path is designed for developers who want both a fast start and a clearer un

The current Quantum 3.x baseline requires:

- PHP 8.1 or newer
- PHP 8.2 or newer
- Composer
- PHP extensions: `pdo`, `curl`, `json`, `simplexml`, `fileinfo`, `openssl`, `bcmath`

Expand Down
2 changes: 1 addition & 1 deletion v3.0/cli/code-generation.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ Quantum also includes:
php qt install:debugbar
```

This publishes the DebugBar resource files into the public assets directory so the toolbar can render correctly in a project that uses it.
This publishes the DebugBar resource files into the public assets directory so the toolbar can render correctly in a project that uses it. See [`install:debugbar`](../packages/console/built-in-commands.md#installdebugbar) for what it copies and when to run it again.

## What generation usually does not mean here

Expand Down
5 changes: 3 additions & 2 deletions v3.0/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ This guide walks you through installing and running a new Quantum PHP project.

Make sure your environment includes:

* **PHP 8.1+**;
* **PHP 8.2+**;
* **PHP extensions**:
* PDO
* curl
Expand All @@ -15,11 +15,12 @@ Make sure your environment includes:
* fileinfo
* OpenSSL
* bcmath
* gd
* **Composer** installed and accessible globally

Optional framework features may require additional extensions or packages such as `redis`, `memcached`, `zip`, `dom`, or `twig/twig`.

Practical note: run `php -v` to check your PHP version before you start. Quantum needs PHP 8.1 or newer.
Practical note: run `php -v` to check your PHP version before you start. Quantum needs PHP 8.2 or newer.

### Installation Steps

Expand Down
2 changes: 1 addition & 1 deletion v3.0/packages/cache/adapters.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,5 +154,5 @@ All built-in adapters share these contracts:

- stored keys are namespaced through `sha1($prefix . $key)`
- `get()` returns the provided default when the key is missing, expired, or contains invalid serialized data
- `getMultiple()`, `setMultiple()`, and `deleteMultiple()` require arrays and throw `InvalidArgumentException` for other iterables
- `getMultiple()`, `setMultiple()`, and `deleteMultiple()` accept any iterable and reject keys that are not strings or integers (see the [batch contract](contracts.md#batch-contract))
- `DateInterval` TTL values are converted to seconds at call time
32 changes: 18 additions & 14 deletions v3.0/packages/cache/contracts.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,23 @@ Resolution rules:

`cache()` returns `Quantum\Cache\Cache`, which forwards calls to the active adapter.

Supported public methods are the PSR-16 style methods implemented by the adapters:
Supported public methods are the PSR-16 methods implemented by the adapters, with the types of `psr/simple-cache` 3:

- `get($key, $default = null)`
- `getMultiple($keys, $default = null)`
- `has($key)`
- `set($key, $value, $ttl = null)`
- `setMultiple($values, $ttl = null)`
- `delete($key)`
- `deleteMultiple($keys)`
- `clear()`
- `get(string $key, mixed $default = null): mixed`
- `getMultiple(iterable $keys, mixed $default = null): iterable`
- `has(string $key): bool`
- `set(string $key, mixed $value, null|int|DateInterval $ttl = null): bool`
- `setMultiple(iterable $values, null|int|DateInterval $ttl = null): bool`
- `delete(string $key): bool`
- `deleteMultiple(iterable $keys): bool`
- `clear(): bool`

Calling a method the adapter does not implement throws `CacheException::methodNotSupported(...)`.

## Key contract

A key is a string. Pass a number as text, `cache()->get('42')`: `cache()->get(42)` throws a `TypeError`, because the methods that take one key declare `string $key`.

All built-in adapters transform the runtime key with:

```text
Expand Down Expand Up @@ -69,13 +71,15 @@ For file and database storage, expiry is checked lazily on read or presence chec

## Batch contract

Batch methods are stricter than the PSR interface suggests.
`getMultiple()`, `setMultiple()` and `deleteMultiple()` accept any iterable: an array, a generator or an iterator. A value that is not iterable throws a `TypeError`.

```php
cache()->setMultiple(['user.1' => $first, 'user.2' => $second], 300);

- `getMultiple()` requires an array of keys
- `setMultiple()` requires an array of `key => value` pairs
- `deleteMultiple()` requires an array of keys
$users = cache()->getMultiple(['user.1', 'user.2']);
```

Passing another iterable type throws `InvalidArgumentException`.
PHP turns a numeric string array key into an integer, so in `setMultiple(['42' => $value])` the key arrives as `42`. The batch methods turn integer keys back into strings, so numeric keys work as expected. Any other key that is not a string, such as `true`, `null` or an object, throws `Quantum\Cache\Exceptions\InvalidCacheKeyException`, which implements `Psr\SimpleCache\InvalidArgumentException`. The message names the type, for example `The cache key must be a string, bool given`.

## Data contract

Expand Down
13 changes: 12 additions & 1 deletion v3.0/packages/console/built-in-commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,18 @@ Contract:

### `install:debugbar`

Publishes DebugBar assets into `public/assets/DebugBar/Resources`.
Publishes the browser files of `php-debugbar/php-debugbar` into `public/assets/DebugBar/Resources`, so the debug toolbar can load its styles and scripts. Run it once in a new project, and again after an upgrade that brings a new major version of the package.

```bash
php qt install:debugbar
```

Contract:

- the files come from the package's `resources` folder, and the toolbar loads the bundled `dist/debugbar.min.css` and `dist/debugbar.min.js`
- the command counts as already installed only when both bundled files exist; otherwise it copies again, over files an older version published, and keeps files the application added there, such as `custom_debugbar.css`
- it creates `public/assets/DebugBar/Resources` when the folder is missing
- it stops with a `FileSystemException` when the package folder cannot be found or a file cannot be copied, instead of reporting success

### `install:openapi <module>`

Expand Down
6 changes: 6 additions & 0 deletions v3.0/packages/jwt/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ A new `JwtToken` instance:

If the environment layer is unavailable or `APP_KEY` cannot be resolved, construction fails through the Environment package.

The key must be at least as long as the algorithm's hash: 32 bytes for `HS256`, 48 for `HS384` and 64 for `HS512`. A shorter key fails when a token is composed or read, with `Provided key is too short` from `firebase/php-jwt`. An `APP_KEY` generated with `php qt core:key` and its default length is 64 characters long, which is enough for all three:

```bash
php qt core:key
```

## What counts as payload

`compose()` only works after you add at least one payload entry.
Expand Down
113 changes: 112 additions & 1 deletion v3.0/upgrade-guide.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,117 @@
# Upgrade Guide

This guide summarizes the changes to make when you upgrade a Quantum project. It has two parts: [3.0 to 3.1](#upgrading-from-30-to-31) and [2.x to 3.0](#upgrading-from-2x-to-30).
This guide summarizes the changes to make when you upgrade a Quantum project. It has three parts: [3.1 to 3.2](#upgrading-from-31-to-32), [3.0 to 3.1](#upgrading-from-30-to-31) and [2.x to 3.0](#upgrading-from-2x-to-30).

## Upgrading from 3.1 to 3.2

3.2 raises the PHP minimum to 8.2 and moves the dependencies to their newest versions that run on it. Most applications only update `composer.json`; the sections below say where code or setup needs a change.

### 1. Platform and dependencies

**PHP 8.2 or newer.** An application on PHP 8.1 stays on 3.1.x. Check `php -v`, the `php` constraint in your `composer.json` (`^8.2`) and the PHP versions your CI runs.

**The `gd` extension.** `gumlet/php-image-resize` 3, which `UploadedFile::modify()` uses, requires `ext-gd`, so Composer refuses to install the framework without it. `UploadedFile::modify()` itself works as before.

**Your `composer.json`.** Require the framework with `"quantum/framework": "^3.2.0"`. A project created from the starter project also requires `symfony/process` and `symfony/yaml`: raise both to `^7.4`, because the framework's `symfony/console` 7.4 refuses `symfony/process` below 6.4 and Composer reports a conflict.

```json
"require": {
"php": "^8.2",
"quantum/framework": "^3.2.0",
"symfony/process": "^7.4",
"symfony/yaml": "^7.4"
}
```

**Newer majors.** The framework requires `psr/log` 3, `firebase/php-jwt` 7 and the Symfony 7.4 line of `symfony/console`, `symfony/var-dumper` and `symfony/var-exporter`. If your `composer.json` pins one of them to an older major, for example `psr/log` `^2.0`, allow the newer one. Commands that extend `Quantum\Console\CliCommand` already have the signatures Symfony 7 expects.

**No action needed:** `Pipeline`, `MatchedRoute` and `RouteFinder` are `readonly` classes now; they are `final`, so nothing extends them.

### 2. The JWT key must be long enough

`firebase/php-jwt` 7 rejects a signing key that is shorter than the algorithm's hash: 32 bytes for `HS256`, the default of `Quantum\Jwt\JwtToken`. The JWT authentication signs with `APP_KEY`, so with a shorter key every sign-in fails with `Provided key is too short`.

Check the length of your `APP_KEY`. If it has fewer than 32 characters, generate a new one:

```bash
php qt core:key
```

The command asks before it replaces an existing key. Tokens issued with the old key no longer verify, so API clients must sign in again. See the [JWT overview](packages/jwt/overview.md) for the lengths of the other algorithms.

### 3. Cache keys are typed

The cache adapters implement `psr/simple-cache` 3 and declare its types, for example `get(string $key, mixed $default = null): mixed`.

- A key passed to `get()`, `set()`, `has()` or `delete()` must be a string: `cache()->get(42)` throws a `TypeError`, so write `cache()->get('42')`.
- `getMultiple()`, `setMultiple()` and `deleteMultiple()` accept any iterable, not only an array. They still accept numeric keys, and throw `Quantum\Cache\Exceptions\InvalidCacheKeyException` for a key that is neither a string nor an integer.
- A cache adapter of your own that implements `Psr\SimpleCache\CacheInterface`, or a class that extends one of the built-in adapters and overrides these methods, must declare the same types.

See the [cache contracts](packages/cache/contracts.md#key-contract) for the details.

### 4. Register console commands with `addCommand()`

Symfony 7.4 deprecates `Application::add()`, and the framework registers its commands with `Application::addCommand()`. Commands you register through the framework need no change. Code of your own that calls `add()` on the Symfony application logs a deprecation; switch it to `addCommand()`:

```php
// before: $application->add($command);
$application->addCommand($command);
```

### 5. Publish the debug toolbar files again

`php-debugbar/php-debugbar` 3 moved its browser files, and the toolbar loads the bundled `dist/debugbar.min.css` and `dist/debugbar.min.js`. A project that published the 2.x files shows the toolbar without its styles and scripts until you run:

```bash
php qt install:debugbar
```

The command copies the new files over the old ones and keeps your own files, such as `custom_debugbar.css`. See [`install:debugbar`](packages/console/built-in-commands.md#installdebugbar).

### 6. OpenAPI generation

`zircote/swagger-php` 7 removed the static `OpenApi\Generator::scan()`. `php qt install:openapi` needs no change, and the generated `spec.json` is the same. Code of your own that builds a spec calls the generator instead:

```php
use OpenApi\Generator;

$openApi = (new Generator())->generate([$path]);
```

### 7. Tests in a project created from the starter project

The starter project's tests run on PHPUnit 11.5. If your project keeps them, require `"phpunit/phpunit": "^11.5"` and `"mockery/mockery": "^1.6"` in `require-dev`, then:

- remove the `verbose="true"` attribute from `phpunit.xml`; PHPUnit 11 no longer knows it and reports the file as a deprecated configuration
- add a `<source>` section to `phpunit.xml` if you collect code coverage (`composer test` does); without it PHPUnit 11 does not process coverage and fails the run:

```xml
<source>
<include>
<directory suffix=".php">./shared</directory>
</include>
</source>
```

- replace `@dataProvider` doc comments with the `#[DataProvider('...')]` attribute (`use PHPUnit\Framework\Attributes\DataProvider;`); PHPUnit 12 no longer reads doc comments.

### 8. Check the upgrade

Update the dependencies and run the checks you already use:

```bash
composer update
vendor/bin/phpunit
composer phpstan
```

Then look for the names this part replaced. Each hit is a section above:

```bash
grep -rnF -e 'Generator::scan(' -e '@dataProvider' -e 'verbose=' shared modules helpers tests phpunit.xml
```

Finally, open a page with `app.debug` on to check the toolbar, sign in once if you use JWT, and run one `php qt` command.

## Upgrading from 3.0 to 3.1

Expand Down