Read-only mirror of https://github.com/sinso/app_routes — Swisscom. Issues & pull requests at the source.
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Sebastian Michaelsen 5eb9e2e1e1 feat!: build PageInformation only when a route asks for it
Every app route so far initialized `frontend.page.information` and
`frontend.page.parts` for the site's root page, whether the handler read
them or not. That bootstrap is not free: `PageRepository::getPage()` only
uses the runtime cache and `SysTemplateRepository` fetches per request by
design, so each call paid for the root page record, a shortcut resolution
where the root is a shortcut, and the sys_template rows of the rootline.
Handlers that only need the request and their own services carried a few
database queries for nothing.

Page information is now built only when a route requests it: either
through the new `defaults.requiresPageInformation: true`, or implicitly
through `requiresTypoScript: true`, since TypoScript needs the
sys_template rows. Without either, the two attributes are not set at all.
`requiresPageInformation` is stripped from the query parameters like the
other route options, so it does not leak into the `PageArguments`.

While here, `FrontendInitialization::createFrontendTypoScript()` takes the
already built `PageInformation` instead of creating a second one, which
saved the same queries again for TypoScript routes.

BREAKING CHANGE: handlers that read `frontend.page.information` or
`frontend.page.parts` without `requiresTypoScript` must add
`requiresPageInformation: true` to their route defaults.

Closes #37

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-10 15:17:15 +02:00
.github/workflows ci: raise PHPStan level to 4 2026-03-12 14:02:27 +01:00
Classes feat!: build PageInformation only when a route asks for it 2026-09-10 15:17:15 +02:00
Configuration !fix: properly work with TYPO3 v13 2026-01-22 08:39:24 +01:00
Tests/Unit feat!: build PageInformation only when a route asks for it 2026-09-10 15:17:15 +02:00
composer.json fix!: remove TSFE initialization 2026-03-03 12:00:54 +01:00
ext_localconf.php [TASK] Make compatible with TYPO3 v12 2022-10-16 13:55:41 +02:00
LICENSE Create LICENSE 2020-12-15 11:24:15 +01:00
phpstan.neon ci: raise PHPStan level to 4 2026-03-12 14:02:27 +01:00
phpunit.xml test: introduce unit tests for key components 2026-03-03 12:00:54 +01:00
Readme.md feat!: build PageInformation only when a route asks for it 2026-09-10 15:17:15 +02:00

TYPO3 App Routes

Route any URL to your application.

You use this package if you want to route certain URLs directly to your controllers, completely ignoring the TYPO3 page routing.
This is especially useful to create REST APIs.

Installation

composer req sinso/app-routes

Configuration

This package will look for Configuration/AppRoutes.yaml files in any loaded extension. Creating this file is all you need to get started:

myApp:
  prefix: /myApi/v2
  routes:
    - name: orders
      path: /orders
      defaults:
        handler: MyVendor\MyExtension\Api\OrdersEndpoint
    - name: order
      path: /order/{orderUid}
      defaults:
        handler: MyVendor\MyExtension\Api\OrderEndpoint

The class you provide as defaults.handler has to implement \Psr\Http\Server\RequestHandlerInterface. The routing parameters will be available in $request->getQueryParams().

Options

Under the hood symfony/routing is used.

Everything that is available as YAML configuration option in symfony/routing should work with this package out of the box.

This package offers these additional options:

  • defaults.cache: true - If true, then responses are cached (see more details below). (default: false)
  • defaults.requiresPageInformation: true - If true, then the frontend.page.information and frontend.page.parts request attributes will be initialized for the site's root page before your handler is called. This costs a few database queries per request, so only enable it for handlers that read page data (default: false).
  • defaults.requiresTypoScript: true - If true, then the frontend.typoscript request attribute will be initialized before your handler is called. Implies requiresPageInformation (default: false).

Generate Route URLs

To generate URLs you can use the Sinso\AppRoutes\Service\Router:

$router = GeneralUtility::makeInstance(\Sinso\AppRoutes\Service\Router::class);
$url = $router->getUrlGenerator()->generate('myApp.order', ['orderUid' => 42]);
// https://www.example.com/myApi/v2/order/42

If you need to generate a URL in a Fluid template, there's also a ViewHelper for that:

<html
	xmlns:ar="http://typo3.org/ns/Sinso/AppRoutes/ViewHelpers"
	data-namespace-typo3-fluid="true"
>

{ar:route(routeName: 'myApp.order', parameters: {orderUid: '42'})}

</html>

Configuration Module

In the configuration module there's an entry "App Routes", that shows all configured routes.

Server Side Caching

  • Caching can be enabled per route via configuration defaults.cache: true.
  • The TYPO3 pages cache is used to cache API responses.
  • Your request handler will not be called at all if the request can be served from cache.
  • Only responses for GET and HEAD requests can be cached.
  • The cache key is built from all query parameters that were matched by your route.
  • Any cache tags added to TYPO3's CacheDataCollector ($request->getAttribute('frontend.cache.collector')) are applied to the cache entry.
  • If you have $GLOBALS['TYPO3_CONF_VARS']['FE']['debug'] enabled, the HTTP response contains headers describing its cache status.
  • Responses with Cache-Control: no-cache or Cache-Control: no-store are not cached.
  • Responses with Cache-Control: max-age=300 overwrite the default TTL of the pages cache.

ETag

Setting an ETag header in your response will enable conditional requests, i.e. the client doesn't need to download the response body if it already has the latest version.

  • If your response contains an ETag header and it matches the If-None-Match header of the request, the response HTTP status will be 304 Not Modified and the response body will be empty.