Skip to content
Open
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
510 changes: 510 additions & 0 deletions AUDIT.md

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Dotkernel Light Documentation

This repository holds the documentation of [Dotkernel Light](https://github.com/dotkernel/light), the smallest complete Mezzio application.

The documentation is published at https://docs.dotkernel.org/light-documentation/.
1 change: 0 additions & 1 deletion docs/book/index.md

This file was deleted.

1 change: 1 addition & 0 deletions docs/book/index.md
4 changes: 2 additions & 2 deletions docs/book/v1/how-tos/create-pages.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ How to register a new route, wire it into the navigation, and create the Twig te

## Register the page route

Open `config/autoload/local.php` and locate the **routes** key.
Open `src/Page/src/ConfigProvider.php` and locate the `getRoutes()` method.
Under the **page** key you will find an associative array with a couple of already existing routes.
You create a new route by appending a new line to that array:

Expand Down Expand Up @@ -92,7 +92,7 @@ The url for the new page in this example is `/page/example-page`.
## FAQ

**Q: Where do I register a new page's route?**
A: In `config/autoload/local.php`, under the `routes` -> `page` key.
A: In `src/Page/src/ConfigProvider.php`, in the `getRoutes()` method, under the `page` key.

**Q: Does the route key have to match the template filename?**
A: No — the array key is the page slug used in the URL, the array value is the template name; they can differ.
Expand Down
25 changes: 17 additions & 8 deletions docs/book/v1/how-tos/routing.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,26 @@ In our current implementation we are using request handlers instead of controlle
### Declaration of the routes and modules

Currently, our structure uses modules, routes and template names.
Those are being declared in the file `config/autoload/local.php` in the following way:
Those are declared in `src/Page/src/ConfigProvider.php`, in the `getRoutes()` method:

```php
'routes' => [
'page' => [
'about' => 'about',
'who-we-are' => 'who-we-are',
],
],
public function getRoutes(): array
{
return [
'page' => [
'about' => 'about',
'who-we-are' => 'who-we-are',
],
];
}
```

The `ConfigProvider` returns this array under the `routes` configuration key.
You can also add routes under the `routes` key of `config/autoload/local.php`.
The configuration aggregator merges both arrays.

> Before release 1.6.0, the page routes were declared only in `config/autoload/local.php`.

In this case `page` represents the module and `'about' => 'about'` represents the page slug and its assigned `.twig` template.
To clarify, this creates a route called `page::about` in the `page` module, it loads the template file `src/Page/templates/page/about.html.twig` and can be accessed at `/page/about`.
The separator between the prefix and the template name is a double colon, so `url('page::about')` resolves, while `url('page.about')` throws.
Expand Down Expand Up @@ -56,7 +65,7 @@ Each module registers its routes in a `RoutesDelegator.php` file, and the two mo
## FAQ

**Q: Where are page routes declared?**
A: In `config/autoload/local.php`, under the `routes` key.
A: In `src/Page/src/ConfigProvider.php`, in the `getRoutes()` method. The `routes` key in `config/autoload/local.php` can add more routes.

**Q: What separates the route prefix from the template name in a route name?**
A: A double colon — `url('page::about')` resolves, while `url('page.about')` throws.
Expand Down
2 changes: 2 additions & 0 deletions docs/book/v1/installation/running-the-application.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ sudo chmod -R 775 data log

You should see the `Dotkernel Light` welcome page.

`composer install` and `composer update` clear the configuration cache automatically, since release 1.6.0.

> If you are getting exceptions or errors regarding some missing services, try running the following command:

```shell
Expand Down
4 changes: 2 additions & 2 deletions docs/book/v1/introduction/file-structure.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ These files sit at the root of the repository:
This folder contents are

* `clear-config-cache.php` - Removes the config cache file `data/cache/config-cache.php`; also available as `composer clear-config-cache`
* `composer-post-install-script.php` - Runs automatically on Composer's `post-update-cmd` hook, and copies the distributed local configuration template in `config/autoload/` into place unless that file already exists
* `composer-post-install-script.php` - Runs automatically on Composer's `post-update-cmd` hook, and copies the distributed local configuration template in `config/autoload/` into place unless that file already exists. After it, the same hook and the `post-install-cmd` hook clear the configuration cache

## `config` folder

Expand All @@ -61,7 +61,7 @@ This folder contains all service-related local and global config files:
* `dependencies.global.php` - Config file to set global dependencies that should be accessible by all modules
* `development.local.php.dist` - Gets symlinked as `development.local.php` when enabling development mode; activates error handlers
* `error-handling.global.php` - Configures and activates error logs
* `local.php.dist` - Local config file where you can overwrite application name and URL
* `local.php.dist` - Local config file where you set the application URL
* `mezzio.global.php` - Mezzio core config file
* `templates.global.php` - mezzio/mezzio-twigrenderer config file

Expand Down
7 changes: 5 additions & 2 deletions docs/book/v1/introduction/packages.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,24 @@

## Summary

The six direct Composer dependencies Dotkernel Light installs, and what each one does.
The nine direct Composer dependencies Dotkernel Light installs, and what each one does.

## Details

* `dotkernel/dot-errorhandler` - Logging Error Handler for Middleware Applications
* `dotkernel/dot-log` - PSR-3 logger that writes the error log
* `laminas/laminas-component-installer` - Composer plugin for injecting modules and configuration providers into application configuration
* `laminas/laminas-config-aggregator` - Lightweight library for collecting and merging configuration from different sources
* `laminas/laminas-diactoros` - PSR-7 HTTP message and PSR-17 HTTP factory implementation
* `laminas/laminas-servicemanager` - PSR-11 dependency injection container
* `mezzio/mezzio` - PSR-15 Middleware Microframework
* `mezzio/mezzio-fastroute` - FastRoute integration for Mezzio
* `mezzio/mezzio-twigrenderer` - Twig integration for Mezzio

## FAQ

**Q: How many direct dependencies does Dotkernel Light have?**
A: Six, listed above — the same six declared under `require` in `composer.json`.
A: Nine, listed above — the same nine declared under `require` in `composer.json`.

**Q: Which package handles routing?**
A: `mezzio/mezzio-fastroute`, FastRoute's integration for Mezzio.
Expand Down
9 changes: 7 additions & 2 deletions docs/book/v1/introduction/request-lifecycle.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,15 @@ FastRoute matches the URL and method against registered routes.
### 6. Handler Invocation

Extract the matched route name from the request and pass it to the renderer.
If no route matched, the handler throws a `RuntimeException`.

```php
$template = $request->getAttribute(RouteResult::class)->getMatchedRouteName();
// $template = 'page::about';
$routeResult = $request->getAttribute(RouteResult::class);
$routeName = $routeResult instanceof RouteResult ? $routeResult->getMatchedRouteName() : false;
if ($routeName === false || $routeName === '') {
throw new RuntimeException('The page handler needs a matched route. Route the request before dispatch.');
}
// $routeName = 'page::about';
```

### 7. Custom Logic Execution in Handler
Expand Down
9 changes: 5 additions & 4 deletions docs/book/v1/introduction/server-requirements.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@ For production, we highly recommend a *nix based system.

You need to convert the provided Apache related `.htaccess` file into Nginx configuration instructions.

## PHP: 8.3, 8.4 or 8.5
## PHP: 8.3, 8.4, 8.5 or 8.6

Both mod_php and FCGI (FPM) are supported.

> These are the versions declared by `composer.json` in Dotkernel Light 1.5.0.
> PHP 8.5 was added in release 1.4.0 and PHP 8.2 was dropped in release 1.5.0, so stay on 1.4.x if you are pinned to PHP 8.2.
> These are the versions declared by `composer.json` in Dotkernel Light 1.6.0.
> PHP 8.5 was added in release 1.4.0, PHP 8.2 was dropped in release 1.5.0 and PHP 8.6 was added in release 1.6.0.
> Stay on 1.4.x if you are pinned to PHP 8.2.

## Required Settings and Modules & Extensions

Expand All @@ -46,7 +47,7 @@ Both mod_php and FCGI (FPM) are supported.
## FAQ

**Q: Which PHP versions does Dotkernel Light support?**
A: PHP 8.3, 8.4 or 8.5, as declared by `composer.json`.
A: PHP 8.3, 8.4, 8.5 or 8.6, as declared by `composer.json`.

**Q: Is Nginx supported out of the box?**
A: No — the repository ships an Apache `.htaccess` file, which must be converted into Nginx configuration instructions manually.
106 changes: 106 additions & 0 deletions docs/book/v1/upgrading/UPGRADE-1.6.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
# Upgrading from 1.5 to 1.6

## Summary

The changes made to the Dotkernel Light skeleton between releases 1.5.0 and 1.6.0, split into updates that affect a project created from the skeleton and updates you can safely skip.

## Details

Release 1.6.0 is published from the `1.0` branch of [dotkernel/light](https://github.com/dotkernel/light).
Apply the changes to your own project by comparing it with the skeleton at tag `1.6.0`.

The table lists each change that can affect a project, what you notice, and what to do.

| Change | Symptom | Fix |
| --- | --- | --- |
| PHP 8.6 support added | None | None |
| `dotkernel/dot-log`, `laminas/laminas-diactoros` and `laminas/laminas-servicemanager` are direct requirements | None, Composer installed them before | Copy the three lines into your `composer.json` |
| The `dotkernel/dot-errorhandler` range is `^5.1.0 \|\| ^6.0.0`, and `composer update` selects 6 | `InvalidArgumentException` from `LogErrorHandlerFactory`, only with your own error handler code or config | Follow the `dot-errorhandler` v6 upgrade guide, or require `^5.1` |
| The page routes moved to `Light\Page\ConfigProvider` | A route that you removed from `local.php` comes back | Remove it from `getRoutes()` in your copy |
| Composer clears the configuration cache after install and update | None | Copy the two scripts into your `composer.json` |
| `ServerProvider` masks session and authorization values in the error log | Masked values in new log lines | Add your own cookie names to `sensitiveParameters` |
| `GetPageViewHandler` throws a `RuntimeException` when no route matched | None in the default pipeline | None |

### Important updates

#### Composer requirements

Change the `require` section of your `composer.json`:

```json
"php": "~8.3.0 || ~8.4.0 || ~8.5.0 || ~8.6.0",
"dotkernel/dot-log": "^5.4.0 || ^6.0.0",
"dotkernel/dot-errorhandler": "^5.1.0 || ^6.0.0",
"laminas/laminas-diactoros": "^3.10.0",
"laminas/laminas-servicemanager": "^4.6.0",
```

`dot-errorhandler` 6 no longer installs `dot-log` and `laminas-diactoros`.
Without the two lines, Composer stops with an error about `psr/http-message-implementation`, or the application stops with `Class "Dot\Log\..." not found`.

If you changed the error handler, read the `dot-errorhandler` v6 upgrade guide before you run `composer update`.
To stay on version 5, require `"dotkernel/dot-errorhandler": "^5.1.0"`.

#### Composer scripts

Add the configuration cache to the Composer hooks:

```json
"post-update-cmd": [
"php bin/composer-post-install-script.php",
"@clear-config-cache"
],
"post-install-cmd": [
"@clear-config-cache"
],
```

A configuration cache from before an update can point to classes that no longer exist.
Then the application stops with errors about missing classes or services.

#### Page routes

The page routes moved from `config/autoload/local.php.dist` to the `getRoutes()` method of `src/Page/src/ConfigProvider.php`.
Copy the method and the `routes` key of `__invoke()` from the skeleton.

The routes in your existing `config/autoload/local.php` still work, because the configuration aggregator merges both arrays.
You can remove the `routes` key from `local.php` after the move.

#### Error log masking

`config/autoload/error-handling.global.php` now configures a processor for each extra provider.
The enabled `ServerProvider` masks `PHPSESSID`, `PHP_AUTH_PW`, `HTTP_AUTHORIZATION` and `HTTP_PROXY_AUTHORIZATION`.
Before, the error log contained the full cookie header.

Copy the file from the skeleton.
Then add the lower-case names of your own session or authentication cookies to `sensitiveParameters`.

### Optional updates

#### Tests and tooling

- The tests use real `Route` and `RouteResult` objects, because these classes are `final` in `mezzio/mezzio-router` 4.
- New tests cover the App module, the factories and the page routes.
- `phpunit.xml` fails on deprecations, notices, warnings and risky tests, and no longer stops at the first error.
- The Qodana workflow runs on PHP 8.6, and the PHPStan job has the id `phpstan`.

## FAQ

### Which PHP versions does 1.6 support?

PHP 8.3, 8.4, 8.5 and 8.6.

### Must I upgrade to dot-errorhandler 6?

No.
Light 1.6 works with `dot-errorhandler` 5.1 and 6.

### Why do my own tests fail with `ClassIsFinalException`?

`mezzio/mezzio-router` 4 declares `Route` and `RouteResult` as `final`, so PHPUnit cannot make doubles of them.
Create real objects, for example `RouteResult::fromRoute(new Route(...))`.

### Do I need to apply the optional updates?

No.
Skipping them does not change how the application runs.
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ nav:
- "Assets and the Vite build": v1/how-tos/manage-assets.md
- Upgrading:
- "Upgrading from 1.0 to 1.5": v1/upgrading/UPGRADE-1.5.md
- "Upgrading from 1.5 to 1.6": v1/upgrading/UPGRADE-1.6.md
site_name: light
site_description: "Dotkernel Light"
repo_url: "https://github.com/dotkernel/light"
Expand Down